Re: [go-nuts] Go has eliminated most of my off-by-one errors except 0... I mean 1.

2020-06-23 Thread C Banning
Well, I imagine there's only a few types in any code where the logic would require retrieving the "last" member of a list or array. Something like the following could address that and be more performant than using reflection - https://play.golang.org/p/XTbuf7RegF2. On Sunday, June 14, 2020 at

Re: [go-nuts] Go has eliminated most of my off-by-one errors except 0... I mean 1.

2020-06-13 Thread C Banning
https://play.golang.org/p/EZEXmBig1y- On Saturday, June 13, 2020 at 9:37:35 AM UTC-6, Jake Montgomery wrote: > > > > On Saturday, June 13, 2020 at 10:55:43 AM UTC-4, Jan Mercl wrote: >> >> On Sat, Jun 13, 2020 at 4:42 PM Tom Limoncelli >> wrote: >> >> I'd suggest to just write the short 'end'

[go-nuts] Re: Trying to parse sitemap xml data into struct

2020-03-03 Thread C Banning
The sequence of struct members doesn't matter - https://play.golang.org/p/m0wZtHcPRcU On Tuesday, March 3, 2020 at 5:49:10 AM UTC-7, Kuldeep Avsar wrote: > > I wrote a program to extract data from sitemaps's as this format > > type URLSet struct { > Urls []SitemapURL `xml:"url"` > } > > type

[go-nuts] Re: Help with XML parsing

2018-04-03 Thread C Banning
ibute, any idea how to do that? > > El martes, 3 de abril de 2018, 19:29:41 (UTC-3), C Banning escribió: >> >> https://play.golang.org/p/MwpdBwvRnUP >> >> On Tuesday, April 3, 2018 at 2:47:49 PM UTC-6, XXX ZZZ wrote: >>> >>> Hello, >>> >>&g

[go-nuts] Re: Help with XML parsing

2018-04-03 Thread C Banning
https://play.golang.org/p/MwpdBwvRnUP On Tuesday, April 3, 2018 at 2:47:49 PM UTC-6, XXX ZZZ wrote: > > Hello, > > I'm trying to parse an XML with golang but I'm having a hard time creating > a parser for the string, in fact I couldn't even get an output using > interface{}. > > package main >

Re: [go-nuts] Re: JSON and Embedded Types (Aliases)

2018-01-22 Thread C Banning
>From the Language Specification - A field declared with a type but no explicit field name is called an *embedded field*. An embedded field must be specified as a type name T or as a pointer to a non-interface type name *T, and T itself may not be a pointer type. The unqualified type name

[go-nuts] Re: JSON and Embedded Types (Aliases)

2018-01-21 Thread C Banning
https://play.golang.org/p/SiWmBrUYUXF On Saturday, January 20, 2018 at 11:16:20 PM UTC-7, dc0d wrote: > > Playground , output: {"Test":100}. > > On Sunday, January 21, 2018 at 9:42:39 AM UTC+3:30, dc0d wrote: >> >> Why embedded type aliases get ignored

[go-nuts] Re: Storing types in a map[string]type ?

2017-12-15 Thread C Banning
You can certainly do what, I think, you're wanting to do. "var versions map[string]Version" is valid. You probably want a package entry point something like "GetVersion(s string) *Version" to select the one you want to use in your mainline. (Note: each Version can use a unique struct if

[go-nuts] Re: Go Compiler How Work?!

2017-12-12 Thread C Banning
2017 at 2:16:23 AM UTC+3:30, C Banning wrote: >> >> Well, GO_BOOTSTRAP lets you use any compiler after go1.4. I usually >> build/install Go using the previous Go-built version - thus, I >> built/installed Go1.9 using the Go1.8.1 compiler. >> >> On Tuesday, Dece

[go-nuts] Re: Go Compiler How Work?!

