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
-1
votes
2 answers

Should I declare variables in package level but outside of http handler?

I'm using gin gonic as an HTTP framework and I need to group some paths with shared variable by like this: ur := r.Group("/") ur.Use(package.Prepare) { ur.GET("/", package.Home) } Inside the Prepare handler, I declare package variable…
TomSawyer
  • 3,711
  • 6
  • 44
  • 79
-1
votes
1 answer

How to handle the errors in Golang for inserting a duplicate keys?

When I insert a record to the database it is saving, but my problem is that in Golang I am not able to handle errors. Suppose right now I am getting the error like Duplicate keys in my console but rather I want to handle it in JSON response, how…
waseem khan
  • 65
  • 1
  • 3
  • 8
-1
votes
1 answer

Location of full HTML POST form data in Golang

I am posting an HTML form to a Golang/Gin backend. The following allows me to access individual values from the form in the backend: titleValue := c.PostForm("Title"); contentValue := c.PostForm("Content"); But I cannot figure out how to access the…
223seneca
  • 1,136
  • 3
  • 19
  • 47
-1
votes
1 answer

What is the correct way to save post data (with integer and string values) in the database golang?

I've the following golang code: package main import ( "github.com/gin-gonic/gin" "gopkg.in/mgo.v2" "gopkg.in/mgo.v2/bson" "log" "time" ) func main() { router := gin.Default() router.POST("/save-address", SaveAddress) …
Swati
  • 83
  • 1
  • 14
-2
votes
2 answers

GoLang custom package import issue

I'm learning GoLang, and got into an issue. I created the mod file with go mod init main Next I created controller and Routes folder which looks something like below: ├── contollers │   └── users.controller.go ├── routes │   ├── index.go │   └──…
Nick
  • 689
  • 14
  • 27
-2
votes
2 answers

'go mod init example.com/m' to initialize a v0 or v1 module

I am learning at https://youtu.be/ma7rUS_vW9M?t=73 Video My environment D:\temp2023_03_01\go\src>go version go version go1.20.1 windows/amd64 My actions Microsoft Windows [Version 10.0.22621.1265] (c) Microsoft Corporation. All rights…
Vy Do
  • 46,709
  • 59
  • 215
  • 313
-2
votes
1 answer

Assertion failed for interface as gin.HandlerFunc

package main import ( "fmt" "github.com/gin-gonic/gin" ) func Foo(ctx *gin.Context) {} func main() { var v interface{} v = Foo _, ok := v.(func(*gin.Context)) fmt.Println(ok) // true _, ok = v.(gin.HandlerFunc) …
keepeye
  • 19
  • 2
-2
votes
1 answer

How do I get the body that was sent? Using gin gonic

How do I get the body that was sent? package main import ( "fmt" "github.com/gin-gonic/gin" ) func main() { fmt.Println("Hello, world!") r := gin.Default() r.POST("/", func(c *gin.Context) { body := c.Request.Body …
Овов Очоы
  • 453
  • 1
  • 5
  • 12
-2
votes
1 answer

Function which returns list of struct from gorm database returning nil?

I'm trying to make a function that will output all of the contents from a table as a slice of the struct the table is. func FetchAll(parameter interface{}) []interface{} { var model interface{} var resultArray []interface{} db :=…
ErikDz1
  • 17
  • 3
-2
votes
1 answer

Replace incoming post request data before bind with Go Gin?

I made a simple post API to store articles in database using Gorm And Go Gin. problem with API showing when I tried to post the category name instead of the category id because the struct declaring it as int32 type I made a simple function to…
Marco
  • 842
  • 6
  • 18
  • 42
-2
votes
1 answer

Why can't I start two servers in the same Go project?

I am a new Go developer and I am trying to build a single project that has both a gRPC server and a Gin HTTP server. This is what my code roughly looks like: package main import ( "log" "net" "github.com/gin-gonic/gin" …
JackH
  • 4,613
  • 4
  • 36
  • 61
-2
votes
1 answer

How to change the resolution of an image?

How do I change the resolution of this image before uploading? f, uploadedFile, err := c.Request.FormFile("file") // image file if err != nil { c.JSON(http.StatusInternalServerError, gin.H{ "message": err.Error(), "error": …
AgentRed
  • 62
  • 5
  • 36
-2
votes
1 answer

Refresh static files in gin-gonic

My application uses the Gin Web Framework for various tasks, one of which is serving static files (Vue.js). In regular intervals calls get made to this API which then updates the data in the DB. This data gets displayed through those static files.…
kaiyonami
  • 3
  • 2
-2
votes
1 answer

Pass an interface{} type with pointer value to an interface{} parameter

I have two function in my code, a parent function with interface{} parameter type and another child function with interface{} parameter type. I called childFunc in parentFunc and assert parent param to *interface{} and pass it to childFunc and at…
-2
votes
1 answer

How to get the claims from the token?

I have a GenerateToken function that generates the token based on Username, Id and the combination of Standard Claims. func GenerateToken( creds *users.User) (tokenString string, err error){ expirationTime := time.Now().Add(100 * time.Hour) …
Abhinav
  • 83
  • 1
  • 10