[go-nuts] Re: How to lowercase all field names for MarshalJSON and UnmarshalJSON?

2018-03-05 Thread Alex Buchanan
Thanks, that does look helpful, although I'll need to evaluate the tradeoffs of not using the std lib. It's hard to believe a library could be substantially faster than the stdlib without giving something up. On Monday, March 5, 2018 at 9:52:04 PM UTC-8, Tamás Gulácsi wrote: > > You can try git

Re: [go-nuts] Re: confusing differences in reflect Type knowledge for a receiver vs. an argument

2018-03-05 Thread Randall O'Reilly
On Mar 5, 2018, at 10:32 PM, Ian Lance Taylor wrote: > > Go doesn't have anything like inheritance in C++. What you are > calling the "true underlying type" simply doesn't exist in Go. Go has > embedded fields, and methods of embedded fields are promoted to become > methods of the outer type in

[go-nuts] Re: How to lowercase all field names for MarshalJSON and UnmarshalJSON?

2018-03-05 Thread Tamás Gulácsi
You can try github.com/json-iterator/go, it allows several naming strategies (https://github.com/json-iterator/go/blob/master/extra/naming_strategy.go#L9), even custom ones. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from th

Re: [go-nuts] Re: confusing differences in reflect Type knowledge for a receiver vs. an argument

2018-03-05 Thread Ian Lance Taylor
On Mon, Mar 5, 2018 at 8:08 PM, Randall O'Reilly wrote: > Thank you for that clarification of what is happening under the hood. > > Nevertheless, I do think there are many cases where it would be very valuable > to have access through reflect of the true underlying type of the receiver > struct.

[go-nuts] Re: Go Games

2018-03-05 Thread Fino
on client side, most of the developer team will use Unity or Unreal engine to save time, so it working this way, choose the commercial tool&library are more critical than choose language itself, BR fino -- You received this message because you are subscribed to the Google Groups "golang-

[go-nuts] Re: How to lowercase all field names for MarshalJSON and UnmarshalJSON?

2018-03-05 Thread Alex Buchanan
I'm bummed there still isn't a good solution for this. It seems like such an easy and extremely common thing. In a decade of webdev, I've possibly never seen a JSON API with Golang style UpperCamelCase keys. Is there a solution to this that I'm missing? Here's one project I'm working on where

Re: [go-nuts] Re: confusing differences in reflect Type knowledge for a receiver vs. an argument

2018-03-05 Thread Randall O'Reilly
Thank you for that clarification of what is happening under the hood. Nevertheless, I do think there are many cases where it would be very valuable to have access through reflect of the true underlying type of the receiver struct. This is evident in that stack overflow question, the *JSON code,

[go-nuts] Re: Gift wrap errors or not?

2018-03-05 Thread adam.azarchs via golang-nuts
Errors in Go aren't really used the same was as exceptions in other languages, and that's a good thing! Most of the time, all you care about is whether the error is non-nil or not. Occasionally you care about the specific type of error, in which case the package emitting the error should defi

Re: [go-nuts] Memory copy on return statement (copy elision)

2018-03-05 Thread Bruno Novais
Ian, good to know that in general you believe that the returned struct will be allocated in the caller. I do think that too, so it's good to know that I'm not thinking too much outside the box. Anyway, out of curiosity I will read more about the flavors of compilers avaliable to use with Go. To b

Re: [go-nuts] Memory copy on return statement (copy elision)

2018-03-05 Thread Bruno Novais
Andrey, Thank you for your help!! I've been analysing the output of my code, and it seems that me and the compiler are "thinking" the same way. I saw this options when I started learning Go, but I didn't realize it could help me like that. I will read more about escape analysis, thanks for pointi

Re: [go-nuts] How to get an alias in a type alias ???

2018-03-05 Thread He Liu
Thank you, I understand 在 2018年3月6日星期二 UTC+8上午2:51:39,Ian Lance Taylor写道: > > On Mon, Mar 5, 2018 at 1:35 AM, He Liu > wrote: > > > > package main > > > > > > import ( > > > > "log" > > > > "reflect" > > > > ) > > > > > > type AAA = int > > > > > > func main() { > > > > var a A

Re: [go-nuts] My views on Go and why it's better than Scripting

2018-03-05 Thread dorival . pedroso
Awesome! I'll read the paper too. Thanks! On Monday, March 5, 2018 at 5:31:06 PM UTC-8, kortschak wrote: > > This was essentially my thinking in choosing Go to write my > bioinformatics library in - mainly because much of our code will be > written and maintained by students, but we want goo

Re: [go-nuts] My views on Go and why it's better than Scripting

2018-03-05 Thread Dan Kortschak
This was essentially my thinking in choosing Go to write my bioinformatics library in - mainly because much of our code will be written and maintained by students, but we want good performance as well. Some of my thought about this are in this paper https://www.biorxiv.org /content/early/2014/05/1

[go-nuts] Re: best practices of client middleware

2018-03-05 Thread Bojan Delić
As far as I am aware, there is very little information about best practices regarding client side middlewares. I though that having such support is neat idea and I have implemented something (that I use for some time now, though still in beta) that you might find useful for your use case. I ha

[go-nuts] Re: Why gc compiler treat slice and custom type differently in garbage collection?

2018-03-05 Thread 'Keith Randall' via golang-nuts
This ideally shouldn't happen. For some reason the compiler is keeping t.y alive across the printMemStat calls, even when it only needs to keep t.x alive. I've opened an issue https://github.com/golang/go/issues/24263 On Monday, March 5, 2018 at 8:08:59 AM UTC-8, di...@veryhaha.com wrote: > > >

[go-nuts] Re: $PATH error.

2018-03-05 Thread Danilo Paes
Dave, Many thanks! Now works fine :) Em segunda-feira, 5 de março de 2018 02:43:19 UTC-3, Dave Cheney escreveu: > > Under the hood go get shells out to git to fetch source code. You need to > install git. -- You received this message because you are subscribed to the Google Groups "golang-n

[go-nuts] Re: Compare values in a for loop that ranges over string array of array

2018-03-05 Thread Ignacio Gómez
Hi, Ashish. If you have a map[string]int (or int 64, float 64, etc.) "m", doing m[key] += value is equivalent to this: m[key] = m[key] + value. Thus, on each iteration we sum the value at dataarray[j][1] (which you stored at sumFloat) to the current value of sums[dataarray[j][0]] (on first

[go-nuts] Re: Compare values in a for loop that ranges over string array of array

2018-03-05 Thread timilsina . ashish . 03
Hi Ignacio, This is excellent, works perfectly. Thank you so much. I will try to do my research but just out of curiosity and make sure I understand the code, what does this line do? I also don't have proper understanding of golang maps sums[dataarray[j][0]] += sumFloat So 'sum' map is takin

[go-nuts] Re: Array in Structs

2018-03-05 Thread Krzysztof Kowalczyk
A an array in JSON maps to a slice of a given type in Go i.e. []*Foo, where Foo is a struct describing the type of array element. You can read up more on JSON mappings: https://www.programming-books.io/essential/go/a-994-json You can use https://mholt.github.io/json-to-go/ which is a tool where

[go-nuts] Re: confusing differences in reflect Type knowledge for a receiver vs. an argument

2018-03-05 Thread Krzysztof Kowalczyk
(in *Inner) InFunc() can't possibly say `in` is Outer. This piece of code: var := Outer{} val.InFunc() Is really: val := Outer{} var tmpInner *Inner = &(val.Inner) tmpInner.InFunc() What is passed to InFunc is a pointer to Inner struct embedded inside Outer struct, not a pointer to Outer stru

[go-nuts] Does HTTP/2 Push() send PUSH_PROMISE and data together?

2018-03-05 Thread Eduard Urbach
I have a question regarding the HTTP/2 Pusher interface and how it handles PUSH_PROMISE and the data transmission. >From the comments in the interface code: // Handlers that wish to push URL X should call Push before sending any // data that may trigger a request for URL X. This avoids a race wh

Re: [go-nuts] osx 10.12 all.bash weirdness with os/signal tests

2018-03-05 Thread andrey mirtchovski
Thanks. This will give me a chance to check the new GitHub PR process: https://github.com/golang/go/pull/24255 On Mon, Mar 5, 2018 at 11:40 AM, Ian Lance Taylor wrote: > On Mon, Mar 5, 2018 at 10:10 AM, andrey mirtchovski > wrote: >> >> I finally found some time to work on this and I think I fig

[go-nuts] Re: Compare values in a for loop that ranges over string array of array

2018-03-05 Thread Ignacio Gómez
You can use a map to keep track of a letters sum. Here's your example slightly modified (it uses float64 as you were using that): https://play.golang.org/p/98L9fDXSN_A El lunes, 5 de marzo de 2018, 15:28:54 (UTC-3), Ashish Timilsina escribió: > > Hi, > > I have an array of array string ([][]stri

Re: [go-nuts] How to get an alias in a type alias ???

2018-03-05 Thread Ian Lance Taylor
On Mon, Mar 5, 2018 at 1:35 AM, He Liu wrote: > > package main > > > import ( > > "log" > > "reflect" > > ) > > > type AAA = int > > > func main() { > > var a AAA = 5 > > x := reflect.TypeOf(a) > > log.Println(x.Name()) > > // print int > > } > > > How to get AAA ??? You can't. A type alias is j

Re: [go-nuts] osx 10.12 all.bash weirdness with os/signal tests

2018-03-05 Thread Ian Lance Taylor
On Mon, Mar 5, 2018 at 10:10 AM, andrey mirtchovski wrote: > > I finally found some time to work on this and I think I figured out > why it fails. I run a very large history file (my HISTSIZE is set to > 10) and on this particular machine I'm at the limit. This causes > the os/signal test to r

Re: [go-nuts] Re: Need help to figure out how to convert user.Current() to string.

2018-03-05 Thread andrey mirtchovski
> var testuser string = string(user.Username) you don't need the conversion. user.Username is already a string. -- 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

[go-nuts] Re: Need help to figure out how to convert user.Current() to string.

2018-03-05 Thread john . mizell
I figured out this issue. I was calling the struct and needed to call one specific element of the struct. Then I assign it to a string. user, err := user.Current() if err != nil { log.Fatal(err) } var testuser string = string(user.Username) if testuser == "root" || tes

Re: [go-nuts] Need help to figure out how to convert user.Current() to string.

2018-03-05 Thread andrey mirtchovski
You have a variable of type *user.User. The documentation (https://golang.org/pkg/os/user/#User) says there is a field on that type called "Username". To get the username of a user you should therefore use username.Username (but that's too stuttery, perhaps "u, err := user.Current()" and then use u

Re: [go-nuts] High precision timer data?

2018-03-05 Thread Frederic Landais
Hello, have you considered using time.NewTicker ? Check the best answer of https://stackoverflow.com/questions/16466320/is-there-a-way-to-do-repetitive-tasks-at-intervals-in-golang for an example Frederic -- You received this message because you are

[go-nuts] Re: Go Games

2018-03-05 Thread nicolas_boiteux via golang-nuts
Hi Currently competiting in botters of the galaxy game challenge https://www.codingame.com/contests/botters-of-the-galaxy works as other langage.You must now that a part of game development is now build directly in integration tools as unity, cry engine, proprietary tools that already have the

[go-nuts] Array in Structs

2018-03-05 Thread pratiktayshete1221
I have a collection in MongoDB in which there is an array of documents for one value. How can I represent this collection in MongoDB in the form of struct in GO. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group an

[go-nuts] Compare values in a for loop that ranges over string array of array

2018-03-05 Thread timilsina . ashish . 03
Hi, I have an array of array string ([][]string{}). I am looping through them and trying to sum the second value of the arrays based on the first value. For example: a := []string{"a", "1"} a1 := []string{"a", "2"} a2 := []string{"a", "3"} b := []string{"b", "4"} b1 := []string{"b", "1"}

[go-nuts] Re: Gift wrap errors or not?

2018-03-05 Thread Stratos Neiros
The way I see it, the current best practice is to treat errors as values and program with them. - https://blog.golang.org/error-handling-and-go - https://blog.golang.org/errors-are-values - https://www.youtube.com/watch?v=PAAkCSZUG1c&t=16m13s - https://commandcenter.blogspot.com/2

[go-nuts] Need help to figure out how to convert user.Current() to string.

2018-03-05 Thread john . mizell
Here is the the program package main import ( "fmt" "log" "os/user" ) func main() { username, err := user.Current() if err != nil { log.Fatal(err) } if username != "root" || username != "someuser" { fmt.Println("You are currentl

[go-nuts] How to get an alias in a type alias ???

2018-03-05 Thread He Liu
package main import ( "log" "reflect" ) type AAA = int func main() { var a AAA = 5 x := reflect.TypeOf(a) log.Println(x.Name()) // print int } How to get AAA ??? -- You received this message because you are subscribed to the Google

[go-nuts] confusing differences in reflect Type knowledge for a receiver vs. an argument

2018-03-05 Thread Randall O'Reilly
I'm new to golang, and am hitting some seemingly strange territory that I couldn't find much prior discussion about -- here's one example of the phenomenon in question: https://stackoverflow.com/questions/22153269/how-to-reflect-fields-of-containing-struct-from-a-method-of-the-embedded-struct/49

Re: [go-nuts] osx 10.12 all.bash weirdness with os/signal tests

2018-03-05 Thread andrey mirtchovski
Hi, I finally found some time to work on this and I think I figured out why it fails. I run a very large history file (my HISTSIZE is set to 10) and on this particular machine I'm at the limit. This causes the os/signal test to run an average 6-7 seconds. The test timeout as shown in my second

[go-nuts] Re: My views on Go and why it's better than Scripting

2018-03-05 Thread dorival . pedroso
Great feedback, Matt and Wang. Thanks and Cheers! On Monday, March 5, 2018 at 2:13:29 AM UTC-8, Wang Sheng wrote: > > I am c++/C expert, I like because it is easier than C++ and more powerful > and flexible than C > with Golang , you would not need consider create/destroy/monitor pthread >

[go-nuts] Re: constructors vs lazy initialization

2018-03-05 Thread Chris Hopkins
I would say Lazy initialisation should build code that is more robust - I can think of few applications where that is not worth the price. So as a rule I agree Lazy is a good place to start unless you have a good reason not to. I also understood it was more idiomatic. In terms of reading/debugg

[go-nuts] Re: Why gc compiler treat slice and custom type differently in garbage collection?

2018-03-05 Thread digg
On Monday, March 5, 2018 at 10:34:35 AM UTC-5, Volker Dobler wrote: > > Your two programs are not the same. > Try fmt.Println(bs[0]) instead of len(bs) in the > first one. > > V. > Yes, you are right. They are different. Their behaviors should be compile dependent. > > On Monday, 5 March

[go-nuts] Re: Why gc compiler treat slice and custom type differently in garbage collection?

2018-03-05 Thread Volker Dobler
Your two programs are not the same. Try fmt.Println(bs[0]) instead of len(bs) in the first one. V. On Monday, 5 March 2018 16:05:05 UTC+1, di...@veryhaha.com wrote: > > Slice: > > package main > > import "fmt" > import "runtime" > > func printMemStat(gcFirstly bool) { > if gcFirstly { >

[go-nuts] Why gc compiler treat slice and custom type differently in garbage collection?

2018-03-05 Thread digg
Slice: package main import "fmt" import "runtime" func printMemStat(gcFirstly bool) { if gcFirstly { runtime.GC() } var stat runtime.MemStats runtime.ReadMemStats(&stat) println(stat.Alloc) } func main() { bs := make([]int, 100) printMemStat(false) /

[go-nuts] best practices of client middleware

2018-03-05 Thread Eyal Posener
Hi I want to implement a client middleware - for example: sign the request body and add the signature as an HTTP header. I thought that the best way to do it is to implement a RoundTripper interface which up on request, calculate the signature, ad

Re: [go-nuts] w, x += i, i+i

2018-03-05 Thread Jan Mercl
On Mon, Mar 5, 2018 at 1:42 PM wrote: > .. isn't the EBNF at https://golang.org/ref/spec#Assignments currently wrong - in that it allows what is currently disallowed The EBNF is just a part of the specification that defines the grammar. Other parts of the specification often restrict what's all

Re: [go-nuts] w, x += i, i+i

2018-03-05 Thread xiofen77
On Thursday, 1 March 2018 01:45:44 UTC, Ian Lance Taylor wrote: > > It was done on purpose, which is to say that there never seemed to be > a reason to add it. It rarely comes up in practice, and it's not > obvious whether it's better to support `v1, v2 :+ inc1, inc2` or `v1, > v2 += inc` (wh

[go-nuts] Re: My views on Go and why it's better than Scripting

2018-03-05 Thread Wang Sheng
I am c++/C expert, I like because it is easier than C++ and more powerful and flexible than C with Golang , you would not need consider create/destroy/monitor pthread , crazy pointer is not problem also . as far as I know , most of golanger is original user of C/C++ 在 2018年3月3日星期六 UTC+

Re: [go-nuts] Channels vs Actors

2018-03-05 Thread Jesper Louis Andersen
To add to Bakul's description: A key difference in an actor-inspired model compared to a CSP-inspired one is that identity is subtly different. In Go, channels have identity and can be referenced. They can have multiple readers and writers. In Erlang, it is processes who has identity and you can s