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
2
votes
0 answers

oapi-codegen gin server append error with c.Error() instead of dumping it with c.JSON()

This is the command I'm using to generate the gin server: oapi-codegen -generate gin,types,spec -package api api/openapi/api.yaml > internal/api/openapi/api.go When the gin server code is generated, it provides a wrapper for the service interface.…
chaseisabelle
  • 162
  • 2
  • 18
2
votes
0 answers

GO dynamic update queries with Gin and PGX

I'm trying to build a web service which would receive an HTTP PATCH request to update some fields in a "users" table (so I don't know how many nor which ones have to be updated). I decided to work with Gin and because I'm working with Postgres, I'm…
Big_Boulard
  • 799
  • 1
  • 13
  • 28
2
votes
1 answer

DB mock using sqlmock not working for testing Gin/GORM API?

I've an API written using Gin that uses GORM for ORM. The API works perfectly fine when using a real DB and accessing the API URL from the web browser. But I can't get a mocked unit test to pass: func TestRespForGetUsersHandlerWithSomeUsers(t…
csmathhc
  • 205
  • 2
  • 12
2
votes
1 answer

Is it possible to retrieve gin Context anywhere in the code (GoLang)?

I know in Java Springboot, it is possible to call SecurityContext anywhere in the code to get the context. For example: SecurityContext context = SecurityContextHolder.getContext(); My question is, is it possible to get the *gin.Context anywhere in…
2
votes
1 answer

Go: How to send a File from AWS S3 via GIN-Router as binary stream to the browser?

How can I send a file, that I've got received from S3, to Gin as binary response? Lets say, I have the following code to obtain an image from S3 bucket: response, err := i.s3Client.GetObject(context.TODO(), &s3.GetObjectInput{ Bucket:…
delete
  • 18,144
  • 15
  • 48
  • 79
2
votes
1 answer

What is the use of test mode in Gin

I've checked the documentation but it does not explain the use of setting test mode for gin gin.SetMode(gin.TestMode) What is this test mode provided for? I do not see any difference when setting & not setting this mode in my tests.
Vivek
  • 11,938
  • 19
  • 92
  • 127
2
votes
1 answer

How to mock a third-party struct with many methods and perform unit tests on endpoints that depend on the third-party struct?

I'm working with getstream's Go library in gin gonic and realized that my endpoints will be heavily dependent on stream_chat.Client. For instance, in the following endpoint (/v1/chat/test-token), a stream_chat.Client must be created so testing this…
Nahua Kang
  • 366
  • 1
  • 7
  • 19
2
votes
1 answer

How to preserve path params after handling a request with router.Any and wildcard

In my case need to catch request and check is internal request or not. If not, redirect these request to other handler function. URL example: 1. URL: http://localhost/internal/dosomething1 2. URL: http://localhost/internal/dosomething2/:id 3. URL:…
Ertuğrul Altınboğa
  • 2,187
  • 4
  • 17
  • 25
2
votes
1 answer

Golang ServeHTTP make proxy error EOF on POST request

I’m working on proxy server with gin and ServeHTTP. 
Actually GET and OPTIONS request works well. But when I trying multiples POST request I get EOF error one in two request. I’ve test to make repeat request without proxy service and its work well,…
Vivien B
  • 83
  • 8
2
votes
1 answer

More elegant way of validate body in go-gin

Is there a more elegant way to validate json body and route id using go-gin? package controllers import ( "giin/inputs" "net/http" "github.com/gin-gonic/gin" "github.com/google/uuid" ) func GetAccount(context *gin.Context) { …
mikolaj semeniuk
  • 2,030
  • 15
  • 31
2
votes
1 answer

Gin reverse proxy tests failing for interface conversion: *httptest.ResponseRecorder is not http.CloseNotifier: missing method CloseNotify

I build a Go Gin reverse proxy API using this page as a guideline: https://le-gall.bzh/author/sebastien-le-gall/ When I try to run tests, I get an error: interface conversion: *httptest.ResponseRecorder is not http.CloseNotifier: missing method…
Ben Walker
  • 2,037
  • 5
  • 34
  • 56
2
votes
0 answers

How to perform the parameter type check in golang gin using validator?

I have a Validator struct like this type UploadFileFormValidator struct { File []*multipart.FileHeader `form:"File" binding:"required,min=1"` InputKey string `form:"Key" binding:"disallowed-char"` Permission…
JY F
  • 39
  • 1
  • 6
2
votes
1 answer

gin golang: what is gin.Context.Keys

I was tring to use the method context.GetBool (here) from the go-gin framework with some query params. It doesn't work as excepted and I think the Context.Keys is not populated by query params. So my question is: what is gin.Context.Keys, and how…
A. Ecrubit
  • 561
  • 6
  • 20
2
votes
1 answer

Getting "multipart: NextPart: EOF" error when reading multipart/form-data

I am building a router layer for an API where I take the response and extract a parameter (in this case a service_code, the name can vary - service_code, serviceCode, code need to handle all) from the request body and pass it to the service that…
Archit Verma
  • 1,911
  • 5
  • 28
  • 46
2
votes
1 answer

Graphql Subscriptions not working with Gin

When I tried to setup a Go web server with GraphQL I used this as template. It is basically a combo of gin and 99designs/gqlgen. When I create a basic gqlgen server based on net/http package, the declaration of GraphQL subscriptions work as…
Willey3x37
  • 310
  • 2
  • 12