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

How to get matched route in context in Gin?

I have this code : package main import ( "net/http" "github.com/gin-gonic/gin" ) func main() { r := gin.New() r.GET("/user/:id", func(c *gin.Context) { // How can I get the litteral string "/user/:id" here ? …
ning
  • 41
  • 1
  • 3
3
votes
1 answer

Golang reverse proxy returns Not found or Forbidden Errors

I'm trying to create a reverse proxy that takes all requests and redirect them into a target url, like google.com or any other API. Unfortunately, all targets returns errors like page Not Found, or Forbidden Errors func main() { r :=…
Nizar AYARI
  • 203
  • 2
  • 12
3
votes
1 answer

Variable in handler is not passing to template

Learning Go and Gin from here. So I have a router like this userRoutes.POST("/login", ensureNotLoggedIn(), performLogin) and the handler function is like this func performLogin(c *gin.Context) { username := c.PostForm("username") password :=…
tomriddle_1234
  • 3,145
  • 6
  • 41
  • 71
3
votes
1 answer

How to get field with error from gin binding/validation?

I have this code: package main import ( "fmt" "github.com/gin-gonic/gin" ) type TestForm struct { Age int `form:"age" binding:"required"` Name string `form:"name" binding:"required"` } func home(c *gin.Context) { …
binary01
  • 1,728
  • 2
  • 13
  • 27
3
votes
1 answer

How to render HTML with golang data in golang gin web frame?

I am trying to place a golang array (also slice, struct, etc.) to HTML so I can use array element in HTML Element content when returning HTML from golang gin web framework. Another problem is how to render these data with loop? Such as Flask…
sixsixsix
  • 1,768
  • 21
  • 19
3
votes
1 answer

Need type assertion on functions

I'm trying to learn type assertion and conversion. It's kinda complicated for me. I have this example: (I'm using gin framework) type Env struct { db *sql.DB } func main() { r := gin.Default() // Initiate session management…
rnk
  • 2,174
  • 4
  • 35
  • 57
3
votes
1 answer

How to set http headers for static files?

I use gin-gonic's r.Static("files", "./files") to serve all files in the files directory. Is there a way to set headers for these file requests so I can allow CORS?
homeboy
  • 171
  • 12
3
votes
2 answers

Golang gin: serving JSON and static files in the same app

I am writing a golang gin app that serve both REST API and static files. Ideally I should separate the backend and front-end logic but for this case I have to put them together. For example, the top-level path of the API is wild-card, like…
YCSeattle
  • 63
  • 1
  • 1
  • 3
3
votes
2 answers

How to ensure redis subscriber receive message in Go (Golang)?

I'm using gin framework to build an API server. In General, I'm build 2 projects. Project 'API' and Project 'SOCKET'. Project 'API' is the main REST API that will used in Android, developed using gin framework (golang). And Project 'SOCKET' is the…
user7309727
3
votes
1 answer

how to debug Gin Web Framework

I am using Go gin for REST API. In ruby on rails application i can debug using debugger or pry. How can i do same in gin framework? Edited: consider the following request. curl -X GET localhost:5005/test_controller/test_action --data '{ "sw_lat" :…
Gurunath
  • 341
  • 3
  • 17
3
votes
2 answers

Mocking functions in Golang to test my http routes

I'm totally confused figuring out how I can mock a function, without using any additional packages like golang/mock. I'm just trying to learn how to do so but can't find many decent online resources. Essentially, I followed this excellent article…
Jenny Blunt
  • 1,576
  • 1
  • 18
  • 41
3
votes
1 answer

How to send an array of maps and iterate over it using gin-templating

Following is the snippet of a working code. I am using gin templating engine. c.HTML(200, "index", gin.H{ "title": "Welcome", "students": map[int]map[string]string{1: {"PID": "1", "Name": "myName"}},}) And in index…
codec
  • 7,978
  • 26
  • 71
  • 127
3
votes
1 answer

Is there anyway to close client request in golang/gin?

Using gin framework. Is there anyway to notify client to close request connection, then server handler can do any back-ground jobs without letting the clients to wait on the connection? func Test(c *gin.Context) { c.String(200, "ok") …
fannheyward
  • 18,599
  • 12
  • 71
  • 109
2
votes
1 answer

gin checks array of json objects

go version:1.18 request params { "questions_batch_id": "1", "answer_list": [ { "questions_ids": "1", "answer": [ "2222","3333" ] } ] } validate code: type Answer struct…
2
votes
1 answer

Go Gin: Validating base64

I am trying to send a base64 image to my server written in Go using Gin. I created a struct with binding and json tags to represent the request body, it looks as follows: type createCompanyRequestBody struct { Name string `json:"name"…
Bram Vanbilsen
  • 5,763
  • 12
  • 51
  • 84