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

same code but different results using gin + go-template

Basic information Go version: go1.4.2 darwin/amd64 Operating System: Mac OS X 10.10.5 I'm working on a small Web project written based on go and gin. Here is my golang code. After running go run test.go we have a web server, which is listening on…
Miaonster
  • 1,482
  • 2
  • 18
  • 32
9
votes
1 answer

Return custom error message from struct tag validation

I'm using Go 1.17 with Gin and I want to implement a struct validation before sending the data to my database. I took the example from Gin documentation. In the struct we can declare different tags to validate a field like this: type User struct { …
John
  • 4,711
  • 9
  • 51
  • 101
9
votes
3 answers

Gin-Gonic middleware declaration

I'm using Gin-Gonic and I'm creating a custom middleware. See: https://github.com/gin-gonic/gin#custom-middleware Is there a reason why the middlewares in the doc are written as such: func MyMiddleware() gin.HandlerFunc { return func (c…
cHz
  • 103
  • 1
  • 1
  • 6
9
votes
1 answer

Golang/gin parse JSON from gin.Context

I learned from the gin doc that you can bind json to a struct like type Login struct { User string `form:"user" json:"user" binding:"required"` Password string `form:"password" json:"password" binding:"required"` } func main() { …
Lucas Liu
  • 823
  • 1
  • 10
  • 12
9
votes
4 answers

Gin Gonic array of values from PostForm

I'm trying to capture an array of Post values from HTML form using Go / Gin Gonic -- in PHP I would use something like:
BadPirate
  • 25,802
  • 10
  • 92
  • 123
9
votes
2 answers

Returning JSON data as a stream per chunk to Angular2 or jQuery over HTTP2 (HTTPS)

In one of my API's I mostly return a result (let's say paged 50 results) as one whole in an json array like so: [{},{},{},{},{},...] I was wondering if there are better ways of doing this over HTTP2 (as it has many new partial streaming features)…
user1467267
9
votes
1 answer

gin/golang - Empty Req Body

I'm new to Go and Gin, and am having trouble printing out the full request body. I want to be able to read the request body from third party POST, but I'm getting empty request body curl -u dumbuser:dumbuserpassword -H "Content-Type:…
Leon Hu
  • 137
  • 1
  • 1
  • 5
8
votes
1 answer

Golang Gin Redirect and Render a Template with New Variables

I am trying to pass some variables after some processes on my Handler function. How can I redirect to a new page an pass some json variables to this new template? // main package func main() { apiRoutes := gin.Default() …
Majid Alaeinia
  • 962
  • 2
  • 11
  • 27
8
votes
0 answers

Nginx(as reverse proxy) does not notify gin-gonic(as web server) when connection canceled by client

In a website which uses gin-gonic as webserver and nginx as a proxy server, clients send their data to the server via gin-gonic exposed APIs, and — in order to send server commands to clients — each one(i.e client) has a connection to the web server…
Bonje Fir
  • 787
  • 8
  • 25
8
votes
2 answers

JSON response in Golang’s GIN returning as scrambled data

I have array of a struct being created from data I collected from the database. For simplicity, lets say this is the struct: type Person struct { ID int `db:"id, json:"id"` } type PessoalController struct{} func (ctrl PessoalController)…
Auyer
  • 2,693
  • 3
  • 15
  • 32
8
votes
2 answers

How to get file posted from JSON in go gin?

I want to save image file posted by JSON. Here is the struct of the post: type Article struct { Title string `json:"title"` Body string `json:"body"` File []byte `json:"file"` } And the handler is : func PostHandler(c…
Karlom
  • 13,323
  • 27
  • 72
  • 116
8
votes
1 answer

How to use templates in Go Gin for dynamic content

I have a simple Go / Gin web app. I need to put some dynamic content in html template. For e.g. I have a few tables (the number is dynamic) with a few rows (the number is dynamic). I need to put them in html template. Is there any way to combine…
kikulikov
  • 2,512
  • 4
  • 29
  • 45
8
votes
3 answers

GoLang Gin Framework Status Code Without Message Body

I'm using GoLang and Gin Framework. I need to respond for REST API call with 204 response code without message body. How it is to do properly? What I could find by digging the source code c.JSON(204, "") But server throws error at such case: Error…
Bogdan Nechyporenko
  • 1,226
  • 2
  • 14
  • 21
7
votes
5 answers

Serving react static files in golang gin-gonic using go:embed giving 404 error on reloading on frontend URL

I have built a go application using gin and go1.17. I am using go:embed to to serve static content for a SPA app built using react. (trying the approach as suggested in https://github.com/gin-contrib/static/issues/19). My frontend files are in a…
Harsh Agarwal
  • 675
  • 2
  • 13
  • 28
7
votes
2 answers

How to get full server URL from any endpoint handler in Gin

I'm creating an endpoint using Go's Gin web framework. I need full server URL in my handler function. For example, if server is running on http://localhost:8080 and my endpoint is /foo then I need http://localhost:8080/foo when my handler is…
Kaushal28
  • 5,377
  • 5
  • 41
  • 72
1 2
3
50 51