[go-nuts] Re: Can anyone show an example of using Context in net.http middleware?

2016-09-02 Thread Hirotaka Yamamoto (ymmt2005)
This is a real world example from our middleware. https://github.com/cybozu-go/cmd/blob/master/http.go#L122-L132 It uses the context in the request to propagate a unique ID. Please see also my announcement of the package here :-) https://groups.google.com/forum/#!topic/golang-nuts/I0wVToodcdo 201

[go-nuts] Re: Can anyone show an example of using Context in net.http middleware?

2016-09-02 Thread fabrizio . blanco
Here is an example: https://play.golang.org/p/3mFS_7-mM8 You have two wrapper handlers (logIt and authIt). authIt, authenticates every handler you want to authenticate. For simplicity it takes a user id from a url and checks roles. logIt is another wrapper handler, that logs every handler and it

[go-nuts] Re: Can anyone show an example of using Context in net.http middleware?

2016-09-02 Thread fabrizio . blanco
H On Friday, September 2, 2016 at 12:39:16 PM UTC-7, kevin.nor...@gmail.com wrote: > > If I understand correctly using Context will allow "middleware" to pass > data into the handler? Can someone provide a simple example please. > > > > -- You received this message because you are subscribed

Re: [go-nuts] tool to print dependency graph of /vendor libs

