[go-nuts] Re: generics: how to repeat type in parameters

2021-10-09 Thread Sathish VJ
Makes sense. Thank you Brian. On Saturday, 9 October 2021 at 23:12:20 UTC+5:30 Brian Candler wrote: > Alternatively, your function can be generic over two different types: > https://go2goplay.golang.org/p/WVVZM-Q_P3t > > In this trivial example though, I still think interface values are what

[go-nuts] generics: how to repeat type in parameters

2021-10-09 Thread Sathish VJ
How can I repeat the same generics type in the parameters? I'm getting a "does not match inferred type" error for the code below. func Print[T Worker](a T, b T) { fmt.Println(a.Work() + b.Work()) } func main() { c1 := coder{} t1 := tester{} Print(c1, t1) } Compiler

Re: [go-nuts] Assigning byte to string location is not allowed

2020-08-13 Thread Sathish VJ
Why would the design not allow the contents of the string to be changed? I understand that the size and memory allocation for it is immutable. On Thursday, 13 August 2020 at 18:50:10 UTC+5:30 Jan Mercl wrote: > On Thu, Aug 13, 2020 at 3:02 PM Sathish VJ wrote: > > > Why is this

[go-nuts] Re: best way to know executable version without running it

2020-08-13 Thread Sathish VJ
Maybe you are asking how to get build version information into the executable. If yes, then use -ldflags. https://pmcgrath.net/include-version-information-in-golang-app On Thursday, 13 August 2020 at 15:12:36 UTC+5:30 seank...@gmail.com wrote: > go version -m > > On Thursday, August 13,

[go-nuts] Assigning byte to string location is not allowed

2020-08-13 Thread Sathish VJ
Why is this not allowed? s := "hello" s[0] = 'a' // compile error: cannot assign to s[0] https://play.golang.org/p/zyJXwhEeKPo -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails

Re: [go-nuts] can "Run" in play.golang.org automatically include imports and format?

2020-05-30 Thread Sathish VJ
> Is there a reason why play.golang.org needs separate buttons for Run, > Format, and Imports? Is there any reason for or anybody not doing those > automatically? Say someone has issues with their code and pastes it to play.golang.org. You want hitting "run" to say "no module named blah" and

[go-nuts] can "Run" in play.golang.org automatically include imports and format?

2020-05-30 Thread Sathish VJ
Is there a reason why play.golang.org needs separate buttons for Run, Format, and Imports? Is there any reason for or anybody not doing those automatically? Shouldn't Run automatically subsume Format and Imports? Also, it would be good to have a keyboard shortcut to run it. It's not

Re: [go-nuts] Use of NoMethod type for custom marshaling

