[go-nuts] Re: json unmarshalling troubles
No, whoever designed the schema of this API has lost their marbles, (or lacks any kind of consideration for the unfortunate souls who need to use this API). Unmarshalling a value whose type is not fixed is a pain in Go. But handling a value of unknown type will be a headache in any language. On Wednesday, 2 June 2021 at 19:55:40 UTC+1 rob...@glonek.co.uk wrote: > I think I'm loosing my marbles. Nevermind what I said. > > On Wednesday, 2 June 2021 at 16:22:34 UTC+1 Brian Candler wrote: > >> > If you try using switch value.(type) instead of using reflect, bool >> will be reported as int, fyi, so using reflect here. >> >> Could you explain that a bit further please? A type switch seems to work >> OK for me, with no reflect. >> https://play.golang.org/p/TBH5zKYnG4G >> >> -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3b039ea4-7c16-4472-9bfc-4a626bf82478n%40googlegroups.com.
Re: [go-nuts] LD_LIBRARY_PATH is required when bootstrapping Go with gccgo (non-standard location)
On Sun, May 23, 2021 at 3:57 AM Bagas Sanjaya wrote: > > Today I have built GCC 11.1.0 for use to bootstrap Go using gccgo. > I installed GCC to non-standard path, that is inside my home directory > (~/.ct-ng/tools/gcc-11.1.10) (sorry for typo when building GCC, I > meant gcc-11.1.0). > > `gcc -v` gave: > > > COLLECT_GCC=/home/bagas/.ct-ng/tools/gcc-11.1.10/bin/gcc > > COLLECT_LTO_WRAPPER=/home/bagas/.ct-ng/tools/gcc-11.1.10/libexec/gcc/x86_64-pc-linux-gnu/11.1.0/lto-wrapper > > Target: x86_64-pc-linux-gnu > > Configured with: ../configure --prefix=/home/bagas/.ct-ng/tools/gcc-11.1.10 > > --disable-multilib --enable-languages=c,c++,go --enable-default-pie > > Thread model: posix > > Supported LTO compression algorithms: zlib > > gcc version 11.1.0 (GCC) > > Then I bootstrapped Go using gccgo from GCC 11.1.0. Because I installed > GCC to non-standard path, I had to add LD_LIBRARY_PATH when invoking > `make.bash`: > > ``` > $ LD_LIBRARY_PATH=/home/bagas/.ct-ng/tools/gcc-11.1.10/lib64 \ >GOROOT_BOOTSTRAP=/home/bagas/.ct-ng/tools/gcc-11.1.10 \ >./make.bash > ``` > Bootstrapping process took about thirty minutes to complete. > > Note that LD_LIBRARY_PATH was required because `go` command from > gccgo was dynamically linked with supporting library `libgo.so`, > and the library was installed to non-standard path. > > However, on official installation from source instructions [1], gccgo > was assumed to be installed from distribution's package manager, > and thus was installed to standard path (/usr), so LD_LIBRARY_PATH > isn't required. > > Maybe the documentation should be updated to take into account > gccgo installations that are installed on non-standard paths > like my case above. Thanks, but I think it's implied that if you want to use gccgo to bootstrap Go, then the gccgo installation has to work. I don't think we want to get into all possible details of how to get your gccgo installation to work. LD_LIBRARY_PATH is just one of many different possible issues. Ian -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUPbavzAnPV0B6yVe1SrFY%2BuRfOKdAHOJOE%2BUX2z8_S9A%40mail.gmail.com.
[go-nuts] Re: json unmarshalling troubles
I think I'm loosing my marbles. Nevermind what I said. On Wednesday, 2 June 2021 at 16:22:34 UTC+1 Brian Candler wrote: > > If you try using switch value.(type) instead of using reflect, bool will > be reported as int, fyi, so using reflect here. > > Could you explain that a bit further please? A type switch seems to work > OK for me, with no reflect. > https://play.golang.org/p/TBH5zKYnG4G > > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/75e2143d-b653-4937-bc3b-c5bb213b6f36n%40googlegroups.com.
[go-nuts] Re: Hiring - Remote / Denver (GoLang)
Can you sponsor US visa? I can consider base salary negotiation if that is possible. On Wednesday, 2 June 2021 at 23:21:35 UTC+5:30 wth...@fluidtruck.com wrote: > Hi everyone, > > I'm the Head of Technical Recruiting for Fluid Truck, and we're hiring > multiple GoLang backend engineers currently. > > This is a full-time role, preferably in Denver but can be remote (US > based), offering very competitive base salaries + stock options, 100% > medical benefits coverage, unlimited PTO, etc. > > If anyone is interested, please let me know! > > Thank you! > -Will > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/371e792e-20fb-4d68-9d98-7f1855c065ffn%40googlegroups.com.
[go-nuts] Hiring - Remote / Denver (GoLang)
Hi everyone, I'm the Head of Technical Recruiting for Fluid Truck, and we're hiring multiple GoLang backend engineers currently. This is a full-time role, preferably in Denver but can be remote (US based), offering very competitive base salaries + stock options, 100% medical benefits coverage, unlimited PTO, etc. If anyone is interested, please let me know! Thank you! -Will -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c679f6b0-d4c1-4f4a-a97f-17976564519an%40googlegroups.com.
[go-nuts] Re: embedding files in tests
"it seems a bug ... it should" Why? Why perform unnecessary disk directory I/O for a build to discover which files satisfy the patterns for a test? Go tools are expected to be fast. Peter On Wednesday, June 2, 2021 at 5:49:41 AM UTC-4 manlio@gmail.com wrote: > Here is an example: https://play.golang.org/p/ElnTtxHnF5I > > The output of `go list -json ./pkg` only reports `TestEmbedPatterns`. > The output of `go list -json -test ./pkg` reports TestEmbedFiles for the > pkg package (it seems a bug, since it should also be reported without the > -test flag). > The TestEmbedFiles is also present in the generated `pkg.test` package and > the pkg [pkg.test] package. > > Thanks > Manlio > > > On Wednesday, June 2, 2021 at 4:23:32 AM UTC+2 nikolay.d...@gmail.com > wrote: > >> I think the question is about `go:embed` directive in `_test.go` files >> will be included in builds of non-test packages, right? >> >> Don't know for sure, but I think: >> - a) if you have `mypkg_test.go` and in it `package mypkg_test` then >> `go:embed` will not get to your non test build as the package is different >> - b) if you have `mypkg_test.go` and in it `pakcage mypkg` then... less >> clear. As above referenced in original docs `_test.go` will be excluded >> from non test build regardless of package. >> >> My personal take, is to go:embed only in case a). >> >> Cheers, >> On Wednesday, June 2, 2021 at 8:09:20 AM UTC+8 peterGo wrote: >> >>> On Tuesday, June 1, 2021 at 9:17:11 AM UTC-4 manlio@gmail.com wrote: >>> When a file is embedded in a test file, will the file be embedded only in the test binary? The documentation says nothing about this case, but the data from go list seems to confirm that the file is only embedded in the test binary. Thanks Manlio >>> >>> The documentation seems clear to me. >>> >>> Package testing >>> https://golang.org/pkg/testing/ >>> >>> To write a new test suite, create a file whose name ends _test.go that >>> contains the TestXxx functions as described here. Put the file in the same >>> package as the one being tested. The file will be excluded from regular >>> package builds but will be included when the "go test" command is run. >>> >>> Peter >>> >> -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/30b171c0-e3c0-4ff5-a279-fd83b8ed81c9n%40googlegroups.com.
[go-nuts] Re: json unmarshalling troubles
> If you try using switch value.(type) instead of using reflect, bool will be reported as int, fyi, so using reflect here. Could you explain that a bit further please? A type switch seems to work OK for me, with no reflect. https://play.golang.org/p/TBH5zKYnG4G -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/1c8fc67f-55ac-42e9-be8c-057695eea29fn%40googlegroups.com.
[go-nuts] Re: json unmarshalling troubles
Here's a quick-glued reflect example. https://play.golang.org/p/blpmIVKhuc4 If you try using switch value.(type) instead of using reflect, bool will be reported as int, fyi, so using reflect here. On Wednesday, 2 June 2021 at 16:02:36 UTC+1 Robert Glonek wrote: > The json is not very strict, while go is. It would be good if the json > struct could potentially be strictly of same type all over the place. > Implementing parser for this json in any language will be a bit of a pain > with some try/except... > > If you really need to do so, you would need to have the Value as type > interface{} and then use Reflect to find out if it's a struct, or bool or > int and cast it accordingly to it's type. But really, would be easier if > the value field was uniform, no matter the language used. > > So in other words: > 1. unmarshal using interface > 2. reflect to find type > 3. cast to a new variable for the select type > > type Autogenerated struct { > AllParameters []struct { >Priority int `json:"priority"` >CreatedAt string `json:"created_at"` >UpdatedAt string `json:"updated_at"` >ID int `json:"id"` Name string `json:"name"` >ParameterType string `json:"parameter_type"` >Value interface{} `json:"value"` >valueAsInt int >valueAsBool bool >valueAsMap map[string]interface{} > } `json:"all_parameters"` > } > > Example here: > https://play.golang.org/p/PWHz_g_jabz > > > On Wednesday, 2 June 2021 at 14:15:50 UTC+1 natxo@gmail.com wrote: > >> hi, >> >> I have this json back from an api: >> >> { >> "all_parameters": [{ >> "priority": 60, >> "created_at": "2021-06-02 12:15:13 UTC", >> "updated_at": "2021-06-02 12:15:13 UTC", >> "id": 28, >> "name": "network_interface_mapping", >> "parameter_type": "yaml", >> "value": { >> "interface1": "eno1", >> "interface2": "eno2", >> "interface3": "eno3", >> "interface4": "eno4" >> } >> }, >> { >> "priority": 60, >> "created_at": "2021-06-02 12:15:13 UTC", >> "updated_at": "2021-06-02 12:15:13 UTC", >> "id": 27, >> "name": "component_1", >> "parameter_type": "boolean", >> "value": true >> }, >> { >> "priority": 50, >> "created_at": "2021-03-19 14:34:26 UTC", >> "updated_at": "2021-03-19 14:34:26 UTC", >> "id": 15, >> "name": "url1", >> "parameter_type": "string", >> "value": "http://www.example.org/1"; >> } >> ] >> } >> >> If I use the json2go service, then it simplifies the values like this: >> >> >> type Autogenerated struct { >> AllParameters []struct { >>Priority int `json:"priority"` >>CreatedAt string `json:"created_at"` >>UpdatedAt string `json:"updated_at"` >>ID int `json:"id"` Name string `json:"name"` >>ParameterType string `json:"parameter_type"` >>Value struct { >> Interface1 string `json:"interface1"` >> Interface2 string `json:"interface2"` >> Interface3 string `json:"interface3"` >> Interface4 string `json:"interface4"` >> } `json:"value"` >> } `json:"all_parameters"` >> } >> >> so the value struct has the values of just the first parameter, in fact. >> The other parameters have different values, could be a boolean or a string. >> >> How can I use this in my client script? Unmarhalling into this struct >> type gives me obviously errors >> >> Error: json: cannot unmarshal object into Go struct field >> .all_parameters.value of type string >> >> Thanks in advance for your input. >> >> Regards, >> Natxo >> > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/500f7306-920a-4b81-9de0-20958d884d36n%40googlegroups.com.
[go-nuts] Re: json unmarshalling troubles
The json is not very strict, while go is. It would be good if the json struct could potentially be strictly of same type all over the place. Implementing parser for this json in any language will be a bit of a pain with some try/except... If you really need to do so, you would need to have the Value as type interface{} and then use Reflect to find out if it's a struct, or bool or int and cast it accordingly to it's type. But really, would be easier if the value field was uniform, no matter the language used. So in other words: 1. unmarshal using interface 2. reflect to find type 3. cast to a new variable for the select type type Autogenerated struct { AllParameters []struct { Priority int `json:"priority"` CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` ID int `json:"id"` Name string `json:"name"` ParameterType string `json:"parameter_type"` Value interface{} `json:"value"` valueAsInt int valueAsBool bool valueAsMap map[string]interface{} } `json:"all_parameters"` } Example here: https://play.golang.org/p/PWHz_g_jabz On Wednesday, 2 June 2021 at 14:15:50 UTC+1 natxo@gmail.com wrote: > hi, > > I have this json back from an api: > > { > "all_parameters": [{ > "priority": 60, > "created_at": "2021-06-02 12:15:13 UTC", > "updated_at": "2021-06-02 12:15:13 UTC", > "id": 28, > "name": "network_interface_mapping", > "parameter_type": "yaml", > "value": { > "interface1": "eno1", > "interface2": "eno2", > "interface3": "eno3", > "interface4": "eno4" > } > }, > { > "priority": 60, > "created_at": "2021-06-02 12:15:13 UTC", > "updated_at": "2021-06-02 12:15:13 UTC", > "id": 27, > "name": "component_1", > "parameter_type": "boolean", > "value": true > }, > { > "priority": 50, > "created_at": "2021-03-19 14:34:26 UTC", > "updated_at": "2021-03-19 14:34:26 UTC", > "id": 15, > "name": "url1", > "parameter_type": "string", > "value": "http://www.example.org/1"; > } > ] > } > > If I use the json2go service, then it simplifies the values like this: > > > type Autogenerated struct { > AllParameters []struct { >Priority int `json:"priority"` >CreatedAt string `json:"created_at"` >UpdatedAt string `json:"updated_at"` >ID int `json:"id"` Name string `json:"name"` >ParameterType string `json:"parameter_type"` >Value struct { > Interface1 string `json:"interface1"` > Interface2 string `json:"interface2"` > Interface3 string `json:"interface3"` > Interface4 string `json:"interface4"` > } `json:"value"` > } `json:"all_parameters"` > } > > so the value struct has the values of just the first parameter, in fact. > The other parameters have different values, could be a boolean or a string. > > How can I use this in my client script? Unmarhalling into this struct type > gives me obviously errors > > Error: json: cannot unmarshal object into Go struct field > .all_parameters.value of type string > > Thanks in advance for your input. > > Regards, > Natxo > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/e8e5d860-307c-4635-9629-c8fd43f8cff8n%40googlegroups.com.
[go-nuts] json unmarshalling troubles
hi, I have this json back from an api: { "all_parameters": [{ "priority": 60, "created_at": "2021-06-02 12:15:13 UTC", "updated_at": "2021-06-02 12:15:13 UTC", "id": 28, "name": "network_interface_mapping", "parameter_type": "yaml", "value": { "interface1": "eno1", "interface2": "eno2", "interface3": "eno3", "interface4": "eno4" } }, { "priority": 60, "created_at": "2021-06-02 12:15:13 UTC", "updated_at": "2021-06-02 12:15:13 UTC", "id": 27, "name": "component_1", "parameter_type": "boolean", "value": true }, { "priority": 50, "created_at": "2021-03-19 14:34:26 UTC", "updated_at": "2021-03-19 14:34:26 UTC", "id": 15, "name": "url1", "parameter_type": "string", "value": "http://www.example.org/1"; } ] } If I use the json2go service, then it simplifies the values like this: type Autogenerated struct { AllParameters []struct { Priority int `json:"priority"` CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` ID int `json:"id"` Name string `json:"name"` ParameterType string `json:"parameter_type"` Value struct { Interface1 string `json:"interface1"` Interface2 string `json:"interface2"` Interface3 string `json:"interface3"` Interface4 string `json:"interface4"` } `json:"value"` } `json:"all_parameters"` } so the value struct has the values of just the first parameter, in fact. The other parameters have different values, could be a boolean or a string. How can I use this in my client script? Unmarhalling into this struct type gives me obviously errors Error: json: cannot unmarshal object into Go struct field .all_parameters.value of type string Thanks in advance for your input. Regards, Natxo -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/fd0e6f0a-06b0-44e6-a699-fc8f0b626039n%40googlegroups.com.
[go-nuts] Re: How is golang web applications for seo
On Tuesday, 1 June 2021 at 18:39:48 UTC+2 beeke...@gmail.com wrote: > How are golang web applications on a scale of 1 to 10 for seo rankings? They range from 1 to 10 depending on how they are implemented. SEO ranking is not influenced by the language you write your "web application" in. V. -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/0cc4f131-0288-4930-9f67-153ee4a19271n%40googlegroups.com.
[go-nuts] Re: embedding files in tests
Here is an example: https://play.golang.org/p/ElnTtxHnF5I The output of `go list -json ./pkg` only reports `TestEmbedPatterns`. The output of `go list -json -test ./pkg` reports TestEmbedFiles for the pkg package (it seems a bug, since it should also be reported without the -test flag). The TestEmbedFiles is also present in the generated `pkg.test` package and the pkg [pkg.test] package. Thanks Manlio On Wednesday, June 2, 2021 at 4:23:32 AM UTC+2 nikolay.d...@gmail.com wrote: > I think the question is about `go:embed` directive in `_test.go` files > will be included in builds of non-test packages, right? > > Don't know for sure, but I think: > - a) if you have `mypkg_test.go` and in it `package mypkg_test` then > `go:embed` will not get to your non test build as the package is different > - b) if you have `mypkg_test.go` and in it `pakcage mypkg` then... less > clear. As above referenced in original docs `_test.go` will be excluded > from non test build regardless of package. > > My personal take, is to go:embed only in case a). > > Cheers, > On Wednesday, June 2, 2021 at 8:09:20 AM UTC+8 peterGo wrote: > >> On Tuesday, June 1, 2021 at 9:17:11 AM UTC-4 manlio@gmail.com wrote: >> >>> When a file is embedded in a test file, will the file be embedded only >>> in the test binary? >>> The documentation says nothing about this case, but the data from go >>> list seems to confirm that the file is only embedded in the test binary. >>> >>> Thanks >>> Manlio >>> >> >> The documentation seems clear to me. >> >> Package testing >> https://golang.org/pkg/testing/ >> >> To write a new test suite, create a file whose name ends _test.go that >> contains the TestXxx functions as described here. Put the file in the same >> package as the one being tested. The file will be excluded from regular >> package builds but will be included when the "go test" command is run. >> >> Peter >> > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d615df39-fb54-4012-8941-edcb1440862cn%40googlegroups.com.
[go-nuts] Re: The last line makes the variable y escape. But should it?
I think I got the reason. It is because the compiler is not aware of the println will not change the value of y. And it is hard or expensive for the compiler to understand the channel synchronization. If the println function changes y, then y must be allocated on heap. On Tuesday, June 1, 2021 at 9:51:50 AM UTC-4 tapi...@gmail.com wrote: > > package main > > func newIntPtr(n int) *int { > return &n > } > > func main() { > x := newIntPtr(3) > y := newIntPtr(5) > c := make(chan bool) > go func() { > *y++ > close(c) > }() > <-c > println(*x, *y) > println(&x) > //println(&y) // This line makes y escape. > } > > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/6829f596-8801-4494-a160-de379f33aaf5n%40googlegroups.com.
Re: [go-nuts] Re: The last line makes the variable y escape. But should it?
On Wed, Jun 2, 2021 at 8:48 AM cheng dong wrote: > `y` escape because the println use interface{} as its parameter, println is a bootstrap function that the compiler knows about by itself. It's formal/pseudo signature does not use 'interface{}'. I haven't checked the actual implementation, but I guess, especially in the early days of the compiler, implementing println without using `interface{}' would be simpler and make more sense. I would just special case at compile time the few supported types to produce calls of different runtime implementations. In any case, using println when studying the escape analyzer is an unfortunate choice because println is kind of a special black box that can differ substantially between compilers and/or versions. -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAA40n-X-JqT%3DaQ_FnfO3tGBqtAjGA%2BBf76q7Ni_6NrzJbC84aQ%40mail.gmail.com.