[go-nuts] Update Mongodb fields with omitempty flag in Golang structure

2017-11-07 Thread Amandeep Kaur
Hi I am working on a Coupon form in which I have some optional fields. *Introduction:* All the form field values are received as JSON and mapped into a Golang structure. In the structure, I have added an "omitempty" flag with every field. So only those form values are mapped which have

[go-nuts] Re: A way to detect closed channel

2017-11-07 Thread Jason E. Aten
Also since nobody else mentioned it, for completeness: the optional second argument to the receive will always tell you if the channel is already closed, if all you are doing is trying to distinguish the zero value from a closed versus unclosed channel.

[go-nuts] Re: A way to detect closed channel

2017-11-07 Thread Jason E. Aten
As others pointed out, you need to use a lock if you want to close a channel from multiple, possibly concurrent, code locations. Here is an example of how I handle such situations: https://github.com/glycerine/idem/blob/master/halter.go#L11 Feel free to use that library, or parts of it. In

[go-nuts] gccgo programs use which garbage collector?

2017-11-07 Thread Jason E. Aten
Just a general question about the binaries produced by gccgo. To wit: Do these binaries use the same garbage collector as gc-produced binaries -- the highly-tuned/low-latency garbage collector that Rick and Austin work on -- or do they use something else? If else, what is used? Thanks! --

[go-nuts] Re: Announcing: Skylark in Go

2017-11-07 Thread bsr
Like Nate mentioned, I too like to try it instead of lua. Is there a good example on how to embed skylark to define custom logic. Thanks. On Monday, October 2, 2017 at 12:39:43 PM UTC-4, Alan Donovan wrote: > > I'm pleased to announce the launch of Skylark in Go: an interpreter for > Skylark,

Re: [go-nuts] newbie trying unusual sort