2017-12-12 Thread C Banning
Well, GO_BOOTSTRAP lets you use any compiler after go1.4. I usually build/install Go using the previous Go-built version - thus, I built/installed Go1.9 using the Go1.8.1 compiler. On Tuesday, December 12, 2017 at 2:48:57 PM UTC-7, erfang...@gmail.com wrote: > > so Main compiler is at

[go-nuts] Re: XML Pretty Print

2017-12-11 Thread C Banning
Well, pretty much all the functionality you need is in clbanning/mxj/xmlseq.go ... so you could cut it out and clean it up a bit. On Monday, December 11, 2017 at 9:03:12 AM UTC-7, C Banning wrote: > > https://godoc.org/github.com/clbanning/mxj#BeautifyXml does that - but > you've g

[go-nuts] Re: is this safe?

2017-11-22 Thread C Banning
Why not something simple like: https://play.golang.org/p/iAlflMUdEA On Monday, November 20, 2017 at 9:48:31 AM UTC-7, Trig wrote: > > for i, user := range myList { > if user.Disabled { > myList = append(myList[:i], myList[i + 1:]...) // remove user from > return list > } > } > > > Is

[go-nuts] Re: json unmarshling error > cannot unmarshal object into Go struct field ParticipantIty.Player of type []utils.Playe

2017-06-29 Thread C Banning
Try: > type ParticipantIty struct { > ParticipantId int > PlayerPlayer > } > On Thursday, June 29, 2017 at 6:10:03 AM UTC-6, Martin Spasov wrote: > > Hey guys, > > I have been trying to decode a json object into a struct with nested > structs. When the struct is 1 level deep it

[go-nuts] Re: "non-bool used as if condition" - why not?

