Gin is a web framework written in Golang. It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
dependabot[bot] on github_actions
chore(deps): bump golangci/gola… (compare)
Hello everyone,
I'm getting context cancelled error inside my go routine below is my code.
func (service maintenanceHandler) CardHandler(ctx *gin.Context) {
var requestBody models.DefaultTicket
//perform some action.
go doSomethingElse(requestBody.Priority,ctx)
}
I also tried with
func (service maintenanceHandler) CardHandler(ctx *gin.Context) {
var requestBody models.DefaultTicket
//perform some action.
go doSomethingElse(requestBody.Priority,ctx.Copy())
}
In both the case I'm getting CONTEXT CANCELLED inside go routine method, can anyone please help me in this?
req.code != msg.Code
required
, not requred
:sweat:
type MyModel struct {
key string `json:"key" bindind:"dafult=5"`
}
How to use a type definition in another file with swaggo?
Using swaggo generate API document based on godoc
syntax.
Source folder and files
|-post
|--controller.go
|--response.go
For this definition:
controller.go
package post
...
// Index godoc
// @Summary Index Post
// @Success 200 {array} []*Response
// @Router /v1/posts [get]
func Index(ctx *gin.Context) {
...
}
The Response
is been defined in an another file but the same package.
response.go
package post
// Response is post response body
type Response struct {
ID int64 `json:"id"`
Name string `json:"name"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
But when run swag init
to generate swagger docs, it said:
2021/01/29 09:39:56 Generate swagger docs....
2021/01/29 09:39:56 Generate general API Info, search dir:./
2021/01/29 09:39:56 ParseComment error in file application/post/controller.go :cannot find type definition:
When I move the Response
struct to controller.go
, it works.
How to import it with godoc or swaggo?
Hi @Antonin72982395_twitter , I don't think you can have default values just like that, but you can do something like below
func NewResponse(data interface{}) Response {
// ... check nil and assign default values
}
or as an extension function
func (r *Response) SetDefaults() Response {
// ... check nil and assign default values
}