2017-11-07 Thread Caleb Spare
You could define multiple types: type bySubtotal []directory type byName []directory which have different Sort methods. You could also define a type that includes a func(d0, d1 directory) bool. The SortKeys example in the sort package docs (https://golang.org/pkg/sort/#example__sortMultiKeys)

Re: [go-nuts] newbie trying unusual sort

2017-11-07 Thread Rob Pike
Look at the "Example (SortKeys)" part of https://golang.org/pkg/sort/ -rob On Wed, Nov 8, 2017 at 12:38 PM, rob wrote: > Hi. I am trying to sort a slice of a struct using one of two different > fields. > > type directory struct { > name string > subtotal int64

[go-nuts] newbie trying unusual sort

2017-11-07 Thread rob
Hi.  I am trying to sort a slice of a struct using one of two different fields. type directory struct {     name string     subtotal int64 } type dirslice []directory I want to sort a var of type dirslice by either name or subtotal.  I understand how to sort by one of those, by defining

Re: [go-nuts] Re: Announcing: Skylark in Go

2017-11-07 Thread 'Alan Donovan' via golang-nuts
On 7 November 2017 at 15:54, Zellyn Hunter wrote: > Oh neat. So is it a sort of competitor to jsonnet? I guess jsonnet is > usually used to generate actual config files, not live-interpret executable > config. > Jsonnet is more of a templating language whereas Skylark is

Re: [go-nuts] Re: Announcing: Skylark in Go

2017-11-07 Thread Zellyn Hunter
Oh neat. So is it a sort of competitor to jsonnet? I guess jsonnet is usually used to generate actual config files, not live-interpret executable config. Zellyn On Tue, Nov 7, 2017 at 3:46 PM Alan Donovan wrote: > On 7 November 2017 at 15:36, Zellyn

Re: [go-nuts] Re: Announcing: Skylark in Go

2017-11-07 Thread 'Alan Donovan' via golang-nuts
On 7 November 2017 at 15:36, Zellyn wrote: > An only-2x-slower than CPython interpreter is pretty cool. Just very > curious what y'all are doing with it. > Various infrastructure projects (such as Copybara) are using Skylark as a configuration language since it has proven

[go-nuts] Re: Announcing: Skylark in Go

2017-11-07 Thread Zellyn
Bump, since y'all seem to be actively posting here :-) An only-2x-slower than CPython interpreter is pretty cool. Just very curious what y'all are doing with it. On Thursday, November 2, 2017 at 3:22:44 PM UTC-4, Zellyn wrote: > > This looks neat. Are you able to provide more context on what

Re: [go-nuts] Re: Announcing: Skylark in Go

2017-11-07 Thread Ben Hoyt
On Tue, Nov 7, 2017 at 3:16 PM, Alan Donovan wrote: > On 7 November 2017 at 15:06, Ben Hoyt wrote: > >> >> 2x as fast as CPython sounds pretty good to me -- nice! >>> > No, CPython is 2x as fast as Skylark in Go. It's implemented in C, so it > can

Re: [go-nuts] Re: Announcing: Skylark in Go

2017-11-07 Thread 'Alan Donovan' via golang-nuts
On 7 November 2017 at 15:06, Ben Hoyt wrote: > > 2x as fast as CPython sounds pretty good to me -- nice! >>> >> No, CPython is 2x as fast as Skylark in Go. It's implemented in C, so it can do things that are sadly impossible in Go, like implement a threaded bytecode

Re: [go-nuts] Re: Announcing: Skylark in Go

2017-11-07 Thread Ben Hoyt
> On Thursday, November 2, 2017 at 9:42:27 PM UTC-4, Ben Hoyt wrote: >>> >>> I'm very curious how the performance of Skylark in Go compares to >>> Skylark in Java (and CPython 3.6 for that matter) -- any benchmarks on that? >>> >> > I don't have any rigorous comparisons, but my informal testing on

[go-nuts] Re: Announcing: Skylark in Go

2017-11-07 Thread adonovan via golang-nuts
On Saturday, 4 November 2017 11:52:05 UTC-4, Keith Brown wrote: > > Are there any native golang tools simar to this which work on > Windows/Linux/OSX? > The Skylark interpreter doesn't make any particular assumptions about the CPU or OS, so it should be highly portable. Please file an issue

[go-nuts] Re: Short Term DSN for database/sql

2017-11-07 Thread Daniel Theophanes
Go1.10 will ship with a driver connector https://tip.golang.org/pkg/database/sql/driver/#Connector . It would be possible for a driver to provide a callback function that returned the most recent authentication parameters by using that. Thanks, -Daniel On Tuesday, November 7, 2017 at 5:34:20

Re: [go-nuts] Short Term DSN for database/sql

2017-11-07 Thread agruetz45
This does not help because if there is no connection in the connection pool the interface will open a new connection with previously supplied DSN from the sql.Open call. Anthony On Tuesday, November 7, 2017 at 7:22:00 AM UTC-8, Konstantin Khomoutov wrote: > > On Tue, Nov 07, 2017 at

Re: [go-nuts] XML Parsing Nested Elements

2017-11-07 Thread lesmond
Thank you for the incredibly detailed response. It has really helped to understand the situation. I actually started with an iterative approach with a Decoder object and this got very complex, very quickly. It worked but the code was unworkable going forwards. I thought it might be worth

Re: [go-nuts] XML Parsing Nested Elements

2017-11-07 Thread Konstantin Khomoutov
On Tue, Nov 07, 2017 at 03:35:45AM -0800, lesm...@gmail.com wrote: > I am really struggling to access nested elements of an XML string and > suspect it is down to the namespaces. This string is obtained from a > larger document and is the "innerXML" of some elements. A simplified > version is

Re: [go-nuts] Re: who does go compiler link executable to glibc without an apparent reason?

2017-11-07 Thread Ian Lance Taylor
On Tue, Nov 7, 2017 at 1:28 AM, Howard Guo wrote: > Just noticed this statement from src/net/net.go: > > -- > On Unix systems, the resolver has two options for resolving names. > It can use a pure Go resolver that sends DNS requests directly to the > servers >

Re: [go-nuts] Short Term DSN for database/sql

2017-11-07 Thread Konstantin Khomoutov
On Tue, Nov 07, 2017 at 12:06:27AM -0800, agruet...@gmail.com wrote: > It appears the Generic Interface for SQL (database/sql) does not support > the ability to use short lived DSN's for cases like AWS's IAM > Authentication to RDS instances. It appears that when doing its connection > pooling

Re: [go-nuts] A way to detect closed channel

2017-11-07 Thread Daniel Skinner
Instead of recover, I'd consider simply writing to the channel. https://play.golang.org/p/ShoadwrwTQ If it has to be a close, pass in additional state to close only once. https://play.golang.org/p/pwO3JF60Cr On Tue, Nov 7, 2017 at 3:32 AM roger peppe wrote: > On 7

Re: [go-nuts] graceful restart of app with more than one tcp Listener

2017-11-07 Thread Peter Mogensen
On 2017-11-07 15:28, Vasiliy Tolstov wrote: > I know about it, but > https://github.com/rcrowley/goagain/issues/12 cant handle multiple listeners > https://godoc.org/github.com/facebookgo/grace/gracenet does not > support close the listener > https://github.com/fvbock/endless works with http ,

Re: [go-nuts] graceful restart of app with more than one tcp Listener

2017-11-07 Thread Vasiliy Tolstov
2017-11-07 17:20 GMT+03:00 Steven Hartland : > There are a number of libraries which attempt to address this, ones I've > seen: > > https://github.com/fvbock/endless > https://github.com/rcrowley/goagain > https://github.com/facebookgo/grace > > I know about it, but

Re: [go-nuts] graceful restart of app with more than one tcp Listener

2017-11-07 Thread Steven Hartland
There are a number of libraries which attempt to address this, ones I've seen: * https://github.com/fvbock/endless * https://github.com/rcrowley/goagain * https://github.com/facebookgo/grace On 07/11/2017 13:33, Vasiliy Tolstov wrote: Hi! I have application that listens 2-4 tcp ports and

[go-nuts] graceful restart of app with more than one tcp Listener

2017-11-07 Thread Vasiliy Tolstov
Hi! I have application that listens 2-4 tcp ports and i need to upgrade it while running. How can upgrade server and not dropping exiting connected apps (tcp nbd-client like apps)? I don't want to use haproxy or nginx before my app. As i understand i need master process that only listens sockets

[go-nuts] Short Term DSN for database/sql

2017-11-07 Thread agruetz45
It appears the Generic Interface for SQL (database/sql) does not support the ability to use short lived DSN's for cases like AWS's IAM Authentication to RDS instances. It appears that when doing its connection pooling activities it always uses whatever DSN was passed initially on Open. 1) Is

