In the following example, we’ll use a string with values separated by commas as delimiters. Example 1: packagemainimport("fmt""strings")funcmain(){varstr="a-b-c"vardelimiter="-"varparts=strings.Split(str,delimiter)fmt.Println(parts)} ...
f :=func(crune)bool{returnc ==':'}// Allow multiple rules separated by ;splitRule :=func(crune)bool{returnc ==';'} parsedRules := strings.FieldsFunc(expression, splitRule)for_, rule :=rangeparsedRules {// get functionparsedFunctions := strings.FieldsFunc(rule, f)iflen(parsedFunctions...
type ProfileForm struct { Name string `form:"name" binding:"required"` Avatar *multipart.FileHeader `form:"avatar" binding:"required"` // or for multiple files // Avatars []*multipart.FileHeader `form:"avatar" binding:"required"` } func main() { router := gin.Default() router.POST("...
type ProfileForm struct { Name string `form:"name" binding:"required"` Avatar *multipart.FileHeader `form:"avatar" binding:"required"` // or for multiple files // Avatars []*multipart.FileHeader `form:"avatar" binding:"required"` } func main() { router := gin.Default() router.POST("...
type ProfileForm struct { Name string `form:"name" binding:"required"` Avatar *multipart.FileHeader `form:"avatar" binding:"required"` // or for multiple files // Avatars []*multipart.FileHeader `form:"avatar" binding:"required"` } func main() { router := gin.Default() router.POST("...
The normal methods for binding request body consumes c.Request.Body and they cannot be called multiple times.type formA struct { Foo string `json:"foo" xml:"foo" binding:"required"` } type formB struct { Bar string `json:"bar" xml:"bar" binding:"required"` } func SomeHandler(c *...
type ProfileForm struct { Name string `form:"name" binding:"required"` Avatar *multipart.FileHeader `form:"avatar" binding:"required"` // or for multiple files // Avatars []*multipart.FileHeader `form:"avatar" binding:"required"` } func main() { router := gin.Default() router.POST("...
String(http.StatusOK, fmt.Sprintf("'%s' uploaded!", file.Filename)) }) router.Run(":8080") } How to curl: curl -X POST http://localhost:8080/upload \ -F "file=@/Users/appleboy/test.zip" \ -H "Content-Type: multipart/form-data" Multiple files See the detail example code. ...