Skip to content

Instantly share code, notes, and snippets.

@joshrotenberg
Last active September 28, 2018 21:34
Show Gist options
  • Select an option

  • Save joshrotenberg/dd1c69a6724ba38fa57f2fa0411a9afa to your computer and use it in GitHub Desktop.

Select an option

Save joshrotenberg/dd1c69a6724ba38fa57f2fa0411a9afa to your computer and use it in GitHub Desktop.

Revisions

  1. joshrotenberg revised this gist Sep 28, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ginthing.go
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ func main() {

    // 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) {
    fmt.Println(c)

    id := c.Query("id")
    page := c.DefaultQuery("page", "0")
    name := c.PostForm("name")
  2. joshrotenberg renamed this gist Sep 28, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. joshrotenberg revised this gist Sep 28, 2018. 1 changed file with 0 additions and 23 deletions.
    23 changes: 0 additions & 23 deletions ginthing.go
    Original file line number Diff line number Diff line change
    @@ -1,23 +0,0 @@
    package main

    import (
    "fmt"
    "net/http"

    "github.com/gin-gonic/gin"
    )
    // curl -v -H"Content-Type: application/x-www-form-urlencoded" "localhost:8080/post?id=1221&page=3" -d 'name=manu&message=this_is_great'
    func main() {
    router := gin.Default()

    router.POST("/post", func(c *gin.Context) {
    fmt.Println(c)
    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))
    })
    router.Run(":8080")
    }
  4. joshrotenberg revised this gist Sep 28, 2018. 1 changed file with 37 additions and 0 deletions.
    37 changes: 37 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    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) {
    fmt.Println(c)
    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")
    }
  5. joshrotenberg revised this gist Sep 28, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ginthing.go
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ import (

    "github.com/gin-gonic/gin"
    )

    // curl -v -H"Content-Type: application/x-www-form-urlencoded" "localhost:8080/post?id=1221&page=3" -d 'name=manu&message=this_is_great'
    func main() {
    router := gin.Default()

  6. joshrotenberg created this gist Sep 28, 2018.
    23 changes: 23 additions & 0 deletions ginthing.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    package main

    import (
    "fmt"
    "net/http"

    "github.com/gin-gonic/gin"
    )

    func main() {
    router := gin.Default()

    router.POST("/post", func(c *gin.Context) {
    fmt.Println(c)
    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))
    })
    router.Run(":8080")
    }