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

service "app" depends on undefined service db: invalid compose project

I build a Go server in Gin framework and now I want to deploy it to GCP. I am trying to run docker compose up -d on VM in GCP Compute Engine. The command successfully runs in my local machine but shows error in VM terminal The error I am getting in…
2
votes
2 answers

Gin middleware context variable not preserving

I am trying to get user's tasks by fetching them from database using user id gotten from gin context. The issue is in GetAllUsersTasks where userContext is . While in loggedIn the user from context fetches all the info. What am I missing…
Fifips
  • 39
  • 3
2
votes
0 answers

TrustedProxies or TrustedPlatform for Gin in AWS EC2 with loadbalancer

Gin framework (for Go) strongly suggest that it's unsafe to "trust all proxies". If I understand the doc's correctly this impacts special HTTP headers like X-Forwarded-For which is used to resolve client IP when service is behind a…
Kalle
  • 452
  • 2
  • 4
  • 19
2
votes
0 answers

Mock a function that returns a struct in Golang

I have started learning Golang and I created a simple application with Gin and there are two lines (in main function) that I am not able to test for having a 100% of coverage: func setupRouter() *gin.Engine { fmt.Println("Starting…
druizz90
  • 21
  • 2
2
votes
0 answers

Gorm Postgresql got the diff-result when use the same SQL-query

SQL query with dates as ( select generate_series( (date ('2022-10-02'))::timestamp, (date ('2022-10-03'))::timestamp, interval '2 hour' ) as dt ) …
evan nurandiz
  • 21
  • 1
  • 2
2
votes
2 answers

swag init gin. Paths is empty

I'm trying to generate swagger.json by using swag init. Here my code: package main import ( _ "album/docs" "context" "fmt" "net/http" "os" "github.com/gin-gonic/gin" "github.com/jackc/pgx/v5" swaggerFiles…
anton
  • 31
  • 3
2
votes
1 answer

How to scan jsonb objects from Postgresql to golang structs

Firstly, I've tried solutions from past stackoverflow answers whose questions were related to mine, and nothing has worked, that's why i am asking it as a separate question. I have two structs in golang type otherPayments struct { DebitTo …
Zulfiqar Ali
  • 269
  • 1
  • 3
  • 12
2
votes
0 answers

How to tell Gin explicitly to bind a struct to the request body and nothing else?

I'm using the gin framework and the following code works fine for me import ( "github.com/gin-gonic/gin" "net/http" ) type RequestBody struct { MyRequiredField string `json:"myRequiredField" binding:"required"` } func Handle(context…
baitendbidz
  • 187
  • 3
  • 19
2
votes
1 answer

Using Golang Gin with AWS Lambda and Serverless with proxy path

I want to proxy all my HTTP requests from root through a single lambda function call. I tried setting /{proxy+} as the path in my serverless.yml. But when I deploy it I get "This page isn't redirecting properly" when visiting the…
BAR
  • 15,909
  • 27
  • 97
  • 185
2
votes
1 answer

How to get an array of parameter values in gin

I need to accept multiple cat_id values in the request, for example: localhost:8080/products/?cat_id=1,2 My func: func GenerateMultiParams(c *gin.Context) models.Params { limit := 0 page := 1 cat_id := 1 query :=…
Casper
  • 173
  • 2
  • 11
2
votes
1 answer

How to validate headers and body in Gin-Gonic?

I have a Gin program. When a request comes, I want all of the fields of the variable data (type ProductCreate) to have values: UserId (from headers) and Name, Price (from JSON body). I used the below code and it works: package main import ( …
Ben Alpha
  • 33
  • 2
  • 5
2
votes
1 answer

How to get field value in GORM

I have a function that outputs all Product data to the data array, but I also need to display 5 products from the same category in the relatives array. Function: func GetProductsById(c *gin.Context) { var Product models.Products Products :=…
Casper
  • 173
  • 2
  • 11
2
votes
1 answer

How to select first N elements Gin-Gorm

I have a function that displays Categories, I want to use the Preload method to also display Products related to this category, but I don’t need all the products, but only 5 pieces, how can I fix the request? Function: func GetAllCategories(c…
Casper
  • 173
  • 2
  • 11
2
votes
0 answers

I have three Micro services in Golang made using gin, Books, Ratings, Reviews API, now i want to get the result of rating an API in Books API

I have three Micro services in Golang made using gin, Books, Ratings, Reviews API, now i want to get the result of rating an API in Books API.Basically how do i connect my three api/Micro-services, using gin, i don't know how to use docker and…
2
votes
2 answers

Golang : "Err TLS Handshake failed: tls: server selected unsupported protocol version 301" when trying to connect to sql server (diferent host)

This my code when try to connect sql server: connString := fmt.Sprintf("server=%s;user id=%s;password=%s¡port=%s;databases=%s", server, user, password, port, database) // if there is an error opening the connection, handle it if err != nil { //…