[go-nuts] Re: who does go compiler link executable to glibc without an apparent reason?

2017-11-07 Thread Howard Guo
Thanks for the info! Kind regards, Howard On Tuesday, 7 November 2017 12:15:46 UTC+1, Dave Cheney wrote: > > Until recently some functions in the os/user package were only available > via glibc. > > The net package links to cgo by default to pick up the nss libraries, > which are important if

Re: [go-nuts] Re: [Request] Official golang debugger

2017-11-07 Thread Sotirios Mantziaris
You both make good point to why that might have it's issues. Taken into account the time mentioned it makes more sense to keep it separate and have it's own release cycle. Thanks for your input. On Tue, Nov 7, 2017 at 1:46 PM Dave Cheney wrote: > > > On Tuesday, 7 November 2017

Re: [go-nuts] Re: [Request] Official golang debugger

2017-11-07 Thread Dave Cheney
On Tuesday, 7 November 2017 22:29:29 UTC+11, Sotirios Mantziaris wrote: > > Apart from the time it would take to make changes to a tool in the > toolchain i could come up with a reason for that: > > If a new feature gets added to go that would affect the debugger it would > be tackled away as

[go-nuts] Re: Why does go run cmd does not accept a directory as an input

2017-11-07 Thread Dave Cheney
On Tuesday, 7 November 2017 22:22:43 UTC+11, Vladimir Varankin wrote: > > Thank you, Dave, for the response. > > > You’ll have a more enjoyable go experience if you structure your code > into packages and use go build or preferably go install. > > To be fair, I don't think that having the

