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

How golang gin stop handler function immediately if connection is lost

I am using gin-gonic/gin to write my server. It seems even if the connection is lost, the handler function is still running. For example, if I visit http://127.0.0.1:8080/ping and close the browser suddenly, the screen will continue to print all the…
qing6010
  • 99
  • 3
  • 7
2
votes
1 answer

Create new struct and append it to array in a one to many relationship

I'm trying to append a new item to an array in a one-to-many relationship. The problem is that one of the IDs is always undefined and the model I want to append to does not get updated. I have the following models: type Station struct { …
JesterWest
  • 499
  • 1
  • 5
  • 13
2
votes
2 answers

Using Gin gonic and some scheduler in Golang

I have some REST service in Gin Gonic, and I need to do some job every 5 seconds using some scheduler. I've tried rakanalh and gocron but it seems that every code written after initializing crons or gin routes will not execute. func main() { …
mondayguy
  • 973
  • 2
  • 12
  • 34
2
votes
2 answers

Axios POST on Gin-Gonic (golang) Server Not Working

I can use GET, but I cannot use POST from axios, sending data to my gin-gonic golang server. It works perfectly in Postman. When I shoot over the request with Axios, I get nothing in return. When I go into the gin-gonic server, it shows that it…
luminol
  • 407
  • 4
  • 15
2
votes
2 answers

File Download works with Chrome but not in Firefox when downloading golang generated file

I have simple golang/gin-gonic REST Service that serves an excel report upon request to /api/billing. When the requester sets the accept header to application/vnd.openxmlformats-officedocument.spreadsheetml.sheet then an Excel file is served…
Vad1mo
  • 5,156
  • 6
  • 36
  • 65
2
votes
1 answer

How to log response body in gin while I redirect the initial request

I'm trying to log the response body of a request that has been redirected. func main() { r := gin.Default() eanAPI := api.NewEanAPI() v1 := r.Group("/v1") v1.POST("/*action", eanAPI.Redirect, middleware.SaveRequest()) port…
Nizar AYARI
  • 203
  • 2
  • 12
2
votes
3 answers

golang can not find package gin in sub directory

I get the following error message: controllers/user.go:4:2: cannot find package "(underscore)/home/ubuntu/goapi/src/github.com/roes/api/vendor/github.com/gin-gonic/gin" in any of:…
Jerry H
  • 135
  • 1
  • 2
  • 10
2
votes
2 answers

How to gracefully handle errors in web service

I am writing a simple REST API in go using gin. I have read many posts and texts about making error handling less repetitive in go, but I cannot seem to wrap my mind around how to do it in gin handlers. All my service does is run some queries…
Mad Wombat
  • 14,490
  • 14
  • 73
  • 109
2
votes
3 answers

Installing swaggo on windows (swagger + gin)

I am trying to setup swagger for gin-gonic on windows. Documentation of swaggo states that I should run: go get -u github.com/swaggo/swag/cmd/swag After installation I should be able to run swag init from within the root of my project where I have…
Bob Meijwaard
  • 388
  • 9
  • 20
2
votes
1 answer

type *gin.Context has no field or method SaveUploadedFile

My code works fine on my computer but I get this compile-time error on my server after I moved the code to the Debian server: type *gin.Context has no field or method SaveUploadedFile I use sample gin code to save file: if err :=…
Karlom
  • 13,323
  • 27
  • 72
  • 116
2
votes
0 answers

signal: killed and server freezes after post

I have this weird message after successfully posting an article. [GIN] 2017/07/18 - 08:43:21 | 200 | 42.729836ms | 127.0.0.1 | POST /api/articles signal: killed The post that I make using curl is: curl -X POST…
Karlom
  • 13,323
  • 27
  • 72
  • 116
2
votes
2 answers

Reading QueryArray from Gin golang

Hi I am passing a query parameter to my gin server like this: curl -X POST \ 'http://localhost:4000/url?X=val1&Y=val2&x[]=1&x[]=2' This is then sent to the my gin handler function func handler (c *gin.Context) { fmt.Println(c.Query("X")) …
manugupt1
  • 2,337
  • 6
  • 31
  • 39
2
votes
1 answer

Golang/gin: How to Pass db to router functions

I'm using gin framework. And I'm opening the sqlite database in the main function like this func main() { ... db, err := sql.Open("sqlite3", "./libreread.db") CheckError(err) defer db.Close() ... } And I have these router handlers in the main…
rnk
  • 2,174
  • 4
  • 35
  • 57
2
votes
1 answer

How to create swagger.json in go gin-gonic

I am trying to add documentation to my golang project which has been created using gin-gonic. The problem I am facing currently is that gin-gonic's stable version does not support swagger. Issue in gin-gonic Currently when I try to generate the…
Akamad007
  • 1,551
  • 3
  • 22
  • 38
2
votes
1 answer

How to create a authentication model to restful API using golang gin?

I hope to create a authentication model to my restful API. Hope to use API token and I'm using MVC in web service and I created a auth.go controller like this. package controllers import ( "github.com/gin-gonic/gin" "os" …
Nuwan Indika
  • 41
  • 1
  • 4
  • 9