Re: [go-nuts] gob Decode cannot override "true" value with "false"

2019-05-20 Thread Dan Kortschak
This is because zero values are not sent by encoding/gob. So the false value never goes over the wire to overwrite the true. If you want things to be zeroable, you need to do that yourself before decoding. From https://golang.org/pkg/encoding/gob/#hdr-Encoding_Details "If a field has the zero

[go-nuts] gob Decode cannot override "true" value with "false"

2019-05-20 Thread nvcnvn
It seem if a field with boolean value setted to "true", some how gob Decode cannot change it to false. Example: https://play.golang.org/p/5eCp_0d1UC4 (original question are here

[go-nuts] Adding a timeout to a script interpreter (without leaking a goroutine)

2019-05-20 Thread Ben Hoyt
I'm looking at adding a timeout option to my GoAWK script interpreter using either a timeout or a context value. This is mainly for safety when using it in an embedded context, for example to avoid someone doing a denial-of-service attack by submitting a `BEGIN { while (1); }` script. This seems

Re: [go-nuts] The strange behavior of defer

2019-05-20 Thread 'Kebo Duan' via golang-nuts
I see, thank you very much! On Monday, May 20, 2019 at 5:18:10 PM UTC-7, kortschak wrote: > > The parameter to fmt.Println is evaluated at the time of the defer > statement's execution. You should do something like this instead > > func main() { > start := time.Now() > defer

Re: [go-nuts] The strange behavior of defer

2019-05-20 Thread Kurtis Rader
On Mon, May 20, 2019 at 4:54 PM duankebo via golang-nuts < golang-nuts@googlegroups.com> wrote: > For the following piece of code. > > func main() { > start := time.Now() > defer fmt.Println(time.Since(start)) > time.Sleep(10) > fmt.Println("Hello, playground") >

Re: [go-nuts] The strange behavior of defer

2019-05-20 Thread Dan Kortschak
The parameter to fmt.Println is evaluated at the time of the defer statement's execution. You should do something like this instead func main() { start := time.Now() defer func() { fmt.Println(time.Since(start)) }() time.Sleep(10) fmt.Println("Hello,

[go-nuts] The strange behavior of defer

2019-05-20 Thread duankebo via golang-nuts
For the following piece of code. func main() { start := time.Now() defer fmt.Println(time.Since(start)) time.Sleep(10) fmt.Println("Hello, playground") fmt.Println(time.Since(start)) } The output is: Hello, playground 1s 0s I'm new at golang. Should the two time.Since both be called

Re: [go-nuts] Http Handler to produce static content

2019-05-20 Thread Amnon Baron Cohen
When web-apps are implemented in scripting languages which suffer from poor performance, it is common practice to proxy them behind a "real" web server such as nginx, and offload SSL termination, caching, handling of static components, etc to it. In Go http.ListenAndServe is an industrial

Re: [go-nuts] constatnt conversion question

2019-05-20 Thread Michael Jones
ahem... https://play.golang.org/p/7gcb9Yv7c9e On Mon, May 20, 2019 at 2:45 AM wrote: > https://golang.org/ref/spec#Constants > > "A constant may be given a type explicitly by a constant declaration > or conversion, or implicitly when used in a variable declaration or an > assignment or as an

Re: [go-nuts] Http Handler to produce static content

2019-05-20 Thread Tyler Compton
> Sorry I don't quite understand -- my go application IS my webserver. > This is a topic that has confused me in the past. In the simple case where you build a Go executable and get requests from it directly, your Go application *is* your web server. However, it's common in industry to put a

Re: [go-nuts] constatnt conversion question

2019-05-20 Thread fgergo
https://golang.org/ref/spec#Constants "A constant may be given a type explicitly by a constant declaration or conversion, or implicitly when used in a variable declaration or an assignment or as an operand in an expression. It is an error if the constant value cannot be represented as a value of

Re: [go-nuts] constatnt conversion question

2019-05-20 Thread Jan Mercl
On Mon, May 20, 2019 at 11:33 AM wrote: > > Hi, > does this should work ? The error is correct. See https://golang.org/ref/spec#Conversions A constant value x can be converted to type T if x is representable by a value of T. An integer cannot represent the value 6.6 hence the

[go-nuts] constatnt conversion question

2019-05-20 Thread djadala
Hi, does this should work ? package main import ( "fmt" ) func main() { const ( c = 2 z = 3.3 y = c * z x = int(y) // or x int = y ) fmt.Println(x) } it does not compile with error: constant 6.6 truncated to integer