[go-nuts] XML Parsing Nested Elements

2017-11-07 Thread lesmond
I am really struggling to access nested elements of an XML string and suspect it is down to the namespaces. This string is obtained from a larger document and is the "innerXML" of some elements. A simplified version is at... I could probably do this with multiple structs but want to have

Re: [go-nuts] Re: [Request] Official golang debugger

2017-11-07 Thread Sotirios Mantziaris
Apart from the time it would take to make changes to a tool in the toolchain i could come up with a reason for that: If a new feature gets added to go that would affect the debugger it would be tackled away as part of the release as opposed to wait for the final release and start implementing the

[go-nuts] Re: Why does go run cmd does not accept a directory as an input

2017-11-07 Thread Vladimir Varankin
Thank you, Dave, for the response. > You’ll have a more enjoyable go experience if you structure your code into packages and use go build or preferably go install. To be fair, I don't think that having the ability to do build + run in one go command goes against the fact that it's worth to

[go-nuts] Re: who does go compiler link executable to glibc without an apparent reason?

2017-11-07 Thread Dave Cheney
Until recently some functions in the os/user package were only available via glibc. The net package links to cgo by default to pick up the nss libraries, which are important if your installation uses ldap. I argued that this should not be the default in the 1.5 release, that most users

[go-nuts] Re: who does go compiler link executable to glibc without an apparent reason?

2017-11-07 Thread Howard Guo
Do you by any chance know what the rationale would be? Kind regards, Howard On Tuesday, 7 November 2017 11:55:22 UTC+1, Dave Cheney wrote: > > The net and os/user packages will force dynamic linking unless > CGO_ENABLED=0 or you are cross compiling. -- You received this message because you

[go-nuts] who does go compiler link executable to glibc without an apparent reason?

2017-11-07 Thread Dave Cheney
The net and os/user packages will force dynamic linking unless CGO_ENABLED=0 or you are cross compiling. -- 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

[go-nuts] Re: who does go compiler link executable to glibc without an apparent reason?

2017-11-07 Thread Howard Guo
Thanks very much Karan, that's indeed a good approach for this challenge. Here is the output from a dynamically linked executable: abort __errno_location fprintf fputc free freeaddrinfo fwrite gai_strerror getaddrinfo getnameinfo malloc mmap munmap nanosleep pthread_attr_destroy

Re: [go-nuts] Is there a way or lib to read a binary into a sturct{len int32;data [len]int32}

