These are chat archives for gin-gonic/gin

14th
Jul 2017
sgon00
@sgon00
Jul 14 2017 15:11
hi, I am trying to run an official example in github's README.md, the code is https://hastebin.com/oyaqipiwey.go . But I got an error msg when runing the server: go run main.go, the error msg is: # command-line-arguments c.SecureJSON undefined (type *gin.Context has no field or method SecureJSON). Can anyone tell me why? thanks a lot.
Javier Provecho Fernandez
@javierprovecho
Jul 14 2017 15:16
@sgon00 run go get -u github.com/gin-gonic/gin
sgon00
@sgon00
Jul 14 2017 15:16
@javierprovecho I have gin. I can run all other examples without any problems.
@javierprovecho I did all the examples before this one.
Javier Provecho Fernandez
@javierprovecho
Jul 14 2017 15:17
@sgon00 I know, just run the cmd above. The -u flag will update your gin to the latest máster commit
sgon00
@sgon00
Jul 14 2017 15:19
@javierprovecho I just get gin a few days ago. maybe four days ago. why do I have to update gin to latest commit? Is this a new feature in the past four days?
I read that. I am a golang newbie. sorry that I don't get why I got that error from that godoc link.
@javierprovecho btw, I am using govendor which is suggested by gin's github's README.md. So I am running gin by using govendor fetch github.com/gin-gonic/gin@v1.2. if I use v1.2, should I do go get -u github.com/gin-gonic/gin? thanks a lot.
If gin v1.2 does not support c.SecureJSON, is this a doc bug?
because I followed what the doc told me.
sgon00
@sgon00
Jul 14 2017 15:25
sorry about too many questions and confusion. I am a golang newbie. I just learnt golang 4 days ago.
Javier Provecho Fernandez
@javierprovecho
Jul 14 2017 15:25
@sgon00 no problem­čśĆ let me explain
@sgon00 godoc follows master branch, thats why you are seeing a func not available at 1.2

Govendor is recommended for sticking into a version or commit,

Using just go get, makes your project unstable with the latest changes even if they are marked as a New version. Think of go get as a git clone for latest commit

sgon00
@sgon00
Jul 14 2017 15:30
@javierprovecho ok. got it. thanks for your explanation. I don't realized I use v1.2 instead of master commit until I checked the govendor command I ran before. Maybe the doc (readme.md) should mention this somewhere. because I feel strongly that the doc recommends me to use govender and v1.2. Maybe my feeling is not correct because I am not a native English speaker and my English is very bad.
@javierprovecho btw, maybe this is a doc bug too. In https://github.com/gin-gonic/gin#single-file, I have to change c.String(http.StatusOK, fmt.Printf("'%s' uploaded!", file.Filename)) to c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error())) to get rid of compile error.
sgon00
@sgon00
Jul 14 2017 15:42
btw, the reason why I was very confused why c.SecureJSON is undefined is because I am using visual-studio-code and I have both go get gin master commit version globally and govendor locally. The testing project is using govendor version. The most confusing part is that when I type c. in visual-studio-code, it (the popup window) does show me I have c.SecureJSON method. I spent about an hour to figure out why the method does exist (shown in visual-studio-code and godoc) and gave me undefined error message. visual-studio-code is very bad and misleading me.
Javier Provecho Fernandez
@javierprovecho
Jul 14 2017 15:44
@sgon00 easy, since 1.5 go build looks first for a dep at /vendor/*, and later at $GOPATH/*
escode suggestion plugin may look only at $GOPATH
and even if you did go get -u ..., you already had v1.2 copy at your vendor folder
so that's why all that bad behavior
sgon00
@sgon00
Jul 14 2017 15:47
Maybe I should get rid of gin from $GOPATH
@javierprovecho thank you very much for your help. Finally, I know why. :)
Javier Provecho Fernandez
@javierprovecho
Jul 14 2017 15:52
or just clean vendor
ex: $ find vendor ! -path vendor -maxdepth 1 -type d | xargs rm -rf
when you want to go back to your specified revs at vendor/vendor.json, just run govendor sync
sgon00
@sgon00
Jul 14 2017 15:56
@javierprovecho for production environment, should I use master commit (go get way) or v1.2 (govendor way) ? which is recommeneded?
Javier Provecho Fernandez
@javierprovecho
Jul 14 2017 15:57
@sgon00 govendor way, because in the future, master branch may point to incompatible apis, and that will break your ci on next build
in dev env, also go vendor if you want to keep a workflow and replicate exactly what you are going to deploy
for weekend projects I just use master branch through go get,
sgon00
@sgon00
Jul 14 2017 15:59
@javierprovecho OK, thanks. One more quick question. Since I just learnt golang 4 days ago, may I ask which dependency manager is better, godep or govendor? I see gin github mentions switching to govendor. Is that switcing from godep to govendor? godep people says godep will become a standard in go 1.10 in stackoverflow and go-nuts IRC channel. thanks.
Javier Provecho Fernandez
@javierprovecho
Jul 14 2017 16:00
no, we switched from godeps, not godep
sgon00
@sgon00
Jul 14 2017 16:01
oh, that's confusing.... godeps and godep...
Javier Provecho Fernandez
@javierprovecho
Jul 14 2017 16:01
godep was not ready when we wanted to change, and between glide and go vendor, we chose the last one
however, go vendor json file is 100% compatible with godep
like yarn and npm on the js world
sgon00
@sgon00
Jul 14 2017 16:04
ok. cheers. I will stick with govendor then because gin chooses it.
lexasa
@lexasa
Jul 14 2017 17:20
@javierprovecho thanks! I did middleware that wraps c.Next() with opentracing span. Timer with select span was correctly terminated after 100ms with AbortWithStatus() from handler but middleware one showed 400ms anyway.
Javier Provecho Fernandez
@javierprovecho
Jul 14 2017 17:26
@lexasa well, that's golang mechanics, you can't kill a goroutine except from inside