Validation 썸네일형 리스트형 Golang Gin-gonic에서의 request 파싱 Validation에 대해서 회사에서 Gin을 쓰다가 struct 단에서의 Validation을 하려는데 gin context에서 binding을 할 때 쓰는 거에 따라서 결과가 달라서 정리를 해본다. 보통 body로 들어오는 요청을 처리하는 struct는 아래와 같이 구성한다. type Bind struct { Name string `json:"name"` } 여기서 만약 해당 struct로 body 값을 파싱하려면 아래와 같이 할 수 있다. r.POST("/", func(c *gin.Context) { req := &Bind{} err := c.Bind(req) if err != nil { c.JSON(http.StatusBadRequest, err.Error()) return } c.Status(http.StatusOK) }).. 더보기 이전 1 다음