Created
August 23, 2022 04:46
-
-
Save khaidir/b666a804d90010df9afbdae9d3d11d71 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ( | |
"net/http" | |
"github.com/gin-gonic/gin" | |
) | |
type CreateParams struct { | |
Username string `json:"username"` | |
Guests Guests `json:"guests"` | |
RoomType string `json:"roomType"` | |
CheckinDate string `json:"checkinDate"` | |
CheckoutDate string `json:"checkoutDate"` | |
} | |
type Guests struct { | |
Person []Person `json:"person"` | |
} | |
type Person struct { | |
Firstname string `json:"firstname" binding:"required"` | |
Lastname string `json:"lastname"` | |
} | |
func main() { | |
r := gin.New() | |
r.POST("/", func(c *gin.Context) { | |
var f CreateParams | |
if err := c.BindJSON(&f); err != nil { | |
return | |
} | |
c.IndentedJSON(http.StatusOK, f) | |
}) | |
r.Run(":4000") | |
} | |
// post data | |
{ | |
"username": "foo", | |
"guests": { | |
"person": [ | |
{ | |
"firstname": "foobar", | |
"lastname": "barfoo" | |
}, | |
{ | |
"firstname": "foofoo", | |
"lastname": "barbar" | |
} | |
] | |
}, | |
"roomType": "16A", | |
"checkinDate": "10-08-2022", | |
"checkoutDate": "12-08-2022" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment