Skip to content

Instantly share code, notes, and snippets.

@joshrotenberg
Last active September 28, 2018 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshrotenberg/dd1c69a6724ba38fa57f2fa0411a9afa to your computer and use it in GitHub Desktop.
Save joshrotenberg/dd1c69a6724ba38fa57f2fa0411a9afa to your computer and use it in GitHub Desktop.
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