Questions tagged [go-gin]

Gin is a HTTP web framework written in Go.

It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.

Docs

GitHub

755 questions
4
votes
1 answer

gin - problem accessing url-encoded path-param containing forward slash

For a given route with path param (example below) router.GET("/employee/:id", empHandler.GetEmployee) When tried to invoke the url with id path-param(encoded) containing forward slashes id = 21/admin/527 url-encoded id =…
Vivek
  • 11,938
  • 19
  • 92
  • 127
4
votes
2 answers

pq: password authentication failed for user "user-name" while accessing postgres in vscode

I am making an API using Golang, and I am using Postgres as database. I have used the following command:- args := "host=" + host + " port=" + port + " dbName=" + dbName + "username=" + username + " sslmode=disable password=" + password db, err…
Ansh Joshi
  • 41
  • 1
  • 7
4
votes
2 answers

Validate enum in Golang using Gin framework

I try to validate if enum is valid in Golang using Gin framework. I came across this solution: Use enum validation in golang with gin with custom error messages But disadvantage of this approach is hardcoded value which we have to change manually…
mikolaj semeniuk
  • 2,030
  • 15
  • 31
4
votes
1 answer

How to get request host from Go gin context?

I'm trying to get the request host from gin context, but the only thing close I've found is Context.ClientIP(). I'm dealing with a dynamic IP, so I'd like to get the host name here instead to check it against an allowed list for setting a CORS…
Ben Walker
  • 2,037
  • 5
  • 34
  • 56
4
votes
1 answer

If I use multiple middleware in gin what is the order in which they are executed

If I use multiple middleware and I want to use output of mw1 in mw2 using ctx.Set and ctx.Get is there any defined order in which middleware are executed? func main() { // Creates a router without any middleware by default r := gin.New() …
user1017860
  • 190
  • 3
  • 11
4
votes
4 answers

How to extract comma separated values from query parameter in Go?

I am using the Gin Web Framework and I am trying to find a way to bind a list of comma separated values from a query parameter into a struct. The following is a snippet of my code: type QueryParams struct { Type []string…
user16368243
4
votes
2 answers

How to propagate context values from Gin middleware to gqlgen resolvers?

I am trying to extract user_id in token authentication middleware and pass it to gqlgen's graphql resolver function (to populate created_by and updated_by columns of GraphQL schema). Authentication part works without any problems. The Gin…
Helen Grey
  • 439
  • 6
  • 16
4
votes
1 answer

Gin gonic templates overwriting partial templates

I am using gin gonic and it's features. One if them being html template rendering. So in spirit of DRY I wanted to create a base.html template with all common html tags etc. with a slot for different page bodies. In essence, this is the…
Razmooo
  • 457
  • 1
  • 7
  • 19
4
votes
1 answer

Gin Validation for optional pointer to be uuid?

I have this struct // CreateAccount Create Account Data Args type CreateAccount struct { .... RegistrationID string `example:"2c45e4ec-26e0-4043-86e4-c15b9cf985a2" json:"registration_id" binding:"max=63"` ParentID *string…
Dan
  • 681
  • 2
  • 11
  • 23
4
votes
2 answers

gin bindJson array of objects

I would like to bind a json array of objects like this one : [ { "id": "someid" }, { "id": "anotherid" } ] Here my model type DeleteByID struct { ID string `json:"id" binding:"required"` } I use gin to handle…
Yok0
  • 121
  • 1
  • 9
4
votes
1 answer

gqlgen Set cookie from resolver

I'm using gin and gqlgen. I was need to set cookie from resolver but all I have in my resolver is context and inputs from graphQL. This question is already answered in github. But this one is different because I can't change ctx.Writer.Write and…
Mreza0100
  • 328
  • 1
  • 9
4
votes
3 answers

how to upload multipart file and json in Go with gin gonic?

I'm trying to upload a file to my server with additional information attached to it as json. I can upload a file alone with gin doing : file, err := c.FormFile("file") if err != nil { return error } But i can't figure out how to pass the file…
goleavid
  • 41
  • 1
  • 1
  • 2
4
votes
1 answer

How to wrap route handler function gin.HandlerFunc

Given: package main import ( "github.com/gin-gonic/gin" ) func main() { r := gin.Default() r.POST("/status", handler) r.Run(":8080") } func handler(c *gin.Context) { var status string if err := c.ShouldBindJSON(&status);…
Erik
  • 163
  • 1
  • 2
  • 10
4
votes
0 answers

Go HTTP POST request with big JSON, sometimes "write: broken pipe"

I have a HTTP client(fasthttp) and a HTTP server(gin). When sending big POST request(Content-Length 70K-100K, Content-Type: application/json), sometimes the client encounters error "write: broken pipe". With ngrep, I found the server returns TCP…
jianfyun
  • 71
  • 1
  • 4
4
votes
1 answer

Get all content of POST HTML form in Gin

I've an HTML form:
Complete
DenCowboy
  • 13,884
  • 38
  • 114
  • 210