2016-09-02 Thread Davis Ford
Daniel, fwiw I couldn't get govendor list to work in my environment. Sam, thanks a lot of that snippet. I also had some trouble running that, but I was able to reverse engineer the important parts out to generate a one-liner that worked for me. go list -f '{{ range .Imports }}{{printf "\t%q -> %

Re: [go-nuts] Re: Surprising benchmark allocations

2016-09-02 Thread peterGo
Francis, And, of course, keyVals := make([]string, b.N*10) // ... for _, key := range keyVals { setTwo(s, key) } should be keyVals := make([]string, b.N) // ... for _, key := range keyVals { setTwo(s, key) } or s /b.N*10/b.N/g Peter On Fri, Sep 2, 2016 at 4:38 PM, peterGo w

[go-nuts] Re: Why can't convert []T to []T2 if T2 is a copy definition of T?

2016-09-02 Thread nicolas riesch
In your original example, if you don't cast, it works. https://play.golang.org/p/g-GScYkA5S The explanation is here: https://groups.google.com/forum/#!topic/golang-nuts/x3nOMDCLv5M Le vendredi 26 août 2016 17:45:40 UTC+2, T L a écrit : > > > > package main > > type Age int > > func main() { >

[go-nuts] Re: Surprising benchmark allocations

2016-09-02 Thread peterGo
Francis, First, fix any bugs. For example, "The benchmark function must run the target code b.N times." https://golang.org/pkg/testing/ Therefore, keyVals := make([]string, b.N*10) // ... for _, key := range keyVals { setOne(s, key) } should be keyVals := make([]string, b.N) // ...

[go-nuts] Can anyone show an example of using Context in net.http middleware?

2016-09-02 Thread kevin . norman . gough
If I understand correctly using Context will allow "middleware" to pass data into the handler? Can someone provide a simple example please. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emai

Re: [go-nuts] tool to print dependency graph of /vendor libs

2016-09-02 Thread Sam Whited
On Fri, Sep 2, 2016 at 1:20 PM, Davis Ford wrote: > Does anyone know of a tool that can analyze dependencies and print a graph, > specifically as it relates to golang vendor'd libraries. I'm using 1.7 and > most tools don't seem to be able to produce results on a project that is > using vendor'd

[go-nuts] Re: tool to print dependency graph of /vendor libs

2016-09-02 Thread Daniel Theophanes
You may be interested in github.com/kardianos/govendor govendor list -v On Friday, September 2, 2016 at 11:20:54 AM UTC-7, Davis Ford wrote: > > Hi, > > Does anyone know of a tool that can analyze dependencies and print a > graph, specifically as it relates to golang vendor'd libraries. I'm usin

[go-nuts] Re: Close a reader to quit a loop without closing its source

2016-09-02 Thread mhhcbon
thanks a lot !! It is very much appreciated. The for loop is *very* clever. Le vendredi 2 septembre 2016 16:30:21 UTC+2, Alan Donovan a écrit : > > On 2 September 2016 at 06:21, mhhcbon > > wrote: > >> I dig into the repo you mentioned, TBHonnest, im not that wise, and it >> remains unclear. >>

[go-nuts] Re: gorutine, channels

2016-09-02 Thread djadala
working examle: https://play.golang.org/p/KLZdle7R47 On Friday, September 2, 2016 at 8:07:32 PM UTC+3, Ринат Галиев wrote: > > Я не могу заставить работать попеременно 2 gorutines: > не использовать новый imports > использовать каналы > получить результаты: 1 2 3 4 5 6 > согte after "// Красноломк

[go-nuts] tool to print dependency graph of /vendor libs

2016-09-02 Thread Davis Ford
Hi, Does anyone know of a tool that can analyze dependencies and print a graph, specifically as it relates to golang vendor'd libraries. I'm using 1.7 and most tools don't seem to be able to produce results on a project that is using vendor'd dependencies. Tools I've tried: - https://git

[go-nuts] Re: gorutine, channels

2016-09-02 Thread djadala
On Friday, September 2, 2016 at 8:07:32 PM UTC+3, Ринат Галиев wrote: > > Я не могу заставить работать попеременно 2 gorutines: > не использовать новый imports > использовать каналы > получить результаты: 1 2 3 4 5 6 > согte after "// Красноломкий " > > Основной пакет > > // красноломкий > > имп

[go-nuts] Re: gorutine, channels

2016-09-02 Thread skirmish
Hi, I took the liberty of creating what I think you're trying to achieve in the go playground so I could test: https://play.golang.org/p/IgtSUNLakJ Are you expecting the output of the two goroutines to be run in parallel so you get the output 1 2 3 4 5 6? Cheers On Friday, September 2, 2016 a

[go-nuts] gorutine, channels

2016-09-02 Thread dieselok161
Я не могу заставить работать попеременно 2 gorutines: не использовать новый imports использовать каналы получить результаты: 1 2 3 4 5 6 согte after "// Красноломкий " Основной пакет // красноломкий импорт "Время" FUNC главный () { идти FUNC () { для _, значение: = диапазон [] INT {1, 3,

[go-nuts] Re: Go performance in regexdna

2016-09-02 Thread Tieson Molly
I looked at the C version, and it looks like it actually uses the TCL regex library that has some slightly different characteristics than the PCRE library. On Thursday, September 1, 2016 at 4:34:41 PM UTC-4, DrGo wrote: > > What is the reason for Go particularly poor performance in regexdna as

[go-nuts] Re: Type And Interface Equivalence

2016-09-02 Thread adonovan via golang-nuts
On Friday, 2 September 2016 09:51:52 UTC-4, Kevin Conway wrote: > > Given a type T that implements interfaces A1 and A2, T is an acceptable > input for any function that requires an A1 or A2 as input. Given A1 and A2 > are identical in definition, the return value of a function that returns an >

[go-nuts] Re: HOW To Write Windows API in GOLANG

2016-09-02 Thread mura
I don't know the answer but if I were you, I would start from looking at Windows applications written in Go and see how they have done. For instance, the package https://github.com/lxn/walk has implemented lots of Windows GUI stuff. It would probably provide the information you are looking for.

[go-nuts] Re: Close a reader to quit a loop without closing its source

2016-09-02 Thread 'Alan Donovan' via golang-nuts
On 2 September 2016 at 06:21, mhhcbon wrote: > I dig into the repo you mentioned, TBHonnest, im not that wise, and it > remains unclear. > For the few i know, select is the approach to take, but the API is unclear. > > Not sure if it s possible to come up with something as straight as > `NewReade

[go-nuts] Type And Interface Equivalence

2016-09-02 Thread Kevin Conway
Not sure exactly how to describe this issue or the right words to use when talking about some of the concepts. Here's a best effort. Given a type T that implements interfaces A1 and A2, T is an acceptable input for any function that requires an A1 or A2 as input. Given A1 and A2 are identical in d

Re: [go-nuts] why this code deadlocks?

2016-09-02 Thread turakulov
You could close(done). It doesn't block, thus you won't have to allocate a buffer. chan struct{} would take even less space and WaitGroup seems unnecessary in this code -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this g

[go-nuts] Introducing Planet Golang

2016-09-02 Thread Nicolas Martyanoff
Hi, There are a lot of Go resources out there, but I've been missing a blog aggregator for some time. So I built one :) It's now running on http://planetgolang.com. Planet Golang is statically generated by a Go program, https://github.com/galdor/planetgolang. I added a few feeds to start, but I'

[go-nuts] go-gcnl: Golang library for accessing the Google Cloud Natural Language API

2016-09-02 Thread Josh Lubawy
Hi All, I made a new library that I thought some people might find useful: https://github.com/jlubawy/go-gcnl Feedback and feature requests are gladly welcomed! Thanks, Josh -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from

[go-nuts] Speeding up Go Report Card

2016-09-02 Thread Shawn Smith
Hi, I'm one of the maintainers of Go Report Card http://goreportcard.com/ and I am looking for advice on how to make it faster. Basically we run a series of checks (gofmt, vet, etc.) on your Go repository and provide a grade based on how many errors each check returns. Each check runs in a sep

[go-nuts] Surprising benchmark allocations

2016-09-02 Thread Francis
I have been working to reduce allocations in a local cache and found some confusing behaviour around the allocs/op output when benchmarking. A simplified reproducing version is pasted at bottom. The behaviour is that setting a value in a single map yields 0 allocations, setting a value in two m

[go-nuts] HOW To Write Windows API in GOLANG

2016-09-02 Thread kumargv
Hello friends, i am trying to write some win api in golang ,because these API not implemented any PKG. "syscall" "github.com/contester/runlib/win32" "golang.org/x/sys/windows" API are code in C++ OpenDesktop hdesk = OpenDesktop( _T("default"), // the interacti

[go-nuts] Re: on GOPATH

2016-09-02 Thread Diddymus
I prefer a GOPATH per project but never worry about setting it. I have a small bash/dash script called gp which finds the GOPATH for me as long as I'm in the project somewhere: #!/bin/dash paths=${PWD} while [ "$paths" != "/" ]; do if [ -d "$paths/bin" ]; then if [ -d "$p

Re: [go-nuts] flag: Stack overflow when return stringer with fmt.Sprint

2016-09-02 Thread Mhd Sulhan
Pada Thu, 1 Sep 2016 21:10:44 +0200 Harald Weidner menulis: > Hello, > > On Thu, Sep 01, 2016 at 01:59:12AM -0700, Muhammad Shulhan wrote: > > > > type Slices []string > > > > > > func (sl *Slices) String() string { > > > return fmt.Sprint(sl) > > > } > > > runtime: goroutine stack excee

[go-nuts] Re: Close a reader to quit a loop without closing its source

2016-09-02 Thread mhhcbon
I dig into the repo you mentioned, TBHonnest, im not that wise, and it remains unclear. For the few i know, select is the approach to take, but the API is unclear. Not sure if it s possible to come up with something as straight as `NewReader(os.Stdin).Block(false).Read()` Le mercredi 31 août

Re: [go-nuts] Re: Glide for forks

2016-09-02 Thread mhhcbon
`glide update` or a install should do the job, yes. If that does not `mv vendor _vendor && glide install` to figure out if things works or are stinky. Do you mean you re in situation where you have one to many repo to update by doing a fork / PR / merge to actually make a significant change

[go-nuts] Re: on GOPATH

2016-09-02 Thread Simon Ritchie
Responses to a question like this tend to be either very detailed, or vague. This one has all the gory details. I develop under Linux. I'm happy to use fancy visual tools, but I also do a lot of stuff from the command line. I have a directory GOCODE where I put stuff that I fetch via go get.

[go-nuts] Re: cgo, CString and C.free

2016-09-02 Thread Elias Naur
Hi, Test() never actually dereference the C string (now dangling) pointer after C.free. And even if it did, it is unlikely that the C.free() resulted in the memory page your string resided on was unmapped. Segfaults only happen if you access unmapped memory. - elias On Friday, September 2, 2

[go-nuts] Re: cgo, CString and C.free

2016-09-02 Thread Kane Kim
Nevermind, looks like it is undefined behavior here. On Friday, September 2, 2016 at 1:43:49 AM UTC-7, kane@sendgrid.com wrote: > > Hello, > > I was expecting it to segfault after deallocating CString. How does it > work internally? > > func (m *Message) Test() string { > s := C.CString("tes

[go-nuts] cgo, CString and C.free

2016-09-02 Thread kane.isturm via golang-nuts
Hello, I was expecting it to segfault after deallocating CString. How does it work internally? func (m *Message) Test() string { s := C.CString("test") C.free(unsafe.Pointer(s)) sh := reflect.StringHeader{(uintptr)(unsafe.Pointer(s)), 4} return *(*string)(unsafe.Pointer(&sh)) } -- You received

[go-nuts] GoBkm 0.7 released

2016-09-02 Thread Thomas Bellembois
Hello Golang community, I have released a new version of the GoBkm bookmark manager: https://github.com/tbellembois/gobkm/releases/tag/0.7 This version fixes an issue with complex bookmark URLs. Regards, Thomas -- You received this message because you are subscribed to the Google Groups "gol