[go-nuts] How can I make changes in `printer.go` affect `gofmt` tests?

2016-12-13 Thread mlg
I'm tinkering with gofmt. I've been able to work with gofmt tests, but I don't understand the `printer.go` tests. The modifications I want to tinker with are in `printer.go`, but the gofmt tests I write seem to compile a different unmodified version of printer.go than the one I checked out. The

[go-nuts] Is it safe to close a channel once more in this way ?

2016-12-13 Thread Tamás Gulácsi
Use sync.Once - but there's a simple rule that helps: Let the writer/producer close the channel! -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsub

[go-nuts] Re: Is it safe to close a channel once more in this way ?

2016-12-13 Thread Dave Cheney
https://play.golang.org/p/LadBqwgxxr _may_ be a fix, but the similarity to the discredited double check lock pattern is worrying. On Wednesday, 14 December 2016 15:32:57 UTC+11, Dave Cheney wrote: > > Nope, it's not safe. > > https://play.golang.org/p/pcPdKixphL > > Run this program in a loop and

[go-nuts] Re: Is it safe to close a channel once more in this way ?

2016-12-13 Thread Dave Cheney
Nope, it's not safe. https://play.golang.org/p/pcPdKixphL Run this program in a loop and it will panic eventually. On Wednesday, 14 December 2016 15:19:24 UTC+11, P Q wrote: > > func close_safe(c chan bool) { > select { > case <-c: > default: > close(c) > } > } > > Closing a channel onece more c

[go-nuts] Is it safe to close a channel once more in this way ?

2016-12-13 Thread P Q
func close_safe(c chan bool) { select { case <-c: default: close(c) } } Closing a channel onece more can be a controversial topic, sometimes it is useuful. I saw the code to close a closed channel. I thought the code looked nice at first, but could become errernous. Let's assume that two goruti

[go-nuts] Re: Channels and Mutexs

2016-12-13 Thread Dave Cheney
On Wednesday, 14 December 2016 13:06:54 UTC+11, sdi...@watchtower-security.com wrote: > > Why would one want to use channels in place of mutexs? > When you want to use select. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe

Re: [go-nuts] Channels and Mutexs

2016-12-13 Thread Ian Lance Taylor
On Tue, Dec 13, 2016 at 6:06 PM, wrote: > > So, I was talking with a friend about channels and mutexs, and the use of > mutexs instead of channels. While I'm not sure why you'd want to, I was > given this example and not an answer. > > In the example, he declares two channels. Input and Output. T

[go-nuts] Channels and Mutexs

2016-12-13 Thread sdickey
So, I was talking with a friend about channels and mutexs, and the use of mutexs instead of channels. While I'm not sure why you'd want to, I was given this example and not an answer. In the example, he declares two channels. Input and Output. Then, he has

[go-nuts] Re: Code-base Refactoring Tool for Go , Move files from packages to sub packages

2016-12-13 Thread Dave Cheney
I advice caution, Go is not Java and does not permit circular dependencies. The more packages you have, the greater the chance you have of creating a circular dependency. On Wednesday, 14 December 2016 00:58:00 UTC+11, jis...@hifx.co.in wrote: > > > > http://stackoverflow.com/questions/41121448

[go-nuts] Re: Cache or tmp file used by golang compiler?

2016-12-13 Thread Dave Cheney
Try go install -v, you'll find the program in $GOPATH/bin. If you get no lines of output, then the program is up to date. On Wednesday, 14 December 2016 11:14:06 UTC+11, ddxgz1...@gmail.com wrote: > > Hi Uriel, > > How did you solve this problem? Because I'm facing the same. > > 在 2015年8月12日星期三 U

[go-nuts] Re: Cache or tmp file used by golang compiler?

2016-12-13 Thread ddxgz19880813
Hi Uriel, How did you solve this problem? Because I'm facing the same. 在 2015年8月12日星期三 UTC+2上午10:29:39,Uriel Fanelli写道: > > > Hi all > > I am facing a strange behavior in "go build" process. > > What I am doing is , from time to time, to do a git pull from a github > repository and recompile th

[go-nuts] Re: net/http best way to get request/response header size

