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

JSON Response: return nested JSON

I am trying to return a JSON response something like this: c.JSON(http.StatusOK, gin.H{"data": resp, "code": http.StatusOK, "status": "success"}) where resp contains data from a db table (struct) which I have converted to JSON. I need to return the…
Ankita Gupta
  • 155
  • 2
  • 14
3
votes
1 answer

go-swagger: no spec available to unmarshal

I am trying to define a swagger operation for my REST endpoint written in Golang. I need to specify the POST request body and responses. // swagger:operation POST /user user createUser // // Creates user // // produces: // - application/json //…
Arjun K S
  • 51
  • 4
3
votes
1 answer

Render HTML files in Go Gin

I'm trying to display the output in HTML templates instead of JSON. Somehow it is not working as expected. I tried in different ways, but no luck. Any help would be great. Here is my code c.HTML( http.StatusOK, "templates/index.html", …
deepu
  • 107
  • 3
  • 10
3
votes
1 answer

gin/golang gin-gonic does not parse time.Time properly for unix json?

I cannot find the way to execute this code properly with UNIX: package main import ( "time" "github.com/gin-gonic/gin" "net/http" ) type Things struct { Name string `json:"name"` OneDay time.Time `json:"oneDay"` } type Example struct { …
juan garcia
  • 1,326
  • 2
  • 23
  • 56
3
votes
2 answers

How to avoid Golang server (Gin Gonic) to crash on INTERNAL_ERROR

first of all : I'm new to Go, I come from years of java development. I have developed a little REST API using Gin Gonic. One of my endpoint occasionally (so I can't reproduce on demand) crashes during an HTTP Get to an external API I don't manage.…
tlebrun06
  • 81
  • 1
  • 7
3
votes
1 answer

How to set a host on gin's test context?

I would like to write a unit test for a controller but I keep getting a runtime error. I found out that it is due to the absence of the Host on the request, the ClientIP() method and request body. How can I set them on the test context? Here is what…
jz22
  • 2,328
  • 5
  • 31
  • 50
3
votes
1 answer

Gin-Gonic Content-Type restriction

There is a service written in golang, using gin-gonic framework. I only ever want to support application/json as a mime-type and it would be great if it always be in UTF-8. The business logic of the service might break if it will get values in…
dmigo
  • 2,849
  • 4
  • 41
  • 62
3
votes
2 answers

Can gin framework get json post data like `map[string]interface{}` instead of binding with struct?

As title said, I am writing an API taking whatever json data that client posts. Is there any way directly get a map[string]interface{} type data like bson.M? I've tried simply looking up properties of gin.Context, is any of them would help if I miss…
Joe
  • 117
  • 1
  • 6
3
votes
1 answer

how to make multiple models auto migrate in gorm

i can see the documentation we do automigrate like this, db.AutoMigrate(&model.TheTodo{}) how about if we have a lot of multiples models? db.AutoMigrate(&model.TheTodo{}, &model.TheBlog{}, &model.Employee{}, and many more...... ) will gorm create…
temps hd
  • 71
  • 1
  • 10
3
votes
1 answer

How to render/show images in HTML created on the fly with Golang and gin-gonic

I'am generating QR codes and right after I need to show them in an HTML without saving them as images. So far I can generate them but I have problems rendering them in the HTML I have here the golang code that generates the QR and the HTML template…
kike
  • 658
  • 1
  • 8
  • 26
3
votes
2 answers

How to make a generic form function for froms with interfeces with gin (framework) and golang?

I want to create a function to process anykind of forms. I want it to be able to handle any kind of data types. Im trying to use a interface to do this task. type Person struct { name string lastName string } func HTMLForm(c…
3
votes
0 answers

path segment conflicts with existing wildcard in path

I want to rewrite flask application in golang-gin, and i have a path problem in routes, :status have only 3 version start pause end , this is my current routes : contracts.POST("/:id/:status", s.contractChangeStatus) …
kodiu
  • 61
  • 2
  • 6
3
votes
2 answers

Expose Prometheus metrics in a separate port in golang

In a microservice running gin-gonic, I'm trying to collect metrics in a router and expose them on a second one, but it seems this is not possible. Does anyone have experience in it? All the documentation I found set the prometheus handler into the…
Simone Cabrino
  • 901
  • 9
  • 24
3
votes
2 answers

Gin framework can not get the data from Postman

Gin framework can not get the data from Postman,below is a demo: package main import ( "fmt" "github.com/gin-gonic/gin" ) type CreateRequest struct { Username string `json:"username"` Phone string `json:"phone"` Password…
zwl1619
  • 4,002
  • 14
  • 54
  • 110
3
votes
1 answer

Gracefully handle template rendering errors in gin-gonic

I'm learning Go and using gin-gonic for a web application. I'm trying to recover gracefully from template errors and haven't been able to figure out how to buffer output or redirect properly to achieve this. With this code: package main import ( …
Parnic
  • 33
  • 6