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
0 answers

err no such file or directory - go file uploader - when i run binary of (go build)

i have below uploader func SaveFile(c *gin.Context) { // Source file, err := c.FormFile("file") if err != nil { c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error())) return } filename :=…
tp-lovers
  • 39
  • 6
2
votes
1 answer

How to add default header to response in golang gin?

How to add default header to response returned in Gin golang? I wanted to add Cache-Control: public, max-age=604800, immutable to the every response that I return.
Madiyor
  • 761
  • 9
  • 23
2
votes
2 answers

Golang Gin retrieve integer data

I'm trying to retrieve int data from POST requisitions with Gin, but I'm getting an error saying that the functions (PostForm, or any other) expects strings as arguments. I've tried to search for a function expecting int content, but with no…
Vinicius Mocci
  • 99
  • 3
  • 12
2
votes
1 answer

Can't update model that have one to many association

I have this struct in model package type Item struct { LineItemID uint `json:"lineItemId" gorm:"primaryKey"` ItemCode string `json:"itemCode"` Description string `json:"description"` Quantity int `json:"quantity"` …
David Winalda
  • 103
  • 1
  • 4
  • 14
2
votes
1 answer

Use existing session cookie in gin router

I'm building a simple webserver in Go / Gin and I want to use cookies to create a persistent session that keeps a user logged in if they navigate away or navigate across several pages. Ideally, this is the flow: initialize router check for an…
symtek
  • 51
  • 1
  • 8
2
votes
1 answer

How to validate API key in go-gin framework?

So I currently have a function that will take in a string APIKey to check it against my MongoDB collection. If nothing is found (not authenticated), it returns false - if a user is found, it returns true. My problem, however, is I'm unsure how to…
Zander
  • 123
  • 1
  • 2
  • 14
2
votes
0 answers

How to detect the json in request body has null value for a key or key is not given

I'm creating a API server using Go gin framework. Now I trying to add PATCH operation for /users endpoint. PATCH operation receives partial properties in json request body and updates the properties of the User model. In this case, the properties…
toshiya
  • 183
  • 2
  • 13
2
votes
2 answers

How to handle nested structures in golang for Elasticsearch replies?

I have an API service written in Go, using gin-gonic, which is backed by an Elasticsearch service. Queries hit the API, the API server queries Elasticsearch, Elasticsearch replies with the search results to the API, and the API serves the results…
mbenoit6
  • 21
  • 2
2
votes
1 answer

Cobra CMD does not executes completly

I have the following code, is really simple. The point is that the code after the first fmt.Println is never executed. Any idea why? The code creates a random string, and then creates a Gin Router. The code that executes the router is never being…
2
votes
2 answers

use same struct for both create and update operations in go lang using gin and gorm

Disclaimer: go lang noob here I've my user struct as type User struct { ID uint32 `json:"id"` FirstName string `json:"firstName" binding:"required"` LastName string `json:"lastName"` Email string `json:"email"…
ahhmarr
  • 2,296
  • 4
  • 27
  • 30
2
votes
1 answer

serve video with go gin

I am writing a api server for upload and serve video and image by go-gin framework. I have uploaded my video to another host, and it worked router := gin.Default() //config := cors.DefaultConfig() //config.AllowAllOrigins = true …
Tin Huynh
  • 55
  • 5
2
votes
1 answer

How to validate data from a middleware go-gin

Trying to learn golang, and I am lost on working with the context.Request.Body and its struct in a validation middleware briefly how do they connect to each other, thanks in advance for your help My middleware package validations import ( …
bihire boris
  • 1,530
  • 3
  • 19
  • 44
2
votes
2 answers

i18n support for Golang Web application HTML templates

Does anyone has a good idea to localize HTML templates in Golang Web application? Now I'm using Gin and go-i18n, but I will use other frameworks if they can localize. If possible, I want to define the localized messages in property (or…
Kohei TAMURA
  • 4,970
  • 7
  • 25
  • 49
2
votes
1 answer

fabric-sdk-go Execute Not always updating ledger

I am using client.channel.Execute API in fabric-sdk-go to invoke the ledger update Txs in chaincode. I know my chaincode for ledger update is correct because invoke Tx when run from cli container command line is working perfectly all the times. Few…
2
votes
1 answer

Go Gin converting json response to base64

I am trying to send db query data as json response . Here is my controller : import ( "fmt" "github.com/json-iterator/go" "log" ) func GetNewsPapers() []byte{ db := GetDB() var json =…
pyprism
  • 2,928
  • 10
  • 46
  • 85