2016-12-13 Thread Nick V
For what it's worth, MaxHeaderSize only works for POST/PUT requests. On Tuesday, December 13, 2016 at 11:19:06 AM UTC-8, Tamás Gulácsi wrote: > > 2016. december 13., kedd 14:57:47 UTC+1 időpontban kaitoY Kors a > következőt írta: >> >> Hello, >> >> In the current implementation of net/http and ne

Re: [go-nuts] Re: Looking for Golang counterpart to 'params' in Python

2016-12-13 Thread Justin Israel
On Wed, Dec 14, 2016 at 11:39 AM Betsy Lichtenberg wrote: > Interesting. Thanks for the idea, but for security reasons I'm not sure if > it's something we can do. For some background, the reason I started down > this road is we cannot include the auth parameter in the request URL. > I was actual

Re: [go-nuts] Re: Looking for Golang counterpart to 'params' in Python

2016-12-13 Thread Betsy Lichtenberg
For what it's worth, a friend of mine advised me to use maps. https://blog.golang.org/go-maps-in-action But, alas, I'm not enough of a guru to do anything fancy. On Tue, Dec 13, 2016 at 2:16 PM, Justin

Re: [go-nuts] Re: Looking for Golang counterpart to 'params' in Python

2016-12-13 Thread Betsy Lichtenberg
Interesting. Thanks for the idea, but for security reasons I'm not sure if it's something we can do. For some background, the reason I started down this road is we cannot include the auth parameter in the request URL. https://developer-api.nest.com/structures?auth=x http://self-issued.info/d

Re: [go-nuts] Re: Looking for Golang counterpart to 'params' in Python

2016-12-13 Thread Justin Israel
Hi, While others have been talking about headers, I notice that you are using the python requests 3rd party library, and referring to the "params" keyword arg which is meant to pass query string values in your GET request. I would think the equivalent in Go would be to: 1. Build the equivale

[go-nuts] Re: Evaluation order

2016-12-13 Thread Rafał Jęczalik
Dave, the example you have on your blog post is the same as the one in spec I linked and is different than mine - the f is called before a is evaluated, if we assumed left-to-right evaluation order. In the spec's example a is evaluated before f is called. I tested my example on both gccgo and g

[go-nuts] Evaluation order

2016-12-13 Thread Dave Cheney
The order of evaluation is not specified. We found a few years ago that gccgo and gc differed in this respect and _both_ implantations are correct. https://dave.cheney.net/2013/11/15/evaluation-order-oddity -- You received this message because you are subscribed to the Google Groups "golang-n

Re: [go-nuts] Re: How to speed up execution time for a set of regular expressions

2016-12-13 Thread Michael Jones
I like regular expressions, but I always think of them as a last resort, sort of like finding your way through a labyrinth by feel. When you know more about the structure of the mystery -- "keep your left hand on the wall" or "spaces separate tokens"-- then other tools and approaches can help treme

Re: [go-nuts] How to speed up execution time for a set of regular expressions

2016-12-13 Thread Andy Balholm
Right. Aho-Corasick can’t be used directly in that case. But it might still be a major performance win to use Aho-Corasick for the first pass, and then confirm with regexes. In other words, if the Aho-Corasick stage finds “associate,” then check whether /associate.*with/ matches. Andy -- You

[go-nuts] Re: How to speed up execution time for a set of regular expressions

