Re: [go-nuts] Re: how to omit empty array

2020-09-03 Thread Nishanth Shanmugham
> I was under the impression it wouldn't omit the array if it had zero length, hence my question. Using omitempty omits the array/slice field in the encoding if it is zero length. Check out https://play.golang.org/p/B1LcICyEfeK. Related encoding/json pack

Re: [go-nuts] Re: how to omit empty array

2020-09-03 Thread burak serdar
On Thu, Sep 3, 2020 at 2:32 PM Alexander Mills wrote: > > I was under the impression it wouldn't omit the array if it had zero length, > hence my question.. > i mean at some point we want an empty array in JSON, so I assume it's > included by default If you define boolField as a type, then you

Re: [go-nuts] how to declare type as interface{}

2020-09-03 Thread Harald Weidner
Hello, > but this doesn't work: > > if err := json.NewDecoder(resp.Body).Decode(&interface{}{}); err != nil { > t.Fatal(err) > } You can use new(interface{}). See https://play.golang.org/p/s85MwlDygBG Harald -- You received this message because you are subscribed to the Google Groups "g

Re: [go-nuts] how to declare type as interface{}

2020-09-03 Thread Brian Candler
You can't take the address of an arbitrary value or expression, although you can for composite literals which is why &struct{}{} is OK. https://golang.org/ref/spec#Address_operators -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe

Re: [go-nuts] how to declare type as interface{}

2020-09-03 Thread 'Axel Wagner' via golang-nuts
What's wrong with the first one? The second one doesn't work because there are not interface composite literals. So you need to actually have an interface{} variable to take the address of. The third one seems to work just fine: https://play.golang.org/p/zn2mL69VzPo On Thu, Sep 3, 2020 at 10:32 PM

[go-nuts] Re: how to omit empty array

2020-09-03 Thread Alexander Mills
I was under the impression it wouldn't omit the array if it had zero length, hence my question.. i mean at some point we want an empty array in JSON, so I assume it's included by default On Thursday, September 3, 2020 at 3:35:05 AM UTC-7 nishanth...@gmail.com wrote: > > how do I omit an array

[go-nuts] how to declare type as interface{}

2020-09-03 Thread Alexander Mills
This works: var z interface{} if err := json.NewDecoder(resp.Body).Decode(&z); err != nil { t.Fatal(err) } but this doesn't work: if err := json.NewDecoder(resp.Body).Decode(&interface{}{}); err != nil { t.Fatal(err) } and this doesn't work: if err := json.NewDecoder(resp.Body).Decod

[go-nuts] Re: regexp group multi Replace Pattern

2020-09-03 Thread 'Emilius Omeen' via golang-nuts
thank you четверг, 3 сентября 2020 г., 13:13:59 UTC+3 пользователь Brian Candler написал: > > On Thursday, 3 September 2020 10:15:29 UTC+1, Emilius Omeen wrote: >> >> pkg "regexp" not have function which allow many group replace, only have >> ReplaceAllString >> >> >> > If I just take the examp

Re: [go-nuts] Re: custom type wrapping errors; what am i missing?

2020-09-03 Thread Jake Montgomery
On Wednesday, September 2, 2020 at 2:19:31 PM UTC-4, simon place wrote: > * fmt.Printf(%w) is just to add more text to an error, because errors are > immutable its needed.(unless you have custom error types and are local to > them, then you could just edit their state.) > There is more to fm

[go-nuts] Re: how to omit empty array

2020-09-03 Thread Nishanth Shanmugham
> how do I omit an array on boolField if the array is empty? Do you mean how to omit an empty array's field in the serialized JSON? If so, you can use "omitempty" like you did in the other type. var boolField struct { Must []HasTermOrMatch `json:"must,omitempty"` MustNot []HasTermOrMatch `

[go-nuts] Re: regexp group multi Replace Pattern

2020-09-03 Thread Brian Candler
On Thursday, 3 September 2020 10:15:29 UTC+1, Emilius Omeen wrote: > > pkg "regexp" not have function which allow many group replace, only have > ReplaceAllString > > > If I just take the examples you posted at the start, I can do that with a single ReplaceAllString: https://play.golang.org/p/9h

Re: [go-nuts] Re: [ generics] Moving forward with the generics design draft

2020-09-03 Thread Nishanth Shanmugham
After thinking about this more last evening and reading code in the new style, I've changed my mind. I think my previous feedback was too influenced by the fact that I disliked a new predeclared identifier being introduced, and that the style was different from what I'm used to in TypeScript/Java.

[go-nuts] os.Readdir() & FileInfo proposal by Go team

2020-09-03 Thread Liam
A discussion of changes to os.Readdir() & os.FileInfo and alternatives is underway in https://github.com/golang/go/issues/41188 -- 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, se

[go-nuts] Re: regexp group multi Replace Pattern

2020-09-03 Thread 'Emilius Omeen' via golang-nuts
pkg "regexp" not have function which allow many group replace, only have ReplaceAllString // ReplaceAllString returns a copy of src, replacing matches of the Regexp // with the replacement string repl. Inside repl, $ signs are interpreted as // in Expand, so for instance $1 represents the t

[go-nuts] Workflow and tools for JSON Schema generation

2020-09-03 Thread Johann Höchtl
Hi, I would like to accomplish the following: An existing golang package on github provides a struct definition I am interested in to be used as part of a REST API interface I design 1. I would like to automatically go generate json schema for this struct 2. I would like to incorporate th