2017-05-21 Thread C Banning
Echoing Nigel. Here's some C: if ((tempNode->parent) && (tempNode->arcToParent->flow)) { // do some work } Here's some Go: if tempNode.parent != nil && tempNode.arcToParent.flow != 0 { // do some work } Certainly the Go code is easier to understand; especially if you're asked to support

[go-nuts] Re: json with comments

2017-05-06 Thread C Banning
https://godoc.org/github.com/clbanning/checkjson#ReadJSONFile and ReadJSONReader will process JSON files or streams that have comments - however, no block comments. More importantly the package provides functions that check for potentially misspelled keys in the JSON object and to identify

[go-nuts] Re: Number of OS threads used by Go runtime

2017-04-07 Thread C Banning
Or: https://play.golang.org/p/ZgI19Z4uU1 On Thursday, April 6, 2017 at 9:37:55 AM UTC-6, Юрий Шахматов wrote: > > Hi all! > > Is there any way to count number of OS threads used by Go runtime > programmatically (ie without using bash with top/ps and others)? > > -- > Best regards, Yuri > --

[go-nuts] Re: Accuracy of time.Sleep and time.Ticker

2017-03-31 Thread C Banning
On a MacBook Pro, 2.6 GHz Intel Core i7, 8 GB 1600 MHz DDR3, I get: 2017-03-31 15:51:00 -0600 MDT - next tick Current : 2017-03-31 15:51:00.8893 -0600 MDT Expected: 2017-03-31 15:51:00 -0600 MDT On Friday, March 31, 2017 at 1:44:44 PM UTC-6, apollo wellstein wrote: > > I seem to be

[go-nuts] Re: JSON empty slice and/or empty set encoding question/proposal

2017-03-30 Thread C Banning
Why not provide a "NewFoo() *Foo" function instead? https://play.golang.org/p/GE8cMgwe24 On Monday, March 27, 2017 at 10:42:46 AM UTC-6, traetox wrote: > > Hello all, > > I have swept through the list and gone through the pkg/encoding/json > package and _believe_ I haven't missed anything, but

Re: [go-nuts] sort.Slice arguments

2017-03-08 Thread C Banning
https://play.golang.org/p/Pqd0Wk-yqe -- 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

[go-nuts] Re: File organization in a github-ed Go project

2017-02-27 Thread C Banning
Try organizing your project as: monimelt src cmd (or "monimelt", if there's just one app) objvalmo serial Then include $HOME/monimelt in your GOPATH. > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group

Re: [go-nuts] Initializing nested struct, by dynamically forming struct member path

2017-02-22 Thread C Banning
Clean-up example: https://github.com/clbanning/mxj/blob/master/examples/leafnodes.go On Wednesday, February 22, 2017 at 4:31:47 AM UTC-7, C Banning wrote: > > Perhaps not very elegant but seems to produce what you're looking for: > https://play.golang.org/p/bpM69Q-ddV > --

Re: [go-nuts] Initializing nested struct, by dynamically forming struct member path

2017-02-22 Thread C Banning
Perhaps not very elegant but seems to produce what you're looking for: https://play.golang.org/p/bpM69Q-ddV -- 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

Re: [go-nuts] how to write self-closing xml tags

2017-01-30 Thread C Banning
https://play.golang.org/p/W5cQkqS0h_ On Monday, January 30, 2017 at 9:06:49 AM UTC-7, Henrik Johansson wrote: > > I am truly sorry for resurrecting this old thread but I found my self > needing to emit xml containing: > > > > today and I am unsure how to deal with it. > > I have to do it for

[go-nuts] Re: I know finalizers are not promised to be called, but is it too not promised?

2017-01-28 Thread C Banning
>From the doc: "The finalizer for obj is scheduled to run at some arbitrary time after obj becomes unreachable. There is no guarantee that finalizers will run before a program exits, so typically they are useful only for releasing non-memory resources associated with an object during a

[go-nuts] Re: how to seek in file using go

2017-01-19 Thread C Banning
Why rd := bufio.NewReader(fi)? 'fi' implements io.Reader. Try: err = binary.Read(fi, binary.LittleEndian, ) instead. Then fi.Seek(...) will manipulate your io.Reader. [An example: https://github.com/clbanning/rfile/blob/master/reverse.go#L57.] On Wednesday, January 18, 2017 at 11:22:48

[go-nuts] Re: Test code that interacts with private variables and doesn't bloat binary

2017-01-17 Thread C Banning
See TestMain() documentation in "Overview" for https://golang.org/pkg/testing/ On Tuesday, January 17, 2017 at 12:28:34 AM UTC-7, alcub...@gmail.com wrote: > > I'm trying to test my packages without bloating the size of the binary. > Currently this consists of moving the test code into a test/

Re: [go-nuts] enforce go source pretty printing

2017-01-07 Thread C Banning
How would this work for you: https://play.golang.org/p/totWmcs8Om On Saturday, January 7, 2017 at 4:12:01 AM UTC-7, mhh...@gmail.com wrote: > > Might work indeed. > > Let s see if i feel in such struggle that i rewrite the KeyValueExpr to > some sort of map assignments. > > thanks! > > On

Re: [go-nuts] enforce go source pretty printing

2017-01-07 Thread C Banning
Or this: https://play.golang.org/p/GF97Pk0gbv On Saturday, January 7, 2017 at 4:12:01 AM UTC-7, mhh...@gmail.com wrote: > > Might work indeed. > > Let s see if i feel in such struggle that i rewrite the KeyValueExpr to > some sort of map assignments. > > thanks! > > On Saturday, January 7, 2017

[go-nuts] Re: What happen if channel is full and there're no way out for this channel?

2017-01-04 Thread C Banning
Not until 'c' is closed. Also, http://localhost:6060/ref/spec#Close On Wednesday, January 4, 2017 at 1:28:41 PM UTC-7, Kritta wrote: > > In other word, Will GC collect this channel for me. > > On Thursday, January 5, 2017 at 3:26:07 AM UTC+7, Kritta wrote: >> >> For example, >> >> go func() { >>

[go-nuts] Re: How to use ~/ in terminal with go program?

2016-12-28 Thread C Banning
if file[0] == '~' { On Wednesday, December 28, 2016 at 6:22:06 AM UTC-7, Aurélien Desbrières wrote: > > As explain ~/ in golang , I > am trying to request the user to cat a file with a gocat program. > > The point is that if the user tell to the

[go-nuts] Re: omitempty custom json Marshaller

2016-12-26 Thread C Banning
https://play.golang.org/p/WoCO7VGvDE On Sunday, December 25, 2016 at 6:36:47 AM UTC-7, Forud A wrote: > > Hi, > I have a struct with custom json.MarshallJSON function. I need to ignore > field of this type when the value is null. something like this > > package main > > import ( >

Re: [go-nuts] Re: JSON smart parsing

2016-12-20 Thread C Banning
Seems to lack Encoding functionality. On Tuesday, December 20, 2016 at 1:39:14 PM UTC-7, ma...@influxdb.com wrote: > > https://github.com/json-iterator/go was recently trending on GitHub. > > I haven't used it personally but it sounds like it might fit your use case. > > On Tuesday, December 20,

Re: [go-nuts] xml omitempty for sub-elements

2016-12-08 Thread C Banning
https://play.golang.org/p/aMtZhha073 On Thursday, December 8, 2016 at 10:09:17 AM UTC-7, Peter Kleiweg wrote: > > Four years later, and this still hasn't been fixed. The conversation you > are linking to has been locked. What can we do? File a new bug report? > > > Op donderdag 15 november 2012

[go-nuts] Re: stripping null in json string

2016-11-27 Thread C Banning
Not sure what you're looking for but here's a couple examples: https://play.golang.org/p/Rrg3kWkuGV On Thursday, November 24, 2016 at 2:02:20 PM UTC-7, Seanchann Zhou wrote: > > hi: >have json: > > "test": { > "test1": null, > "test2": null, > "test3": null, >

[go-nuts] Re: Beautify XML

2016-11-04 Thread C Banning
You can try: https://godoc.org/github.com/clbanning/mxj#BeautifyXml On Friday, November 4, 2016 at 3:32:24 PM UTC-6, Tong Sun wrote: > > How to beautify a given XML string in GO? > > The xml.MarshalIndent() only apply to a GO structure, not XML strings. > > Thanks > > -- You received this

[go-nuts] Re: How to initialize all members of a slice

2016-10-03 Thread C Banning
Lot's of people will jump up and down that this is "unsafe," but if you're building a utility and have complete control of the code something like this might work: https://play.golang.org/p/eDPoI83C0u On Sunday, October 2, 2016 at 10:39:08 PM UTC-6, Sarah Ahmed wrote: > > Hello, > I am trying

[go-nuts] Re: unmarshaling json to byte type

2016-09-14 Thread C Banning
Not very elegant but: https://play.golang.org/p/m6WFioPURM On Wednesday, September 14, 2016 at 9:06:41 AM UTC-6, Luke wrote: > > Hi, > > i have something like: https://play.golang.org/p/j5WhDMUTI- > > type A struct { >Name string `json:"n"` >Typ byte `json:"t"` > } > > JSON string:

[go-nuts] Re: Max age for TCP connection

2016-09-13 Thread C Banning
What is your http.Client.Timeout value? On Tuesday, September 13, 2016 at 8:57:45 AM UTC-6, david...@ft.com wrote: > > Hi, > > We've got a HTTP client connecting to an active-passive cluster setup, > controlled through a traffic managed DNS entry and a good-to-go signal on > each cluster. When

[go-nuts] Re: Search for Another JSON Package

2016-08-24 Thread C Banning
https://godoc.org/github.com/ugorji/go/codec supports this. On Wednesday, August 24, 2016 at 3:30:10 AM UTC-6, dc0d wrote: > > Is there a JSON package that have these characteristics? > > >- can marshal numeric integer values to strings (like >using `json:",string"` tag) >- can

[go-nuts] Re: redirect already running processes stdout

2016-07-01 Thread C Banning
Check out: https://golang.org/pkg/os/exec/#example_Cmd_StdoutPipe On Friday, July 1, 2016 at 11:35:28 AM UTC-6, ethanl...@gmail.com wrote: > > I am starting to look into intercepting