2017-11-07 Thread Konstantin Khomoutov
On Tue, Oct 31, 2017 at 04:36:20PM +0800, hui zhang wrote: [...] > > > Is there a way or lib to read a binary into a this structure in one line > > > code? > > > > > > how about more complicate struct ? > > > type complicatestrt struct { > > > len int32 > > > strData []variastrt > > >

[go-nuts] Re: who does go compiler link executable to glibc without an apparent reason?

2017-11-07 Thread Karan Chaudhary
With a quick look, it seems "net" is not the only pkg which depends on cgo, though by default it uses pure Go DNS resolver only. I tested on small program: package main import ( "fmt" "net/http" ) func main() { fmt.Println("Hello, playground")

[go-nuts] Why does go run cmd does not accept a directory as an input

2017-11-07 Thread Dave Cheney
Real talk: go run is for examples as large as one would type into the playground. Nothing more. You’ll have a more enjoyable go experience if you structure your code into packages and use go build or preferably go install. -- You received this message because you are subscribed to the

[go-nuts] Why does go run cmd does not accept a directory as an input

2017-11-07 Thread Vladimir Varankin
Currently `go run` accepts a file or a list of ".go" files: ``` % go help run usage: go run [build flags] [-exec xprog] gofiles... [arguments...] ``` For me, it doesn't seem to be obvious, why can't "go run" accept the directory that contains files of the main package as an input? Note, I'm

Re: [go-nuts] A way to detect closed channel

2017-11-07 Thread Dave Cheney
gross. -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.

Re: [go-nuts] A way to detect closed channel

2017-11-07 Thread Steven Hartland
If you're using it as a signal to trigger only on close and not sending any data, you should use chan struct{}, the reason for this is is that the empty struct consumes zero storage . Also there is a multi-valued assignment form of the

[go-nuts] Re: Data persistence in go routine in defer

2017-11-07 Thread Karan Chaudhary
Yes it will work as "x" is within scope. https://play.golang.org/p/dhBahtIVGb On Tuesday, 7 November 2017 14:42:47 UTC+5:30, Abhijit Desai wrote: > > I want to log MyStruct value in "defer + go routine" so that logging > will not affect total execution time of the the request which works

Re: [go-nuts] Re: [Request] Official golang debugger

2017-11-07 Thread Florin Pățan
For that tool, which is not the subject of this thread, the maintainers are willing to pay the price of inclusion in the toolchain. As I stated in my original reply,I would hope we don't have to pay the same price for the debugger. I don't understand why anyone thinks that inclusion in the

Re: [go-nuts] A way to detect closed channel

2017-11-07 Thread roger peppe
On 7 November 2017 at 00:59, Albert Tedja wrote: > So, I just found out that closed channels always yield the zero value. That > means, a closed channel inside a select statement seems to always be > guaranteed to be executed. > > Since closing an already closed channel

[go-nuts] Re: who does go compiler link executable to glibc without an apparent reason?

2017-11-07 Thread Howard Guo
Just noticed this statement from src/net/net.go: -- On Unix systems, the resolver has two options for resolving names. It can use a pure Go resolver that sends DNS requests directly to the servers listed in /etc/resolv.conf, or it can use a cgo-based resolver that calls C library

Re: [go-nuts] Re: [Request] Official golang debugger

2017-11-07 Thread Sotirios Mantziaris
https://github.com/golang/dep/wiki/Roadmap The goal with dep is to be absorbed into the go toolchain. That's the path we're on, but it's up to the Go community - you! - to help us see it through. On Tue, Nov 7, 2017 at 11:16 AM Florin Pățan wrote: > dep is not part of

Re: [go-nuts] Re: [Request] Official golang debugger

2017-11-07 Thread Florin Pățan
dep is not part of the toolchain. On Tue, 7 Nov 2017, 08:38 Sotirios Mantziaris, wrote: > would it not make sense them to keep dep out of the std toolchain to adapt > faster to changes? > > On Tuesday, November 7, 2017 at 9:31:01 AM UTC+2, Dave Cheney wrote: >> >> If you

[go-nuts] Data persistence in go routine in defer

2017-11-07 Thread desaiabhijit
I want to log MyStruct value in "defer + go routine" so that logging will not affect total execution time of the the request which works fine as serving request is not taking 5+seconds... my question is.. will I get value of "x" in "defer + go routine" as main module already exit

Re: [go-nuts] Re: [Request] Official golang debugger

2017-11-07 Thread Sotirios Mantziaris
would it not make sense them to keep dep out of the std toolchain to adapt faster to changes? On Tuesday, November 7, 2017 at 9:31:01 AM UTC+2, Dave Cheney wrote: > > If you reported an issue today, Nov 6, you could be waiting nearly 9 > months to see a fix in the next released version of Go. >