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

golang: serving net.Conn using a gin router

I have a function that handles an incoming TCP connection: func Handle(conn net.Conn) error { // ... } Also, I have an initialized gin router with implemented handles: router := gin.New() router.GET(...) router.POST(...) The router.Run(addr)…
Prisacari Dmitrii
  • 1,985
  • 1
  • 23
  • 33
3
votes
1 answer

custom gin logging middleware truncating logs

Intermittently, I see truncated json objects being written to loggly through my custom logging middleware. I've confirmed the outgoing records are in fact being truncated in my code. Logs are formatted with zerolog and then T'd out between stdout…
3
votes
1 answer

How to trim white space for query and json in go gin?

I have a struct like this type Data struct { Foo string `json:"foo" binding:"required"` } And I use ShouldBind to bind query or json body to the struct. data := Data{} err := ctx.ShouldBind(&data) I was wondering what is the best practice to…
3
votes
3 answers

Trouble getting reverse proxy working with TLS (to proxied server) in Golang with Gin

I've been tasked with creating a reverse proxy that is required to make a TLS connection to the proxied service. The certificates I have are unique per request, and in-memory. I haven't had much luck getting it right, and I've tried a number of…
Ben Lesh
  • 107,825
  • 47
  • 247
  • 232
3
votes
2 answers

How to log HTTP client's requests with request ID that was created by Gin context

Idea: I want to log incoming and outcoming requests to my Gin server with unique request ID. Also I want to log all HTTP client's requests inside my Gin's routes using the same request ID that route has. All of that should to work under the hood…
joeyave
  • 316
  • 3
  • 11
3
votes
1 answer

Is It Necessary to Add Ack Mechanism To Websocket Server?

We are building a websocket server via golang+gin+json+gorilla websocket to push messages from server side to browser. We plan to provide frontend with some subscription command, which means messages from server side will be sent to those users who…
Wallace
  • 561
  • 2
  • 21
  • 54
3
votes
1 answer

Golang gin proxy to handle svelte frontend and Golang api

I am trying to write a proxy for my api and frontend using Golang and gin. If the request goes to anything except "/api" I want to proxy to svelte server. If goes the "/api/something" I want to handle it in gin. Currently my code is like this. func…
ucktrk
  • 93
  • 2
  • 4
3
votes
2 answers

How to mock a gin.Context?

Hi I've been trying to mock a gin.Context but I have not been able to make it work I was trying what they did in this solution but it does not work with my router this is the error I have been getting r.POST("/urls", urlRepo.CreateUrl) cannot use…
3
votes
2 answers

gorm exec return ID from insert transaction with raw sql

I am using GORM to run SQL queries. I am trying to Exec an INSERT statement as a TRANSACTION because I need to be able to return the latest inserted ID. Here is a code snippet: query := ` START TRANSACTION; INSERT INTO something…
sgerbhctim
  • 3,420
  • 7
  • 38
  • 60
3
votes
3 answers

Swagger UI still showing the example

I want to use Swagger for my RESTFul API Documentation from Go and Gin. I have this code in main.go: package main import ( "gowebservice/config" "gowebservice/controllers" "github.com/gin-gonic/gin" swaggerFiles…
David Winalda
  • 103
  • 1
  • 4
  • 14
3
votes
1 answer

How can use both LoadHTMLGlob and LoadHTMLFiles

I want separator logical template from difference subdirectories under templates folder, the following is my templates folder templates ├── authentication │ ├── login.gohtml │ └── logout.gohtml ├── index.gohtml └── profile └──…
yAnGwAwA
  • 89
  • 1
  • 6
3
votes
1 answer

Undefined validation function "xxx" on field

When I just upgraded Gin from v1.4.0 to v1.5.0, I used the 'BindJSON' function as usual, and threw this error. 2019/11/29 11:44:13 [Recovery] 2019/11/29 - 11:44:13 panic recovered: Undefined validation function 'exists' on field…
ulyC
  • 330
  • 3
  • 11
3
votes
3 answers

How to assert error type json.UnmarshalTypeError when caught by gin c.BindJSON

I'm trying to catch binding errors with gin gonic and it's working fine for all validation errors from go-playground/validator/v10 but i'm having an issue catching errors when unmarshalling into the proper data type. Unsuccessful validation of a…
michogph
  • 35
  • 1
  • 6
3
votes
2 answers

HTTP client receives status code 200 when server panics with gin-gonic and gin-contrib/gzip

When accessing the gin-gonic server below, the HTTP client should receive the code 500, but receives the code 200. package main import ( "github.com/gin-contrib/gzip" "github.com/gin-gonic/gin" ) func main() { …
N.F.
  • 3,844
  • 3
  • 22
  • 53
3
votes
0 answers

how to represent inet column type of postgres for a GORM model?

I am trying to use inet column type of postgres for one of my GORM models my application is a gin-gonic based micro-service which is backed by GORM package for ORM. The default GORM postgres dialect doesn't support this datatype currently. What is…
Sathish
  • 1,245
  • 2
  • 15
  • 22