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 9

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' f

[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 Sit

[go-nuts] Re: Help with XML parsing

2018-04-03 Thread C Banning
, 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, >>> >>> I

[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 acts

[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 throug

[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 neces

[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 previous

[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'

[go-nuts] Re: XML Pretty Print

2017-12-11 Thread C Banning
https://godoc.org/github.com/clbanning/mxj#BeautifyXml does that - but you've got to lug around a pretty large package just for that functionality. On Monday, December 11, 2017 at 8:12:38 AM UTC-7, Mandolyte wrote: > > At my previous company I had a Go program that would take any XML document >

[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 using

[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 so

[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 str

[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 > -- Yo

[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 having

[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 a

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 https://gr

[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 a

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 gola

[go-nuts] ANN: checkxml package for validating XML data using struct definitions.

2017-02-21 Thread C Banning
The checkxml package [1] extends the mxj package [2] to validate XML data using go struct definitions. [1] https://github.com/clbanning/checkxml [2] https://github.com/clbanning/mxj -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe

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 le

[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 long-run

[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, &pi) 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/ s

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 Saturda

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 a

[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: What happen if channel is full and there're no way out for this channel?

2017-01-04 Thread C Banning
select { case c <- true: method1() default: // do something because channel is full // perhaps put in a for{} loop to retry after a pause } On Wednesday, January 4, 2017 at 1:26:07 PM UTC-7, Kritta wrote: > > For example, > > go func() { >c <- true //This is blocked cause c is full

[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 termi

Re: [go-nuts] Converting escaped unicode to utf8

2016-12-26 Thread C Banning
If you're processing anonymous messages and don't know where unicode will occur you might want something like this: https://play.golang.org/p/M-21sy_en5 On Monday, December 26, 2016 at 9:41:15 AM UTC-7, JohnGB wrote: > > Thanks Roger. That is a really elegant solution. > > On 26 December 2016 a

[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 ( > "encoding/jso

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, 2

[go-nuts] Re: JSON smart parsing

2016-12-20 Thread C Banning
Don't know how to make 'X' simple, but you can use a strategy like https://play.golang.org/p/1bdlbFWjwg which at least minimizes allocations by only Unmarshal'ing the k:v pairs of interest. On Tuesday, December 20, 2016 at 8:48:03 AM UTC-7, Alexander Petrovsky wrote: > > Hello! > > By example I

[go-nuts] Re: JSON smart parsing

2016-12-20 Thread C Banning
Don't know how to make 'X' simple, but you can use a strategy like https://play.golang.org/p/n4ms3hNGgy which at least minimizes allocations by only Unmarshal'ing the k:v pairs of interest. On Tuesday, December 20, 2016 at 8:48:03 AM UTC-7, Alexander Petrovsky wrote: > > Hello! > > By example I

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 1

[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, > "test4

[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 mess

[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 to

[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 unmars

[go-nuts] Re: Data locality in large slices

2016-08-03 Thread C Banning
PS - that's with Go v1.6. On Wednesday, August 3, 2016 at 7:49:49 AM UTC-6, C Banning wrote: > > On MacBook Pro, 2.6 GHz Intel Core i7, 8 GB 1600 MHz memory, running OS X > 10.11.6, your benchmarks look pretty consistent: > > > BenchmarkStart-4 20 1.45

[go-nuts] Re: Data locality in large slices

2016-08-03 Thread C Banning
On MacBook Pro, 2.6 GHz Intel Core i7, 8 GB 1600 MHz memory, running OS X 10.11.6, your benchmarks look pretty consistent: BenchmarkStart-4 20 1.45 ns/op BenchmarkEnd-420 1.47 ns/op BenchmarkHereThere-4 20 1.46 ns/op BenchmarkSta

[go-nuts] Re: Data locality in large slices

2016-08-03 Thread C Banning
On MacBook Pro, 2.6 GHz Intel Core i7, 8 GB 1600 MHz memory, you benchmarks look pretty consistent: BenchmarkStart-4 20 1.45 ns/op BenchmarkEnd-420 1.47 ns/op BenchmarkHereThere-4 20 1.46 ns/op BenchmarkStartEnd-4 20

[go-nuts] Re: Can I convert bytes.Buffer object to a string, and vice-versa ?

2016-07-11 Thread C Banning
https://play.golang.org/p/BmKQTewR9w On Monday, July 11, 2016 at 6:06:12 AM UTC-6, Mayank Jha wrote: > > Can I convert bytes.Buffer object to a string, and vice-versa , getting > the original bytes.Buffer object back from the string ? > -- You received this message because you are subscribed to

[go-nuts] Re: Does http PATCH not read body data ?

2016-07-09 Thread C Banning
try: https://play.golang.org/p/2RDK8JVO_2 On Saturday, July 9, 2016 at 12:12:42 PM UTC-6, Mayank Jha wrote: > > I am using, https://play.golang.org/p/0_FhHaMNIz to implement a PATCH > method endpoint. However when I try to read the body, using io.ioutil I am > getting nothing in the body even th

[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

Re: [go-nuts] Re: encoding/json: any way to receive number literal "10.0" into integer field?

2016-06-18 Thread C Banning
Or: https://play.golang.org/p/VjFJGUI27W On Friday, June 17, 2016 at 4:33:20 PM UTC-6, Matt Harden wrote: > > https://play.golang.org/p/8R6QmYw_28 > > On Fri, Jun 17, 2016 at 3:08 PM Evan Digby > wrote: > >> To further this, if you do need your internal model to be a concrete >> struct rather th