Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
guozhu cheng
@bengol
I think "broken pipe" is just a network error and trigger an warn log is enough
Phillip Couto
@phillipCouto
@bengol, @kaka19ace I wonder if using context.Done() before rendering the json would help to determine if the user is already gone and we should just end the request / response.
kaixiang zhong
@kaka19ace
@phillipCouto good idea, the action should be operated in gin framework, and just put warning message.
Erudykh
@Erudykh
@phillipCouto thanks dude!
Cristian
@cristianchaparroa
Hi everybody, do you know how to get the path of the handler inside of middleware through the context for example .
r.Get("foo", fooHandler) func Mid() gin.HandlerFunc { return func(c *gin.Context) { p := c.Path() // should be foo } }
Cristian
@cristianchaparroa
fixed with
 path := removeParams(c)  // remove params in case of foo/:param 
....
func removeParams(c *gin.Context) string {
    url := c.Request.URL.String()

    fmt.Println(c.Params)
    for _, p := range c.Params {
        url = strings.Replace(url, p.Value, "", 1)
    }
    return url
}
sorushsaghari
@sorushsaghari
hi guys do you khnow what is the usage of C *gin.context in
type UserSerializer struct {
    C    *gin.Context
    UserModel
}
Phillip Couto
@phillipCouto
@sorushsaghari what package is that in?
First glance it is just attaching a reference to the structure for ease of use instead of passing in as an argument in any function calls on an instance of the structure.
Richard
@moos3
i have a question, if I wanted to generate a token or url that disappeared in 15 minutes after creation, how would I handle that time.Time call ?
Phillip Couto
@phillipCouto
@moos3 for me I usually consider two options. Creating a table in a database to track them if I want to be able to expire them sooner or you create a link that uses an HMAC to verify the parameters in the link are valid.
The key for the HMAC can only be know by the application so that a malicious user can't craft their own.
Henri Idrovo
@henriguy1210

Hi I'm wondering how people handle environment specific configurations with a gin app, I'd love to hear how the community here handles that!

I have a gin app that reads from a cassandra db. So I want to setup up three different configurations for cassandra(dev, test, prod). Thanks!

Richard
@moos3
@phillipCouto yeah I'm playing with tracking them now, just trying to figure out the HMAC
Iurii
@pyxru_gitlab
Hello every! First of all wanna say so much thank for gin, it is best of the best.
Second one, i create simple middleware package for check user on sing in or not, may be will be helpful for some one
Stanislav Valasek
@valasek
I made a starter kit using Gin and Quasar, material design Vue.js framework. PRs, new feature requests, issues, and your feedback are welcomed. https://github.com/valasek/quasar-starter-kit-go-gin
Piyush Bhangale
@officialpiyush
Hi
I had a question, how can we get the params from the url.
With this, I mean that i have a path /i/<code>, where <code is what i want to get
How can I do that?
sorushsaghari
@sorushsaghari
c.Params c.Query
Phillip Couto
@phillipCouto
@moos3 did you figure out HMAC?
DoctorNasa
@DoctorNasa
hi there
Ryan Luo
@Senmumu
hi there
Tiago Cardoso
@tiagoacardoso
Yo folks, is it possible to redirect a request to NoRoute handler?
Tiago Cardoso
@tiagoacardoso
any other way than use context Redirect to a route that doesn't exists?
Phillip Couto
@phillipCouto
@tiagoacardoso create the NoRoute handler as a separate function. Then in the code you want to redirect from just call your function and return to make sure nothing else runs.
Stefanos Chrs
@stefanoschrs
Hello, I have a question, is there any way to skip logging the 200 status requests? There is not much documentation on the logger middleware from what I searched. I'm looking for something like https://github.com/expressjs/morgan#skip
MZERO
@flymzero
test
MZERO
@flymzero
test
Phillip Couto
@phillipCouto
@stefanoschrs I would create a new router with a custom middle ware that checks status code and if not 200 passes the context to the logger:
I would provide a code sample but I can't from my device. If you want I can type one up later when i am on my laptop.
Gopher1980
@gopher1980
HI
I need your opinion of the my little module go for create CRUD on GORM. This module can work with mux or gingonic.
https://github.com/gopher1980/gormcrud
If you want help me, I will thank
Gopher1980
@gopher1980

other ide is use TableName
var suffix string

// Record is the one entity
type Record struct {
ID uint gorm:"primary_key" json:"id"
CreatedAt time.Time json:"created_at"
UpdatedAt time.Time json:"updated_at"
DeletedAt *time.Time json:"deleted_at"
Name string json:"name"
}

func (e Record) TableName() string {

return "record_" + suffix

}

and use suffix = "1"
db.AutoMigrate(&Record{})
suffix = "2"
db.AutoMigrate(&Record{})
I was wrong chat
Richard
@moos3
question, when using a logger middle ware like zerolog, how do I call it in my handlers when I want to log errors?
Rohit Roy Chowdhury
@roychowdhuryrohit-dev
How to validate if a json value was empty for a boolean field of a struct model?
John Napiorkowski
@jjn1056
I'm studying custom validation (https://gin-gonic.com/docs/examples/custom-validators/) and wondering if there's a best practice approach when you custom validation needs to access the database (for example to enforce uniqueness for a username, or require a password to be different than the last 3). Some examples I find via Google suggest just making the DB handler global and adding the SQL directly into the registered validation method. Does that seem like the approach to take? I'm still new to Golang and the idea of a global makes me itchy.
thanks for anything responses, thoughts.
John Napiorkowski
@jjn1056
a smaller question you might be able to answer, I can't seem to find online docs for the Gin API (for example c.ShouldBindWith). Is there an annotated API someplace or do you all just read the source code?
Riley J.
@the-rileyj
Reading the source code or using a search engine with the specific method is what I do
I am having issues with overwriting the 404 returned from NoRoute, I want it to be 200 and it will not set it correctly
Riley J.
@the-rileyj
nevermind, I got it figured out; I was writing the status after writing the content, which caused the 404. Writing the status first solved the problem
bugproof
@bugproof
is this benchmark accurate?
image.png