2016-12-13 Thread David Sofo
Thanks Tamas. I am not aware of Ragel. Regard David Le mardi 13 décembre 2016 20:24:18 UTC+1, Tamás Gulácsi a écrit : > > 2016. december 13., kedd 16:53:45 UTC+1 időpontban David Sofo a következőt > írta: >> >> Hi, >> >> For a set of rules expressed in regular expression (around 1000 rules >> e

Re: [go-nuts] Re: Looking for Golang counterpart to 'params' in Python

2016-12-13 Thread 'Chris Manghane' via golang-nuts
I see, well that makes the compiler error make more sense. You're trying to declare a function type within a function. Use a function literal instead, for example: `doIT := func(p Params) string { ... }`. On Tue, Dec 13, 2016 at 11:18 AM, Betsy Lichtenberg wrote: > The expression is inside of th

[go-nuts] Re: How to speed up execution time for a set of regular expressions

2016-12-13 Thread Tamás Gulácsi
2016. december 13., kedd 16:53:45 UTC+1 időpontban David Sofo a következőt írta: > > Hi, > > For a set of rules expressed in regular expression (around 1000 rules > expected) to find some keywords in a text file (~50Ko each file), how to > speed up the execution time. Currently I compile the re

[go-nuts] Re: net/http best way to get request/response header size

2016-12-13 Thread Tamás Gulácsi
2016. december 13., kedd 14:57:47 UTC+1 időpontban kaitoY Kors a következőt írta: > > Hello, > > In the current implementation of net/http and net/textproto, other than > iterating all the key/value pairs of Header, type map[string][]string, is > there any other way to get the total size effecti

Re: [go-nuts] Re: Looking for Golang counterpart to 'params' in Python

2016-12-13 Thread Betsy Lichtenberg
The expression is inside of the main function. package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "https://developer-api.nest.com/structures"; payload := strings.NewReader("code=a&client_id=&client_secret=&grant_type=authorization_code") req, _ :=

Re: [go-nuts] import a "main" package

2016-12-13 Thread Dave Cheney
There were some difficulties in writing external tests for a main package, ie package main_test, but they were resolved a long time ago. On Wednesday, 14 December 2016 04:18:22 UTC+11, Jan Mercl wrote: > > On Tue, Dec 13, 2016 at 6:13 PM adonovan via golang-nuts < > golan...@googlegroups.com > wr

Re: [go-nuts] Re: Looking for Golang counterpart to 'params' in Python

2016-12-13 Thread 'Chris Manghane' via golang-nuts
That error seems to be from writing that expression outside of a function. There's no problem with structs supporting string fields: https://play.golang.org/p/YeP2qhRdxp. On Tue, Dec 13, 2016 at 10:45 AM, Betsy Lichtenberg wrote: > Do structs support strings? I tried this: > > type Params st

Re: [go-nuts] import a "main" package

2016-12-13 Thread Manlio Perillo
Il giorno martedì 13 dicembre 2016 18:13:08 UTC+1, adon...@google.com ha scritto: > > On Tuesday, 13 December 2016 11:34:24 UTC-5, Jan Mercl wrote: >> >> On Tue, Dec 13, 2016 at 5:19 PM Manlio Perillo >> wrote: >> >> > However I think that there is no reason why a "main" package should not >> b

[go-nuts] Re: Looking for Golang counterpart to 'params' in Python

2016-12-13 Thread Betsy Lichtenberg
Do structs support strings? I tried this: type Params struct { auth string } func doIt(p Params) string { return p.auth } doIt(Params{auth: }) I'm getting these errors: betsyl-macbookpro:~ betsyl$ go run get1.go # command-line-arguments ./get1.go:25: synt

Re: [go-nuts] Why does the close built-in panic on previously closed channels?

2016-12-13 Thread go-question
I see, from reading the Golang spec on the close builtin it wasn't clear to me that it was communicating with the receivers. Thanks for clarifying! On Tuesday, December 13, 2016 at 10:19:46 AM UTC-8, Ian Lance Taylor wrote: > > On Tue, Dec 13, 2016 at 10:03 AM, go-question > > wrote: > > >

Re: [go-nuts] Why does the close built-in panic on previously closed channels?

2016-12-13 Thread Ian Lance Taylor
On Tue, Dec 13, 2016 at 10:03 AM, go-question wrote: > > Whats the reason behind panicking when calling close on a closed channel? > > Receiving on a closed channel returns the zero value. > Wouldn't it be safer to do a no-op and rely on the multivar return to inform > the caller when it is succes

[go-nuts] Why does the close built-in panic on previously closed channels?

2016-12-13 Thread go-question
Whats the reason behind panicking when calling close on a closed channel? Receiving on a closed channel returns the zero value. Wouldn't it be safer to do a no-op and rely on the multivar return to inform the caller when it is successful? Though, maybe the latter point could be confusing with r

Re: [go-nuts] Function scoped method receivers

2016-12-13 Thread go-question
Thanks rog for the suggestions. I can see the case for mocking as well. On Tuesday, December 13, 2016 at 5:11:26 AM UTC-8, rog wrote: > > On 13 December 2016 at 01:08, go-question > wrote: > > > > I noticed that its possible to define/scope types/interfaces in > functions. > > > > Now I'm n

[go-nuts] Responsive boxes in go-gtk

2016-12-13 Thread James Ralphs
I'm writing a desktop application using the Go bindings for GTK at https://mattn.github.io/go-gtk/. I'm showing a set of widgets in a listing "view". I'd like to make it responsive - kind of like using the "float" property in CSS. So far I've looked at VBox, HBox, Table, and the Fixed Layout an

[go-nuts] pprof cum units

2016-12-13 Thread vadim
According to some older pprof tutorials, the units reported by "top" or "web" are the numbers of calls. Newer tutorials as well as my own experiments show seconds instead. For example, compare: (pprof) top10 Total: 2525 samples 298 11.8% 11.8% 345 13.7% runtime.mapaccess1_fast64 268 10.6% 22.4

Re: [go-nuts] import a "main" package

2016-12-13 Thread Jan Mercl
On Tue, Dec 13, 2016 at 6:13 PM adonovan via golang-nuts < golang-nuts@googlegroups.com> wrote: > Packages named main are importable, just like any other. Occasionally this is useful when you want to write tests for members of that package. Of course, the main function is not exported. I recall r

Re: [go-nuts] import a "main" package

2016-12-13 Thread adonovan via golang-nuts
On Tuesday, 13 December 2016 11:34:24 UTC-5, Jan Mercl wrote: > > On Tue, Dec 13, 2016 at 5:19 PM Manlio Perillo > wrote: > > > However I think that there is no reason why a "main" package should not > be importable, to the point that > > I think that the fact that a "main" package is not importa

Re: [go-nuts] How to speed up execution time for a set of regular expressions

2016-12-13 Thread David Sofo
Thank you Andy for your reply, I can have optional classes like (B1|B2|B3)? and some keywords are multiword expression it can have some words within its parts. Exemple: *associate … with, **protect … from. Can *Aho-Corasick string matching used for this task. If I understood Aho-Corasick string

[go-nuts] Re: Looking for Golang counterpart to 'params' in Python

2016-12-13 Thread Betsy Lichtenberg
Thanks for the ideas. I'm using OAuth2, not basic Auth. I originally had the auth code in the header, but that resulted in a 401 because of this issue: https://nestdevelopers.io/t/rest-works-in-curl-but-not-in- python-requests-401-error/391/2 Below is the full Go script. The auth is working fin

Re: [go-nuts] import a "main" package

2016-12-13 Thread Jan Mercl
On Tue, Dec 13, 2016 at 5:19 PM Manlio Perillo wrote: > However I think that there is no reason why a "main" package should not be importable, to the point that > I think that the fact that a "main" package is not importable is an "exception" implemented in the Go tool. The package dependency gr

Re: [go-nuts] How to speed up execution time for a set of regular expressions

2016-12-13 Thread Andy Balholm
If it’s actually just a list of keywords (no wildcards, character ranges, etc.), I would recommend using Aho-Corasick string matching rather than regular expressions. Andy > On Dec 13, 2016, at 7:53 AM, David Sofo wrote: > > Hi, > > For a set of rules expressed in regular expression (around

[go-nuts] import a "main" package

2016-12-13 Thread Manlio Perillo
This is something that I asked in the past, but now it is a feature that I probably need for a project. I have a main package with some data fixtures, stored in the package assets directory. I want to implement a Go tool that, given a package importpath and a Data Source Name (not necessarily a

[go-nuts] How to speed up execution time for a set of regular expressions

2016-12-13 Thread David Sofo
Hi, For a set of rules expressed in regular expression (around 1000 rules expected) to find some keywords in a text file (~50Ko each file), how to speed up the execution time. Currently I compile the regex rule at initialization time with init function at put them in a map at package level th

[go-nuts] Re: Code-base Refactoring Tool for Go , Move files from packages to sub packages

2016-12-13 Thread adonovan via golang-nuts
On Tuesday, 13 December 2016 08:58:00 UTC-5, jis...@hifx.co.in wrote: > > > > http://stackoverflow.com/questions/41121448/code-base-refactoring-tool-for-go-move-files-from-packages-to-sub-packages > > Currently my code-base have just 1 level of packages , due to the increase > in number of compone

[go-nuts] Re: Looking for Golang counterpart to 'params' in Python

2016-12-13 Thread Val
Hello Betsy There is no "passing optional arguments by name" in go. This link [1] has an overview what what can or can't be done for optional params : - the *Functional options* technique. - or you may define a struct as parameter, then call it with only the fields you're interested in : [2] Thi

Re: [go-nuts] Evaluation order

2016-12-13 Thread Ian Lance Taylor
On Tue, Dec 13, 2016 at 6:46 AM, Jesper Louis Andersen wrote: > On Tue, Dec 13, 2016 at 2:57 PM Rafał Jęczalik > wrote: >> >> Hey Gophers! >> >> Does the spec guarantees the following program will always output "3 2"? >> > > Yes. f() is in funcall context, and there the order is lexicographic > l

Re: [go-nuts] Is there a tool or a library that lets me typecheck Go programs?

2016-12-13 Thread adonovan via golang-nuts
On Monday, 12 December 2016 12:22:51 UTC-5, Jan Mercl wrote: > > On Mon, Dec 12, 2016 at 6:20 PM > wrote: > > > I realize that obviously the Go compiler does it, I was wondering if > there is a good API for that I can use, like the ast package? > > See https://golang.org/pkg/go/types/ > You can u

Re: [go-nuts] Evaluation order

2016-12-13 Thread Jesper Louis Andersen
On Tue, Dec 13, 2016 at 2:57 PM Rafał Jęczalik wrote: > Hey Gophers! > > Does the spec guarantees the following program will always output "3 2"? > > Yes. f() is in funcall context, and there the order is lexicographic left-to-right as the specification says. -- You received this message becaus

Re: [go-nuts] Re: CPU scheduler on Xeon

2016-12-13 Thread Stannis Kozlov
Got it! Thanks On Tue, Dec 13, 2016 at 11:35 AM, Dave Cheney wrote: > > > On Tuesday, 13 December 2016 19:20:04 UTC+11, Stannis Kozlov wrote: >> >> Thanks for reply, Dave >> >> I've made simple application and run it on Xeon and i5. In case of i5 I >> see threads as expected, on Xeon CPU only on

Re: [go-nuts] json unmarshal automatic type conversion issue

2016-12-13 Thread Jesse McNelis
On Tue, Dec 13, 2016 at 7:43 PM, wrote: > Hi gophers, > > How to prevent json unmarshal from type conversion. From the below sample > code i got the input string converted to float64 Note that the variable 'input' is being assigned a json encoded number and not a json encoded string. Using a jso

[go-nuts] json unmarshal automatic type conversion issue

2016-12-13 Thread arunkumar
Hi gophers, How to prevent json unmarshal from type conversion. From the below sample code i got the input string converted to float64 package main import ( "fmt" "encoding/json" "reflect" ) func main() { var output interface{} var input = "1" fmt.Println(reflect.TypeOf(input)) json.Unmarshal

[go-nuts] net/http best way to get request/response header size

2016-12-13 Thread kaitoY Kors
Hello, In the current implementation of net/http and net/textproto, other than iterating all the key/value pairs of Header, type map[string][]string, is there any other way to get the total size effectively? The concern is if the header contains lots of key/value pairs, it might be inefficient

[go-nuts] Evaluation order

2016-12-13 Thread Rafał Jęczalik
Hey Gophers! Does the spec guarantees the following program will always output "3 2"? https://play.golang.org/p/InTOwJIPmD >From what I read [0] only evaluation order of expressions inside slice or map definitions or indexing on those values is unspecified? -- Rafal [0] https://golang.org/ref

[go-nuts] Make go commands autocomplete to package names

2016-12-13 Thread apquiche
Hi fellow gophers, I've managed to make go commands autocomplete the way I wanted to and figured someone here might be interested. - the way the go commands autocomplete frustrates me (mainly : it autocompletes to all files and directories, segment by segment, when usually expecting a package

[go-nuts] Code-base Refactoring Tool for Go , Move files from packages to sub packages

2016-12-13 Thread jishnu
http://stackoverflow.com/questions/41121448/code-base-refactoring-tool-for-go-move-files-from-packages-to-sub-packages Currently my code-base have just 1 level of packages , due to the increase in number of components it would make much sense if I use sub packages.Is there any code refactoring

Re: [go-nuts] Should I return a value or pointer?

2016-12-13 Thread 'Russ Cox' via golang-nuts
In the very old days, errors.New was spelled os.NewError, and it returned an os.errorString, not an &os.errorString, and so those error implementations did compare by string value. Arranging for the pointer to be used instead was done explicitly so that errors.New called with the same text from mul

[go-nuts] Re: SQLite3 Support without CGo

2016-12-13 Thread sam
If anyone is interested, I've opened a ticket on GitHub (https://github.com/golang/go/issues/18296). Please drop by and show your support. On Monday, December 12, 2016 at 11:28:19 PM UTC, brainman wrote: > > I was toying with this idea myself. > > Maybe even going all the way with "pure" Go vers

Re: [go-nuts] Should I return a value or pointer?

2016-12-13 Thread Jon
Thanks for the thorough answer! I think you answered my question. The errors package was the simplest piece of code I could find where it didn't seem to matter whether a value or pointer was passed so I wanted to know why a pointer was passed instead of a value. As you mentioned twice now (with

Re: [go-nuts] Function scoped method receivers

2016-12-13 Thread roger peppe
On 13 December 2016 at 01:08, go-question wrote: > > I noticed that its possible to define/scope types/interfaces in functions. > > Now I'm not arguing that this is good practice, but for the sake of > curiosity. > How can I then add a method w/ a receiver to type foo so that it satisfies > interf

Re: [go-nuts] Should I return a value or pointer?

2016-12-13 Thread 'Axel Wagner' via golang-nuts
On Tue, Dec 13, 2016 at 10:48 AM, Jon wrote: > Axel, that's an interesting thought on why errors.New() returns a > &errorString. However, I would argue that being able to do > errors.New("foo") == errors.New("foo") could be seen as a feature by some > people to break dependencies > Well, not by

Re: [go-nuts] Re: invitation to gophers.slack.com

2016-12-13 Thread Damian Gryski
On Friday, December 9, 2016 at 4:16:45 PM UTC+1, Ian Davis wrote: > > As an aside, does anyone know if there are publicly available chatlogs > from the slack channel? > > There are not. You must be a member of the Gophers Slack to see the message achive. Damian -- You received this message

Re: [go-nuts] Should I return a value or pointer?

2016-12-13 Thread Jon
Axel, that's an interesting thought on why errors.New() returns a &errorString. However, I would argue that being able to do errors.New("foo") == errors.New("foo") could be seen as a feature by some people to break dependencies, albeit suboptimal. Therefore I am not quite convinced this is the

[go-nuts] Re: Should I return a value or pointer?

2016-12-13 Thread Jon
I don't think this is a valid question with the errors package as the only option is (if err == myerrors.ErrValue) because errorString is private to the package. Therefore you cannot do (if e, ok := err.(*errors.errorString); ok). On Saturday, 10 December 2016 21:36:34 UTC, parais...@gmail.com

[go-nuts] Re: CPU scheduler on Xeon

2016-12-13 Thread Dave Cheney
On Tuesday, 13 December 2016 19:20:04 UTC+11, Stannis Kozlov wrote: > > Thanks for reply, Dave > > I've made simple application and run it on Xeon and i5. In case of i5 I > see threads as expected, on Xeon CPU only one thread is working. May it > related with difference go versions? > yes, th

[go-nuts] Re: CPU scheduler on Xeon

2016-12-13 Thread Stannis Kozlov
Thanks for reply, Dave I've made simple application and run it on Xeon and i5. In case of i5 I see threads as expected, on Xeon CPU only one thread is working. May it related with difference go versions? i5 output (go version 1.6): $ go run test_tr.go Spinning thread Spinning thread Spinning