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
6
votes
1 answer

How to define a go-gin route with an id in the middle

I want to define a route /user/{userid}/status How can I define this kind of route and intercept the userid in handler. Something like this r.GET("/user/{userid}/status", userStatus) How can read the userid variable in my Go code in such case?
codec
  • 7,978
  • 26
  • 71
  • 127
6
votes
3 answers

How to use Context.Request.Body and retain it?

I am trying to write a middleware where I will be doing a json schema validation against the request body. After the validation, I need to use the request body again. But I am not able to figure out how this can be done. I referred this post and…
Sanath Ballal
  • 1,648
  • 4
  • 22
  • 31
5
votes
1 answer

How to set new request body in Go Gin while proxing a request

I'm trying to proxy an HTTP call, and trying to modify the JSON body before sending it to the proxy service. However, if I try to modify the c.Request.Body with any new data, the POST request ends in 400 bad format. But if I set the same previous…
Nirojan Selvanathan
  • 10,066
  • 5
  • 61
  • 82
5
votes
1 answer

Authentication middleware not working in Gin

I have the following routes and the session setup: func SetupRouter() *gin.Engine { r := gin.Default() // Session store := cookie.NewStore([]byte("secret")) // Set session expiration time store.Options(sessions.Options{MaxAge:…
Samoila Andrei
  • 327
  • 2
  • 14
5
votes
1 answer

How to use a certificate from a certificate store and run TLS in gin framework in go?

My current application starts a Go Gin web server using TLS and loads the cert and key from a local file system. I want to load these files from a cert store or I want to pass the certificate and private key as byte array instead of file…
vidya k.s.
  • 131
  • 2
  • 5
5
votes
1 answer

How to render HTML Template In Gin Gonic (Golang)?

I am trying to create an HTML template on Golang using Gin Gonic. but there are problems when rendering the template that I made to produce a web view (the result is blank). Is there something wrong with my code? i tried to read gin gonic…
Tammam
  • 416
  • 1
  • 7
  • 16
5
votes
1 answer

Use /path/{proxy+} with AWS SAM to have a greedy API in API Gateway

I'm using SAM. The following setup works: Function: Type: AWS::Serverless::Function Properties: CodeUri: ./code/ Runtime: go1.x MemorySize: 64 Handler: main Events: TesstApi: Type: Api …
mealesbia
  • 845
  • 2
  • 12
  • 28
5
votes
3 answers

Gin wildcard route conflicts with existing children

I'd like to build a gin program which serves the following routes: r.GET("/special", ... // Serves a special resource. r.Any("/*", ... // Serves a default resource. However, such a program panics at runtime: [GIN-debug] GET /special …
maerics
  • 151,642
  • 46
  • 269
  • 291
4
votes
1 answer

Fizz OpenAPi generator for Gin is renaming types

I have created a simple API written in Gin. I used Fizz to generate an OpenApi 3 specification. Here is my POST endpoint: // Sets user route group func UserRoute(grp *fizz.RouterGroup) { // create new user grp.POST("",…
jsfrz
  • 99
  • 9
4
votes
1 answer

Cannot find default credentials in Cloud Run

I am writing a program that speaks with Cloud Spanner in Postgres Dialect. My application is a gin server and I am using pgadapter to connect as mentioned in this doc. My application runs fine locally. But when I deploy it to cloud run, I get the…
4
votes
0 answers

golang validation with gin-gonic

I'm trying to build a login API type LoginRequest struct { Email string `json:"email" binding:"required,email"` Password string `json:"password" binding:"required"` } func LoginHandler(app *config.Config) func(ctx *gin.Context) { …
4
votes
1 answer

Why should I make a copy of a context for goroutines inside handlers?

I recently started rewriting some of my Python services in Go to speed them up and came across this section of the gin documentation: https://github.com/gin-gonic/gin#goroutines-inside-a-middleware So I understand the instructions, but I'm trying to…
Michael
  • 1,428
  • 3
  • 15
  • 34
4
votes
0 answers

Testify mock ExpectedCall does not match expected call in gin handler, panics

I'm using gin-gonic for a server, and testify for testing and mocks, along with "testing" and "net/http/httptest" The part of the interface that mocks the method: func (m *MockInterface) Method(ctx context.Context, id string, deleted bool)…
Laura
  • 288
  • 1
  • 4
  • 14
4
votes
2 answers

Generate OpenAPI spec from gin project

Is there a way to generate OpenAPI spec files from a gin project? This issue is really hard to search for, all I could find so far are on doing there reverse.
Philippe
  • 1,715
  • 4
  • 25
  • 49
4
votes
1 answer

Golang Gorm not retrieving data from associated table

I'm working on a Gin app using Gorm with MySQL. In order to define a belongs to relationship in a Gorm Model, you have to do the following (example taken from Gorm docs): // `User` belongs to `Company`, `CompanyID` is the foreign key type User…
MrCujo
  • 1,218
  • 3
  • 31
  • 56