Re: [go-nuts] Re: genmap: Generate thread-safe, type-safe maps easily

2017-07-09 Thread Henrik Johansson
I agree a typed concurrent map would be very neat but each type that make has to support requires AFAIK specialisation in the compiler(?) which seems to be burdensome. Perhaps backwards compatibility prohibits the use of the name 'cmap', not sure. mån 10 juli 2017 kl 05:23 skrev : > I do not u

Re: [go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-09 Thread charlievx
Yes! That works :-) Thanks so much. So apparently we cannot call *net.http.Server.Shutdown()* from a handler function. Maybe this should be added to the docs. On Monday, July 10, 2017 at 3:05:10 PM UTC+10, mikioh...@gmail.com wrote: > > calling Shutdown method of http.Server in a registered HTTP

Re: [go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-09 Thread mikioh . mikioh
calling Shutdown method of http.Server in a registered HTTP handler probably may prevent the package internal helpers from marking the inflight connection idle. so you can write like the following: http.HandleFunc("/stop", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "s

[go-nuts] Re: Random Number Generation in a given range

2017-07-09 Thread peterGo
Alok, Your import path "github.com/alok87/goutils/random" is not valid for "go get". The source is at "github.com/alok87/goutils/pkg/random". You write "for { rand.Seed(); rand.Intn(); }". Therefore, the range of values is not random. You write "arr[r] = rand.Intn(max) + min" which is incorrec

Re: [go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-09 Thread charlievx
Interesting - now I get the same messages: 2017/07/10 13:23:17 Server starting up... 2017/07/10 13:23:22 Server shutting down... test - before shutdown But the program doesn't stop! I need to Ctrl+C to stop it... I don't get it - why doesn't server.Shutdown() just work? On Monday, July 10, 201

[go-nuts] Re: genmap: Generate thread-safe, type-safe maps easily

2017-07-09 Thread alex . mirrr
I do not understand what prevents the authors of the language from determining the thread-safe type *cmap*(name is taken for example) with builtin mutex: *X: = cmap[int]string{}* *Y: = make(cmap[string]interface{})* *x, exists := X[10]**y, ok := Y["some"]* In this case, the programmer might

Re: [go-nuts] Customized Go template FuncMap example

2017-07-09 Thread Tong Sun
Thanks Matt. What I'm trying to do is to modulelize customized Go template functions, say one module provide advanced regexp support, while another one specialized in text formatting (vertical aligning, text folding in column, etc), so on and so forth, *each of the module has a collection of their

Re: [go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-09 Thread Matt Harden
Try a channel to wait for shutdown in main. func main() { srv := &http.Server{Addr: ":8080", Handler: http.DefaultServeMux} *done := make(chan struct{})* http.Handle("/web/", http.FileServer(http.Dir("./"))) http.HandleFunc("/stop", func(w http.ResponseWriter, r *http.Request) {

Re: [go-nuts] Checking for expired certificates

2017-07-09 Thread Matt Harden
To detect revoked certificates, you have to either have a current CRL for the CA that issued the cert, or use OSCP. This doesn't appear to be easy to do in Go yet, but https://godoc.org/golang.org/x/crypto/ocsp may help. On Sat, Jul 8, 2017 at 1:06 AM gwhelbig via golang-nuts < golang-nuts@googleg

Re: [go-nuts] confused with packages

2017-07-09 Thread Glenn Hancock
Nevermind, I figured it out. I was trying to do a go build test.go and should have been providing the path up to the folder and not including the name of the go file itself. ie: go build projectfolder/test . instead of go build test.go while inside the test folder. Thanks, Glenn On Sunda

Re: [go-nuts] Customized Go template FuncMap example

2017-07-09 Thread Matt Harden
Why are you trying to do that? It feels like you're trying to do object-oriented programming in Go. Don't do that. What are you trying to achieve that the *template.Template type doesn't allow? If you just want a template with a FuncMap already applied, write a function to do that: func MyTemplat

Re: [go-nuts] confused with packages

2017-07-09 Thread Glenn Hancock
Sorry, I'm not quite following your question as I thought I answered it in my original post. When I attempt a run or a build I get ./test.go:12: undefined: myfirstfunction As I stated, I have 2 separate files, one called test.go and another called functions.go, both in same folder and both wit

Re: [go-nuts] confused with packages

2017-07-09 Thread Ian Lance Taylor
On Sun, Jul 9, 2017 at 6:28 PM, Glenn Hancock wrote: > > I have setup a test program with the following files > > test folder with test.go and functions.go > > both files contain . package main > > function file has func in it called myfirstfunction() that just prints a > line > > from main I atte

[go-nuts] [ANN] gojekyll clone of the Jekyll static site generator

2017-07-09 Thread Oliver Steele
Hi everyone, As my "learn Go" project, I've been working on a clone of the Jekyll static site generator. (The original is in Ruby.) It's far from a 1.0 release – and it's not my main project, so I don't know when it will see one. It does work on several of my GitHub Pages sites, and mostly wor

[go-nuts] confused with packages

2017-07-09 Thread Glenn Hancock
I have setup a test program with the following files test folder with test.go and functions.go both files contain . package main function file has func in it called myfirstfunction() that just prints a line from main I attempt to call myfirstfunction() but get compiler error saying it doesn't

[go-nuts] Re: bufio.Scanner and partial reads

2017-07-09 Thread Juliusz Chroboczek
>> Do I have a guarantee that the final \n will be passed to my custom >> scan function and the result passed to the Scan function even if the >> connection hangs just after the \n? > Yes (assuming the underlying Reader returns the final \n). >> Do similar properties hold for bufio.Reader (i.e.,

Re: [go-nuts] Are functional options idiomatic

2017-07-09 Thread Sam Whited
On Sun, Jul 9, 2017 at 2:05 PM, 'Anmol Sethi' via golang-nuts wrote: > I haven’t seen this API design used anywhere at all in any library I have > ever used (or in the standard library at all) so I was wondering whether or > not it’s idiomatic. It's used heavily in the golang.org/x/text subrepos,

Re: [go-nuts] My project is now missing from godoc

2017-07-09 Thread Tong Sun
On Sun, Jul 9, 2017 at 11:06 AM, Jan Mercl <0xj...@gmail.com> wrote: > > On Sun, Jul 9, 2017, 16:45 Tong Sun wrote: > >> >> >> On Sun, Jul 9, 2017 at 10:41 AM, Jan Mercl wrote: >> >> >>> >>> On Sun, Jul 9, 2017, 16:35 Tong Sun wrote: >>> Hi, My project is *now* missing from godoc,

[go-nuts] Are functional options idiomatic

2017-07-09 Thread 'Anmol Sethi' via golang-nuts
Hello everyone! I’m writing a new library where I need to be able to configure a struct. This struct and its configuration will be accessed concurrently. One design pattern I see throughout the standard library and community is to make the struct and its configuration fields public but all othe

Re: [go-nuts] bufio.Scanner and partial reads

2017-07-09 Thread Ian Lance Taylor
On Sun, Jul 9, 2017 at 5:47 AM, Juliusz Chroboczek wrote: > > I cannot find anything in the documentation about how bufio.Scanner > behaves when the underlying io.Reader does partial reads. It will behave correctly, doing additional reads as needed to complete a token. The Go documentation gener

[go-nuts] Re: Random Number Generation in a given range

2017-07-09 Thread alok . singh
A python like range utility which can be used for this https://github.com/alok87/goutils/blob/master/pkg/random/random.go ```random.RangeInt(2, 100, 3)``` On Wednesday, March 28, 2012 at 5:43:55 AM UTC+5:30, Guillermo Estrada wrote: > > Hi, I've been reading some posts but I still have the same q

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-09 Thread Marvin Renich
* T L [170709 04:56]: > On Friday, July 7, 2017 at 8:42:28 PM UTC+8, Marvin Renich wrote: > > Yes, the go routine establishes a happens-before relationship such that > > x is incremented before y, and the atomic Add of y and Load of y ensure > > that the Load either happens before or after, but

Re: [go-nuts] Re: unsafe.Pointer to byte slice

2017-07-09 Thread Santhosh Ram Manohar
On Sun, Jul 9, 2017 at 12:30 AM, Dave Cheney wrote: > As your using the unsafe package your doing things which are not > considered safe by the lanaguge so only imprecise interpretations are > possible. My interpretation is, assuming that next words after p in memory > are zeroed the you have eff

Re: [go-nuts] golint warning: should replace errors

2017-07-09 Thread Björn Graf
Ahoy, this warning is about errors.New(fmt.Sprintf()) being the same as fmt.Errorf() and so the latter should be used to reduce complexity. -- bg On Sun, Jul 9, 2017 at 3:32 PM, Tong Sun wrote: > Hi, > > what does the golint warning: *should replace errors* actually means? > > I've just finish

Re: [go-nuts] How does gccgo compile with my own package imported?

2017-07-09 Thread ajee . cai
Hi Ian, OK I got it now. I have to separately compile the imported packages as .o if I use gccgo and then link them to the final executable. Resolving the dependency of the packages may be troublesome so go tool is good if we have choice. Thanks. -- You received this message because you ar

Re: [go-nuts] My project is now missing from godoc

2017-07-09 Thread Jan Mercl
On Sun, Jul 9, 2017, 16:45 Tong Sun wrote: > > > On Sun, Jul 9, 2017 at 10:41 AM, Jan Mercl wrote: > > >> >> On Sun, Jul 9, 2017, 16:35 Tong Sun wrote: >> >>> Hi, >>> >>> My project is *now* missing from godoc, the >>> http://godoc.org/github.com/go-easygen/easygen >>> is *now* returning "Not Fou

Re: [go-nuts] My project is now missing from godoc

2017-07-09 Thread Tong Sun
On Sun, Jul 9, 2017 at 10:41 AM, Jan Mercl wrote: > > > On Sun, Jul 9, 2017, 16:35 Tong Sun wrote: > >> Hi, >> >> My project is *now* missing from godoc, the >> http://godoc.org/github.com/go-easygen/easygen >> is *now* returning "Not Found". >> >> It has always been working before, for >> https:/

Re: [go-nuts] My project is now missing from godoc

2017-07-09 Thread Jan Mercl
On Sun, Jul 9, 2017, 16:35 Tong Sun wrote: > Hi, > > My project is *now* missing from godoc, the > http://godoc.org/github.com/go-easygen/easygen > is *now* returning "Not Found". > > It has always been working before, for > https://github.com/go-easygen/easygen > > What's wrong? Thx. > Try to r

[go-nuts] My project is now missing from godoc

2017-07-09 Thread Tong Sun
Hi, My project is *now* missing from godoc, the http://godoc.org/github.com/go-easygen/easygen is *now* returning "Not Found". It has always been working before, for https://github.com/go-easygen/easygen What's wrong? Thx. -- You received this message because you are subscribed to the Goo

[go-nuts] golint warning: should replace errors

2017-07-09 Thread Tong Sun
Hi, what does the golint warning: *should replace errors* actually means? I've just finished my easygen V2 reconstruction: https://github.com/go-easygen/easygen but now golint gives a warning: *should replace errors* for Line 157

[go-nuts] bufio.Scanner and partial reads

2017-07-09 Thread Juliusz Chroboczek
Hi, I cannot find anything in the documentation about how bufio.Scanner behaves when the underlying io.Reader does partial reads. I'm using a Scanner to parse a stream of tokens that arrives over a TCP socket. The stream is a sequence of lines terminated by \n. Do I have a guarantee that the fi

[go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-09 Thread charlievx
Just tried it but it doesn't work. The problem I started from is that server.Shutdown didn't wait for my requests to complete. (To check this I put in the time.Sleep(6000 * time.Millisecond)). When I narrowed down the problem it showed me that code after the Shutdown call wasn't being executed.

[go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-09 Thread Elias Naur
Your main goroutine probably exits before the handler gets to write "after shutdown" to the console. Try adding a time.Sleep(1*time.Second) as the very last line in main(). - elias On Sunday, July 9, 2017 at 1:53:36 PM UTC+2, char...@gmail.com wrote: > > Hi, > > Go code after calling srv.Shutd

[go-nuts] http.Server.Shutdown() crashing?

2017-07-09 Thread charlievx
Hi, Go code after calling srv.Shutdown() simply isn't called. There is no error message, no dump, nothing. This is the output after visiting http://localhost:8080/stop on my browser 2017/07/09 13:58:40 Server starting up... 2017/07/09 13:58:44 Server shutting down... test - before shutdown Not

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-09 Thread Jan Mercl
On Sun, Jul 9, 2017 at 10:56 AM T L wrote: > But I remember that the "happens-before relationship" is never written down in any official Go documentation. https://golang.org/ref/mem#tmp_2 -- -j -- You received this message because you are subscribed to the Google Groups "golang-nuts" grou

[go-nuts] Re: constants vs variables

2017-07-09 Thread T L
On Sunday, July 9, 2017 at 10:26:16 AM UTC+8, Alexey Dvoretskiy wrote: > > Hello golang-nuts, > > Here are two code snippets with operations on different types. One with > constants and another one with variables. The first one works, the second > one doesn't. Why is it like this? Logically bot

[go-nuts] Re: unsafe.Pointer to byte slice

2017-07-09 Thread T L
On Sunday, July 9, 2017 at 6:31:24 AM UTC+8, Santhosh Ram Manohar wrote: > > hello, > > This piece of code prints [10 0 0 0] as expected.. > > func main() { > i := 10 > p := unsafe.Pointer(&i) > intPtr := (*[4]byte)(p) > fmt.Println(*intPtr) > } > > But if I conver

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-09 Thread T L
On Friday, July 7, 2017 at 8:42:28 PM UTC+8, Marvin Renich wrote: > > * T L > [170707 01:32]: > > Then how about this? > > > > package main > > > > import "fmt" > > import "sync/atomic" > > > > func main() { > > var x, y int32 > > go func() { > > atomic.AddInt32(&x, 1)

Re: [go-nuts] Re: unsafe.Pointer to byte slice

2017-07-09 Thread Dave Cheney
As your using the unsafe package your doing things which are not considered safe by the lanaguge so only imprecise interpretations are possible. My interpretation is, assuming that next words after p in memory are zeroed the you have effectively a slice that points to a backing array at *p, and