2019-09-14 Thread Sathish VJ
: > > On Sat Sep 14, 2019 at 1:43 AM Sathish VJ wrote: > > I saw some code where there is a temporary type called *noMethod* > created > > before performing custom marshaling. > > > > What is the purpose of doing this? > > > > type T struct { > &g

[go-nuts] Use of NoMethod type for custom marshaling

2019-09-14 Thread Sathish VJ
I saw some code where there is a temporary type called *noMethod* created before performing custom marshaling. What is the purpose of doing this? type T struct { A int C string } func (t T) MarshalText() (text []byte, err error) { type noMethod T return json.Marshal(noMethod(t)) }

[go-nuts] Re: When doing "type X Y", is it a type alias or type redefinition or type adapter or something else?

2019-08-13 Thread Sathish VJ
ntains > neither. So the main difference between a type alias and > the other two is: The other two do not exist. > > V. > > On Tuesday, 13 August 2019 06:53:20 UTC+2, Sathish VJ wrote: >> >> And what is the difference between each of these: type alias, type >> redefin

[go-nuts] When doing "type X Y", is it a type alias or type redefinition or type adapter or something else?

2019-08-12 Thread Sathish VJ
And what is the difference between each of these: type alias, type redefinition, type adapter. -- 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

[go-nuts] is there any type that cannot be sent on a channel?

2019-06-30 Thread Sathish VJ
I thought I read somewhere that functions cannot be sent on channels. But I tried it out and it can be. Play link: https://play.golang.org/p/OeLpQsNwnCn So, is there anything that cannot be sent on channels? -- You received this message because you are subscribed to the Google Groups

Re: [go-nuts] Using default in select causes a deadlock

2018-10-24 Thread Sathish VJ
Thank you. Would you have an explanation for why it works so differently from using default? On Wednesday, 24 October 2018 22:44:26 UTC+5:30, Burak Serdar wrote: > > You can do this instead: > > https://play.golang.org/p/avMIyYlwxbF > On Wed, Oct 24, 2018 at 11:05 AM Sath

[go-nuts] Using default in select causes a deadlock

2018-10-24 Thread Sathish VJ
This is a program where the receiver is asking the sender to close after receiving 1 value. Using default for the sending (line 34) causes the code to deadlock while even a timeout of a nanosecond causes it to be ok. I don't want to time the sending though. Is there a better option to

Re: [go-nuts] Why doesn't this benchmark test end?

2018-10-22 Thread Sathish VJ
Thank you Ian. On Monday, 22 October 2018 21:46:44 UTC+5:30, Ian Davis wrote: > > > > > On Mon, 22 Oct 2018, at 4:36 PM, Sathish VJ wrote: > > So, I also tried with > *go test -v -bench=. -test.benchtime=0.1s * > and that does complete. > > But is the impl

Re: [go-nuts] Why doesn't this benchmark test end?

2018-10-22 Thread Sathish VJ
t 22, 2018 at 5:21 PM Sathish VJ > wrote: > > I believe it does actually end, it's just the timeout kicks in sooner. > > The testing package attempts to make the benchmark run for at least 1 sec > by default, IINM. Your code has two parts. The measured one is like 1

[go-nuts] Why doesn't this benchmark test end?

2018-10-22 Thread Sathish VJ
Play Link: https://play.golang.org/p/YppC11kwyLz Running this command hangs the program: go test -v -bench=. *"*** Test killed with quit: ran too long (10m0s)."* But if I comment out the stop/start timer, it is fine. I tried both with go1.10 and go1.11. Same result. I have no other file in

Re: [go-nuts] why does go reverse the order of name and type? "i int" vs "int i"

2018-09-19 Thread Sathish VJ
g like this: > > http://c-faq.com/decl/spiral.anderson.html > > On Wed, 2018-09-19 at 22:30 -0700, Sathish VJ wrote: > > I've been asked this question a few times and I haven't been able to > > find > > an answer. Why does go reverse the order of variable >

[go-nuts] why does go reverse the order of name and type? "i int" vs "int i"

2018-09-19 Thread Sathish VJ
I've been asked this question a few times and I haven't been able to find an answer. Why does go reverse the order of variable declaration: "i int" vs "int i" Is there anything in the language design that requires this or was it based on readability/writability or related to the parsing

Re: [go-nuts] "GOPATH" set but "go get" downloads to ~/go

2018-09-11 Thread Sathish VJ
Ok, this might be it for one case. I'll check again tomorrow. On Tue, Sep 11, 2018, 8:55 PM Borman, Paul wrote: > Silly question, but is it exported? You can easily check with the > command: > > env | grep GOPATH > > -Paul > > On Sep 11, 2018, at 9:30 AM, Sath

[go-nuts] Re: "GOPATH" set but "go get" downloads to ~/go

2018-09-11 Thread Sathish VJ
, Sathish VJ wrote: > > I saw this behavior with a couple of Mac machines today and I was unable > to debug it. Just checking to see if it is a known issue. > > Macbook 1: > GOPATH is set to a known location (verified with echo $GOPATH) and it > matches what is shown in

[go-nuts] "GOPATH" set but "go get" downloads to ~/go

2018-09-11 Thread Sathish VJ
I saw this behavior with a couple of Mac machines today and I was unable to debug it. Just checking to see if it is a known issue. Macbook 1: GOPATH is set to a known location (verified with echo $GOPATH) and it matches what is shown in "go env" do "go get github.com/username/pkgname" on

Re: [go-nuts] Re: Long running task in select case

2018-03-19 Thread Sathish VJ
ger than the timeout we'll see that the tasks will be > canceled after timeout >time.Sleep(time.Second * 8) > >// The call of the cancel function has only effect when we slept shorter > then the defined timeout >// if so the single call of the cancel function will send a ca

[go-nuts] Re: Long running task in select case

2018-03-17 Thread Sathish VJ
sive to the quit channel >> (for example, by using a select like you're using in f already). > > > The default select case does it: https://play.golang.org/p/jlfaXu6TZ8L > > Here's another way: https://play.golang.org/p/gEDef3LolAZ > > Matt > > On Friday, March

[go-nuts] Long running task in select case

2018-03-16 Thread Sathish VJ
All the examples I've seen use some kind of ticker to run various cases of a select statement. But how does one run a long running task that is still cancelable? In the example below the quit part is never reached. https://play.golang.org/p/PLGwrUvKaqn (it does not run properly on

[go-nuts] Is there any tutorial or documentation on getting flame graphs with go 1.10?

2018-03-13 Thread Sathish VJ
Trying to figure out profiling and flame graphs on the latest go. And information seems to be lacking. Any pointers to articles that work? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving

[go-nuts] Pass API key to google cloud vision api

2017-12-20 Thread Sathish VJ
I'm trying to make an api call to google vision api using an api key from golang. But I'm getting a 400: bad request, invalid_grant error. What is the right way to make this call? import ( // ... "google.golang.org/api/option" vision "cloud.google.com/go/vision/apiv1"

[go-nuts] Re: go test error: cannot use matchString as type testing.testDeps in argument to testing.MainStart

2017-03-14 Thread Sathish VJ
Aaah, got it. I had updated GOROOT for 1.8 and then hadn't changed it back. sorry for wasting your time. But I found the solution long after I faced it but as soon as I posted it publicly. Figures. On Wednesday, 15 March 2017 01:35:50 UTC+5:30, Sathish VJ wrote: > > Ok, I don't kno

[go-nuts] Re: go test error: cannot use matchString as type testing.testDeps in argument to testing.MainStart

2017-03-14 Thread Sathish VJ
updates other than downloading 1.8 it to a folder and trying a basic hello world with it. On Wednesday, 15 March 2017 01:26:27 UTC+5:30, Sathish VJ wrote: > > I'm trying to run test on a library that I haven't updated since mid Jan > (based on my git log). I know for a fact that I

[go-nuts] go test error: cannot use matchString as type testing.testDeps in argument to testing.MainStart

2017-03-14 Thread Sathish VJ
I'm trying to run test on a library that I haven't updated since mid Jan (based on my git log). I know for a fact that I ran tests on the same project during a demo/workshop in february. I try to run the tests now and am seeing the error below: master ± go test # testmain

[go-nuts] Check if previous value in template range is different

2017-01-04 Thread Sathish VJ
Is there a way to check if the previous value in the template range is different from the current one? type Data struct { Value int32 } var htmlTemplate = `{{range $i, $el := .}} {{$i}}:{{.Value}}: (is it diff from previous value, i.e. data[i-1]) {{end}}` Intended use: to change the color of

Re: [go-nuts] custom json unmarshaling between object or arrays

2016-12-28 Thread Sathish VJ
aah, got it. the case []interface{}: is what I'd not gotten right. Thanks for the detailed examples. On Thursday, 29 December 2016 12:57:54 UTC+5:30, Konstantin Khomoutov wrote: > > On Wed, 28 Dec 2016 21:55:33 -0800 (PST) > Sathish VJ <sath...@gmail.com > wrote: > &g

[go-nuts] custom json unmarshaling between object or arrays

2016-12-28 Thread Sathish VJ
I'm trying to do custom json unmarshaling when there could be an error. In case there is an error, it will have json like: { "error": "err msg"} Else, it could be anything. If it is another json object, then I'm having no issues. But if the incoming data is an array, then it fails. How do I

[go-nuts] list tests without actually running them

2016-12-28 Thread Sathish VJ
Is there a `go test` option that allows one to list the tests that will be run without actually running them? I have a few tests that have side effects (in the initial stages of development) and I want to ensure that those are not accidentally run. -- You received this message because you are

[go-nuts] Re: error when json unmarshaling string to type string

2016-12-15 Thread Sathish VJ
son package encounters an invalid json: struct tag. > > Chris > > On Thursday, December 15, 2016 at 8:32:03 AM UTC-5, Sathish VJ wrote: >> >> I have a struct that maps json of type string to a string. >> S string `json:"s,string"` >> >> When run wi

[go-nuts] Error on play.golang.org?

2016-12-15 Thread Sathish VJ
I'm getting a server error on play.golang.org when I try to share my code. Are others also seeing it? It just says Server error: try again. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving

[go-nuts] godoc does not show from GOPATH/src/vendor

2016-12-09 Thread Sathish VJ
I have my vendor folder like this: $GOPATH/src/vendor. This works for the code. However, godoc does not show the libraries therein. Is there a way I can fix this? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group

Re: [go-nuts] pointer value not updated when called as interface?

2016-11-21 Thread Sathish VJ
if resp is an interface, then resp.(string) *type asserts* it into a string. And that will be ok if the underlying type is a string. In the question that I asked, the underlying type was not a string, but a pointer to a string. So he type asserted it into a pointer of string type.

Re: [go-nuts] pointer value not updated when called as interface?

2016-11-20 Thread Sathish VJ
thank you. that works, and I think I also get the general idea. On Sunday, 20 November 2016 17:30:06 UTC+5:30, Jan Mercl wrote: > > On Sun, Nov 20, 2016 at 12:55 PM Sathish VJ <sath...@gmail.com > > wrote: > > > In the code below, why is the value of s not changed in

[go-nuts] pointer value not updated when called as interface?

2016-11-20 Thread Sathish VJ
In the code below, why is the value of s not changed in the calling function? func f(resp interface{}) { resp = "abcd" } func main() { var s string f() fmt.Println(s) //prints blank? } Play link: https://play.golang.org/p/KtfooO-cNt -- You received this message because you are subscribed

[go-nuts] Re: unmarshal unix time from a json stream is of different format

2016-11-19 Thread Sathish VJ
That by itself works, but I still haven't figured out how to make a custom marshal type work automatically in both directions. i.e. the streaming part in json is in unix time format but internally it is time.Time. Can we put a custom type in the tag value? Something like this? T time.Time

[go-nuts] Re: Go 1.7 Release Candidate 1 is released

2016-07-12 Thread Sathish VJ
On Mac, bash prompt, attempting to install go to custom location using package installation file go1.7rc1.darwin-amd64.pkg. But it is always installed in /usr/local/bin. export GOROOT="/Users/username/coding/golang/go1.7.rc1" export GOPATH="/Users/username/coding/golang/gopath" export