These are chat archives for gin-gonic/gin

18th
Jul 2017
Jim McDonald
@mcdee
Jul 18 2017 09:41
Hi is it possible to route in gin based on a header value? Specifically, the incoming request sets an APIVERSION header that I need to use to send the request to the correct version of the endpoint function (separate functions for each version)
Thomas Boerger
@tboerger
Jul 18 2017 10:05
I don't think that this is possible with the router directly
Moggers
@Moggers
Jul 18 2017 11:19
Hello fellow alcoholics
How do I "finish" a request in the middleware?
When I return its chaining on the actual request- but I'm writing auth so if I dont explicitly next() I want it to not fall through to the request
Phillipp Schmedt
@phillippschmedt
Jul 18 2017 14:44
How do you guys do your basic deployment? How do you ship stuff like your templates and other assets
Thomas Boerger
@tboerger
Jul 18 2017 14:59
I'm bundling the assets into my binary via fileb0x
I have also added a flag that can optionally overwrite the embedded assets if they can be found on the path specified by the flag
Here you can see the http Filesystem that provides the optional overwrites, Otherwise it got the fallback to embedded resources https://github.com/webhippie/ldap-proxy/blob/master/pkg/assets/assets.go
Phillipp Schmedt
@phillippschmedt
Jul 18 2017 15:03
I am not really a big fan of embedding assets (yet). Is there any other popular approaches? :D
Thomas Boerger
@tboerger
Jul 18 2017 15:04
Just a static path
Phillipp Schmedt
@phillippschmedt
Jul 18 2017 15:05
So you would just for example zip your binary + assets and move to server and start?
Thomas Boerger
@tboerger
Jul 18 2017 15:05
I like the embedding combined with the option to serve custom assets :)
Yes, or rsync
I'm personally deploying only docker containers these days
Phillipp Schmedt
@phillippschmedt
Jul 18 2017 15:06
I come from a Spring MVC background, so for me it's pretty normal to deal with WAR files that just includes all you need
Thomas Boerger
@tboerger
Jul 18 2017 15:07
Nothing like that within the go world :)
Phillipp Schmedt
@phillippschmedt
Jul 18 2017 15:10
I think I will just make a resources directoy that includs all kinds of assets, templates, css, js, images and stuff like that
So I only need to zip that directory and my binary and are good to go
I already had a lot of fun today trying to cross compile https://github.com/mattn/go-sqlite3
I didn't succeed.
Thomas Boerger
@tboerger
Jul 18 2017 15:12
xgo ftw!
https://github.com/karalabe/xgo works pretty well for my to cross-compile even go-sqlite3
Phillipp Schmedt
@phillippschmedt
Jul 18 2017 15:13
Yes I am using xgo now :D
Just a little bit sad that it takes quite some while now
Phillipp Schmedt
@phillippschmedt
Jul 18 2017 16:14
I am trying to start my server in RELEASE mode, i get no message but the process wont start
Any idea what I can do? It starts fine in DEBUG mode
[ERROR] listen tcp 0.0.0.0:80: bind: permission denied
That's the problem. Interesting that this error is not printed in RELEASE Mode?
Phillipp Schmedt
@phillippschmedt
Jul 18 2017 17:30
I slowly get the hang of go and gin :D
unreadable
@unreadable
Jul 18 2017 17:52
Try sudo
Gin is amazing, I find it very productive with a very clean api
Thomas Boerger
@tboerger
Jul 18 2017 17:55
@schmedt you are just not fetching the error properly
Jim McDonald
@mcdee
Jul 18 2017 17:56
You might want to take a look at authbind rather than running the process as root
Thomas Boerger
@tboerger
Jul 18 2017 17:59
Or just use another port
unreadable
@unreadable
Jul 18 2017 18:21
Try this if you're on unix
lsof -i :80
kill -9 <PID>
You'll see PID listed below
Nvm, won't gonna solve it
Phillipp Schmedt
@phillippschmedt
Jul 18 2017 18:27
Not using it as root. I redirect 80 traffic to 8080 with iptables now.
Phillipp Schmedt
@phillippschmedt
Jul 18 2017 21:06
How can I declare a variable inside a template? Can anyone help me?
https://play.golang.org/p/QsIXcvCobw - Anyone knows how to get this to work / make it easily readable. I don't want to inline everything inside the class attribute.
Javier Provecho Fernandez
@javierprovecho
Jul 18 2017 21:19
@schmedt i'm not sure if you mean really to declare a variable inside the template (see https://golang.org/pkg/text/template/#hdr-Variables) or to use a variable inside the template ({{ .myVariable.MyField }})
Phillipp Schmedt
@phillippschmedt
Jul 18 2017 22:28
@javierprovecho Thanks. If I want to add some data to every view I ender. Like the BaseURL. How could I do that with gin?
unreadable
@unreadable
Jul 18 2017 23:36
func main() {
router := gin.Default()
router.LoadHTMLGlob("templates/")
//router.LoadHTMLFiles("templates/template1.html", "templates/template2.html")
router.GET("/index", func(c
gin.Context) {
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"title": "Main website",
})
})
router.Run(":8080")
}
It was taken from example
Takken*
Taken* lol