Last active
September 28, 2018 21:34
-
-
Save joshrotenberg/dd1c69a6724ba38fa57f2fa0411a9afa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"github.com/gin-gonic/gin" | |
) | |
func main() { | |
router := gin.Default() | |
// curl -v -H"Content-Type: application/x-www-form-urlencoded" "localhost:8080/post?id=1221&page=3" -d 'name=manu&message=this_is_great' | |
router.POST("/post", func(c *gin.Context) { | |
id := c.Query("id") | |
page := c.DefaultQuery("page", "0") | |
name := c.PostForm("name") | |
message := c.PostForm("message") | |
c.String(http.StatusOK, fmt.Sprintf("id: %s; page: %s; name: %s; message: %s", id, page, name, message)) | |
}) | |
// curl -X POST http://localhost:8080/upload -F "file=@./ginthing.go" -H "Content-Type: multipart/form-data" | |
router.POST("/upload", func(c *gin.Context) { | |
// single file | |
file, _ := c.FormFile("file") | |
log.Println(file.Filename) | |
// Upload the file to specific dst. | |
// c.SaveUploadedFile(file, dst) | |
c.String(http.StatusOK, fmt.Sprintf("'%s' uploaded!", file.Filename)) | |
}) | |
router.Run(":8080") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment