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

go-gin request cancellation

How do I cancel further processing if the connection is closed before 10 seconds? There is c.Request.Context().Done() but coudn't find an example on how to use it. func main() { r := gin.Default() r.GET("/ping", func(c *gin.Context) { …
iamvinitk
  • 165
  • 3
  • 15
7
votes
3 answers

Go-Gin read request body many times

I am trying to restore the context with it's data after performing validation on it's data.I need the data to keep moving as need it later on in the next function. I am new to golang and the below code is as far I could go. any help and a better…
bihire boris
  • 1,530
  • 3
  • 19
  • 44
7
votes
2 answers

How to combine group of routes in gin?

I have created two different Groups for gin routing specifically /user and /todo in two different packages and I want to merge them into one file . Here is my userroutes.go file. package userrouter import ( …
p_k
  • 87
  • 1
  • 7
7
votes
1 answer

c.JSON gin.H{()} outputs empty objects

I just started to learn GO(lang) in combination with Gin framework and I've decided that I will write some simple api for fetching data about alcohol drinks. My current problem is that api (get method on http://localhost:8080/alcohol-drinks) returns…
Valor_
  • 3,461
  • 9
  • 60
  • 109
7
votes
1 answer

Transform gin.Context to context.Context

Is there a way to transform gin.Context to context.Context in Go? What should be used in building a Go microservice?
Vishal R
  • 1,026
  • 1
  • 7
  • 21
7
votes
1 answer

Syntax question from `gin-gonic` documentation

I have been developing in Node/Python for years, and over the holiday I have been trying to expand my knowledge of Go. I have a pet project that I've been working on to learn it. As I have been reading the gin-gonic documentation, I found syntax…
Spencer Stolworthy
  • 1,352
  • 10
  • 17
7
votes
3 answers

How to get header data of postman using gin package in golang

I want to get the header data using gin package(golang) in the postman but I don't get any idea how to do it. I search it for google but not getting any answer. Can anyone help me to get the data from the postman header the data I want to get is…
Puneet
  • 615
  • 2
  • 7
  • 17
7
votes
1 answer

Listen on TCP4 not TCP6

I am using https://github.com/gin-gonic/gin to write an http service But when I deploy it, it keeps deploying on tcp6(according to netstat) r := gin.Default() //none of these are working , It keeps being listed on…
user914584
  • 571
  • 8
  • 15
7
votes
2 answers

How To pass a function to template through c.HTML() in gin gonic framework (golang)

I want to pass a function through c.Html() function of type Context in gingonic. For example, if we want to pass a variable, we use c.HTML(http.StatusOK, "index", gin.H{ "user": user, "userID": userID, }) And in html we…
Vutuz
  • 458
  • 1
  • 7
  • 19
7
votes
1 answer

How to write golang code in html file (gin gonic framework)

Im newbie in golang code as well as in gin gonic. I got a problem while using gin gonic. In my controller. i get all articles and render to html file by code. c.HTML(http.StatusOK, "articles/list", gin.H{ "title": "Articles", "articles":…
Vutuz
  • 458
  • 1
  • 7
  • 19
7
votes
1 answer

Testing gin based REST API not getting params while using net/http/httptest

I am developing a REST API based on Gin Go, the endpoint looks something like below: func carsByType(c *gin.Context) { fmt.Println("Go Request in Handler...") carType := c.Params.ByName("type") fmt.Println(carType) if carType != ""…
Alex Benz
  • 395
  • 4
  • 14
6
votes
3 answers

Can't install gin-gonic: c.engine.AppEngine undefined (type *Engine has no field or method AppEngine)

I can't install gin-gonic for my golang project. I tried reinstalling go, resetting the bash files, delete and recreate the project folder, and searched the error as keyword on google, but found nothing Here are my terminal messages: $ go get -u…
Indra
  • 61
  • 3
6
votes
2 answers

How to correctly set Mock Row and Query for go-sqlmock

I'm setting up testing in golang. I use go-sqlmock to test mysql connection. But sqlmock.NewRows and mock.ExpectQuery does not work well with error. I want to know how to resolve this error. server side: golang db: mysql web framework:…
jpskgc.v5
  • 249
  • 1
  • 5
  • 9
6
votes
1 answer

How to handle these routes: /example/log and /example/:id/log?

I tried something like this: router.GET("/example/log", logAllHandler) router.GET("/example/:id/log", logHandler) But Gin does not allow this and panics upon start. An idea is write a middleware to handle this case, but ...
6
votes
4 answers

Using Gin: How to pass original JSON payload to a Redirect POST

I'm a newbie when it comes to Go and Gin, so please excuse my ignorance. I've setup a server using Gin which supports a POST request. I would like the user to POST their request which includes a required JSON payload redirecting that request to…
user6938349
  • 63
  • 1
  • 3