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

Testing CORS Middleware with Gin

I'm trying to write a test that validates the CORS for my API are setup correctly. The API is written in Go and uses GIN. I have different CORS settings depending on router group. It looks like: router :=…
Keith
  • 23
  • 4
2
votes
2 answers

golang gin gorm insert and set primary_key but primary_key got null

I use gin gorm mysql build application. I set topic_id primary_key auto_increment not null in model.go as follow: type Topic struct { gorm.Model TopicId uint64 `gorm:"PRIMARY_KEY;AUTO_INCREMENT;NOT NULL"` TopicName string …
齐德隆咚锵
  • 35
  • 1
  • 1
  • 5
2
votes
1 answer

Go Gin Setting and Accessing context value from middleware

I am trying to set my user context, in the middleware then trying to check if user have permission in other handler functions. But for some reason when I try to access the user from context it is coming back as nils. The middleware code seems to be…
rak1n
  • 671
  • 1
  • 8
  • 17
2
votes
1 answer

What is difference between router.Static() and router.Use(static.Serve()) on the gin?

I was just reading the documentation of gin and found there are 2 different way to set assets folder to the server, one is using Static() method of the router as follow: package main import "github.com/gin-gonic/gin" func main() { r :=…
Ueda Takeyuki
  • 721
  • 10
  • 26
2
votes
1 answer

Connecting Gorm and Gin Golang

I am trying to create an API with Go, gorm and gin. However, using a direct SQL query did work, but it became too cumbersome and I decided to leverage gorm which is fantastic. However after my implementation, I am unable to get the project up again…
King
  • 1,885
  • 3
  • 27
  • 84
2
votes
1 answer

How do you remove a static middleware on a post request?

I want the home page to stop being available after a post request. Here is my code. Thanks in advance. package main import( "github.com/gin-contrib/static" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() …
user12695481
2
votes
1 answer

How to set a cookie with Gin JWT middleware

I believe I successfully implemented the JWT middleware for Gin Gonic by following the example in the readme. It is my understanding that upon retrieving an access token, I should also retrieve a refresh token that is being stored in a http only…
user3255061
  • 1,757
  • 1
  • 30
  • 50
2
votes
1 answer

How to keep the gzip representation of HTTP body

In the context of a go web app, I am using a cache of responses and compressing them, so I save bandwidth (responses are larger). I am using gin-gonic framework and the package gzip for compressing. This package works pretty well and makes…
lrleon
  • 2,610
  • 3
  • 25
  • 38
2
votes
1 answer

Binding validations does not work when request body is Array of objects

Gin's request validation feature is not working when the request body (JSON) represents an array of objects Ex: [ { "field1":"aaa", "field2":"bbb" } ] code: type item struct { Field1 string `json:"field1"…
Peggy
  • 372
  • 1
  • 6
  • 27
2
votes
1 answer

How to return a files or images path urls to forntend using golang rest apis?

I am using Golang(gin-gonic framework) for my backend. I have developed below rest API to receive images or files from the frontend applications. I am saving files in this path…
Cherry
  • 699
  • 1
  • 7
  • 20
2
votes
1 answer

How to delete a table with relationships in GORM?

I deleted the object and want it's ID deleted too in a relationship table. How do I do it? i.e. objects with relations are deleted but the tables of their relations remain. Also wanted to ask, GORM is the best ORM solution for Go-Gin ?
atkisai
  • 53
  • 3
  • 7
2
votes
2 answers

How to omit some parameters of structure Gin gonic

I have big structure with more than 50 params type Application struct { Id int64 `json:"id"` FullName string `json:"fullName,omitempty"` ActualAddress string …
mondayguy
  • 973
  • 2
  • 12
  • 34
2
votes
1 answer

How to serve statics files in Gin

by following the tutorial I try to connect the frontend (React) to backend API (Gin), but the static.Serve doesn't work, error prompted as below: cannot use static.Serve("/", static.LocalFile("./views", true)) (type…
Zeng Vincent
  • 83
  • 1
  • 5
2
votes
1 answer

server running on localhost:8080 getting CORS from frontend running on 9090

I have a API-server (gin-gonic) running on localhost:8080. All the typical CORS-Header are set for debugging: When I try to test the API with a simple Frontend (swagger-ui) i get a CORS-error. (swagger is running on localhost:9090) It works when…
Paul Oskar Mayer
  • 1,107
  • 1
  • 10
  • 22
2
votes
3 answers

How can I know when two servers are ready to get requests?

I have two servers router := createServer() loginServer := createLoginServerMock() servLogin := &http.Server{ Addr: ":9333", Handler: loginServer, } testServer := &http.Server{ Addr: ":9444", Handler: …