[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 Error: type tester of t1 does not match inferred type coder for T

If I flip the parameters that I pass, then the error is now for the second 
one.  
Print(c1, t1)
Compiler Error: type coder of c1 does not match inferred type tester for T)

Play link: https://go2goplay.golang.org/p/z6YsFbZSdRg

-- 
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/abe6eed4-4158-44d7-b3ca-570d0fdc3d9an%40googlegroups.com.


[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 
> you want.  There's not much difference in safety, except you could get 
> passed nil interface values.
>
> On Saturday, 9 October 2021 at 18:38:00 UTC+1 Brian Candler wrote:
>
>> "coder" and "tester" are two different defined types, but function Print 
>> is defined to take two arguments of the same type.
>>
>> Even though they implement the same interface, they are not the same 
>> type.  I'd say you want to interfaces *instead* of generics:
>> https://go2goplay.golang.org/p/rPU46HWvZJu
>>
>> On Saturday, 9 October 2021 at 18:33:10 UTC+1 sath...@gmail.com wrote:
>>
>>> 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 Error: type tester of t1 does not match inferred type coder for 
>>> T
>>>
>>> If I flip the parameters that I pass, then the error is now for the 
>>> second one.  
>>> Print(c1, t1)
>>> Compiler Error: type coder of c1 does not match inferred type tester for 
>>> T)
>>>
>>> Play link: https://go2goplay.golang.org/p/z6YsFbZSdRg
>>>
>>>

-- 
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/f0e31da1-8df4-49b2-aac1-ab7700d60f7an%40googlegroups.com.


[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 
"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/608c41d5-a226-4d77-a8fc-c4563d69f5db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ffafebcc-b8e9-4aa2-bb8d-e9dd2efc8f54%40googlegroups.com.


[go-nuts] Re: 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
So doing *type X Y* is just a type declaration then?

Meanwhile, I wrote a small example to help me figure out the differences 
between some of these based on the specs.  Leaving it here in case it is 
useful for somebody.

package main

import "fmt"

type X struct {}
func (X) f() {}

type Y X // cannot call functions on X via Y

type Z = X // alias declaration. identical types.

func main() {
 x := X{}
 y := Y{}
 z := Z{}
 
 fmt.Println(x, y, z)
 x.f()
 z.f()

 // y.f() // not possible
}




On Tuesday, 13 August 2019 11:19:51 UTC+5:30, Volker Dobler wrote:
>
> type X Y declares a named type X with underlying type Y.
> A type alias is something completely different (look up
> "Alias declaration" in the Spec).
>
> There are no such things like "type redefinition" or
> "type adapter" in Go. See the Spec again: It contains
> 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 
>> 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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/273b9d33-97f4-4946-9cb9-b92fe5ee769f%40googlegroups.com.


[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))
}


func (t *T) UnmarshalText(text []byte) error {
 type noMethod T
 return json.Unmarshal(text, (*noMethod)(t))
}


func (t T) MarshalJSON() (text []byte, err error) {
 type noMethod T
 return json.Marshal(noMethod(t))
}


func (t *T) UnmarshalJSON(text []byte) error {
 type noMethod T
 return json.Unmarshal(text, (*noMethod)(t))
}





https://play.golang.org/p/e8cZfkU1uvE 

-- 
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/cacde93e-6b27-49e7-962f-e755f62ed442%40googlegroups.com.


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

2019-09-14 Thread Sathish VJ
Yes, that makes sense.  Thank you.

The example I wrote was concocted.  But I've seen others do it on their own 
types too, which didn't make sense at all.  Maybe they were just 
copy-pasting similar code from elsewhere.

On Saturday, 14 September 2019 20:20:49 UTC+5:30, Ben Burwell wrote:
>
> 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 { 
> >  A int 
> >  C string 
> > } 
> > 
> > func (t T) MarshalJSON() (text []byte, err error) { 
> >  type noMethod T 
> >  return json.Marshal(noMethod(t)) 
> > } 
> > 
> > https://play.golang.org/p/e8cZfkU1uvE 
>
> When json.Marshal is called, if the value passed implements 
> json.Marshaler, then that method is called to marshal the value. 
>
> If you wrote 
>
> func (t T) MarshalJSON() (text []byte, err error) { 
> return json.Marshal(t) 
> } 
>
> func main() { 
> var t T 
> json.Marshal(t) 
> } 
>
> then you'd end up with infinite recursion, as the T.MarshalJSON() method 
> would just keep getting called. By defining `type noMethod T` and 
> casting t to a noMethod before calling json.Marshal, you can avoid this 
> because the noMethod type has, well, no methods, and thus does not 
> implement json.Marshaler and will be encoded using the struct encoder. 
>
> In this case, you may as well just not implement json.Marshaler at all 
> and fall through immediately to the struct encoder, but perhaps there's 
> some reason to do this that your example doesn't show. 
>

-- 
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/aeea2f49-58e1-42d8-806a-56cdf899c70c%40googlegroups.com.


[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"
"golang.org/x/net/context"
)

func getImageLabels(filename string) []string {

ctx := context.Background()

apiKey := "..." // my api key has been generated in the console and should 
be fine.
apiKeyOption := option.WithAPIKey(apiKey)

client, err := vision.NewImageAnnotatorClient(ctx, apiKeyOption)

// ...
labels, err := client.DetectLabels(ctx, image, nil, 10)

}

*Failed to detect labels: rpc error: code = Internal desc = transport: 
oauth2: cannot fetch token: 400 Bad Request*
*Response: {*
*  "error" : "invalid_grant"*
*}*

p.s. is there a specific group for gcp+golang that I should preferably post 
this to?

-- 
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://groups.google.com/d/optout.


[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 GOBIN="/Users/username/coding/golang/gopath/bin"  # with or without 
this, result is the same.
export PATH=$PATH:$GOBIN
export PATH=$PATH:$GOROOT/bin:/Users/vj/coding/golang/go_appengine

Folder for GOROOT, GOPATH, and GOBIN already exists.  

Is there any way I can get it to install in a custom path?  Or is there an 
issue in the pkg installation?

On Friday, 8 July 2016 10:20:34 UTC+5:30, Chris Broadfoot wrote:
>
> Hello gophers,
>
> We have just released go1.7rc1, a release candidate for Go 1.7.
> It is cut from release-branch.go1.7 at the revision tagged go1.7rc1.
>
> Please help us by testing your Go programs with the release, and report 
> any problems using the issue tracker:
>   https://golang.org/issue/new
>
> You can download binary and source distributions from the usual place: 
>   https://golang.org/dl/#go1.7rc1
>
> To find out what has changed in Go 1.7, read the draft release notes:
>   https://tip.golang.org/doc/go1.7
>
> Documentation for Go 1.7 is available at:
>   https://tip.golang.org/
>
> Cheers,
> Chris
>

-- 
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://groups.google.com/d/optout.


[go-nuts] Re: goimports has been updated

2016-07-15 Thread Sathish VJ
hey brad, is it possible to have a ```goimports version``` so that we know 
what versions we currently have?

On Friday, 15 July 2016 11:04:36 UTC+5:30, bradfitz wrote:
>
> goimports has been updated.
>
> If you've been frustrated by its speed lately, run:
>
>$ go get -u golang.org/x/tools/cmd/goimports
>
> ... and things should be much nicer.
>
> Details at https://golang.org/cl/24941
>
> If I broke something, file a bug: https://golang.org/issues/new
>
> The general speed tracking bug is https://golang.org/issue/16367 (don't 
> use for new bugs, only for speed)
>
>

-- 
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://groups.google.com/d/optout.


[go-nuts] Re: [security] Go 1.6.3 and 1.7rc2 are released

2016-07-18 Thread Sathish VJ
Not sure if this is a real issue but I noticed it with rc1 also.  Raised a 
github request here: https://github.com/golang/go/issues/16409

I'm unable to install it on a Mac from .pkg file into any dir except 
/usr/local/go.

On Monday, 18 July 2016 22:29:54 UTC+5:30, Chris Broadfoot wrote:
>
> A security-related issue was recently reported in Go's net/http/cgi 
> package and net/http package when used in a CGI environment. Go 1.6.3 and 
> Go 1.7rc2 will contain a fix for this issue.
>
> Go versions 1.0-1.6.2 and 1.7rc1 are vulnerable to an input validation 
> flaw in the CGI components resulting in the HTTP_PROXY environment variable 
> being set by the incoming Proxy header. This environment variable was also 
> used to set the outgoing proxy, enabling an attacker to insert a proxy into 
> outgoing requests of a CGI program.
> This is CVE-2016-5386 and was addressed by this change: 
> https://golang.org/cl/25010, tracked in this issue: 
> https://golang.org/issue/16405
>
> The Go team would like to thank Dominic Scheirlinck for coordinating 
> disclosure of this issue across multiple languages and CGI environments. 
> Read more about "httpoxy" here: https://httpoxy.org/
>
> Go 1.6.3 also adds support for macOS Sierra. See 
> https://golang.org/issue/16354 for details.
>
> Downloads are available at https://golang.org/dl for all supported 
> platforms.
>
> Cheers,
> Chris (on behalf of the Go team)
>
>

-- 
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://groups.google.com/d/optout.


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

2016-11-18 Thread Sathish VJ
I'm trying to unmarshal unix time from a json stream.  Why is my custom 
type UnixTime printing a completely different format of the time? 
 Shouldn't it be just a normal time.Time format?

type UnixTime time.Time

func (t *UnixTime) UnmarshalJSON(b []byte) error {
ts, _ := strconv.Atoi(string(b))

fmt.Println("time:", time.Unix(int64(ts), 0))
*t = UnixTime(time.Unix(int64(ts), 0))
fmt.Println("Unixtime:", *t)

return nil
}

//output

time: 2016-11-19 05:58:58 + UTC
Unixtime: {63615131938 0 0x196f20}




Play link (full code): https://play.golang.org/p/FfhBI5lq2K

-- 
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://groups.google.com/d/optout.


[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 `json:"created_time,Unixtime"`

It doesn't work in my sample.  And I've not found any samples on the net 
yet.
New play link: https://play.golang.org/p/f_t0A9M5bL

On Saturday, 19 November 2016 12:32:35 UTC+5:30, Dave Cheney wrote:
>
> UnixTime and time.Time are different types with different method sets. 
> UnixTime is not a subclass or a child type of time.Time as there is no such 
> thing as inheritance in go. 
>
> Try printing this value. 
>
>time.Time(*t)
>
> Dave
>
>

-- 
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://groups.google.com/d/optout.


[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(&s)
fmt.Println(s) //prints blank?
}


Play link: https://play.golang.org/p/KtfooO-cNt

-- 
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://groups.google.com/d/optout.


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  > wrote:
>
> > In the code below, why is the value of s not changed in the calling 
> function? 
>
> Interface is just a value, to indirect through a pointer it contains one 
> can do something like: https://play.golang.org/p/qbx6ltL_SN
>
>
>
> -- 
>
> -j
>

-- 
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://groups.google.com/d/optout.


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. 
 resp.(*pointer).
Now that we have a pointer to the string, we set it's value as 
*strPtr="string value".

On Monday, 21 November 2016 22:56:29 UTC+5:30, Ali Altun wrote:
>
>
> Whats is the meaning of   *resp.(*string) = "abcd" .   I have not seen 
> this before.
>

-- 
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://groups.google.com/d/optout.


[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 and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[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 emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


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

2016-12-15 Thread Sathish VJ
I have a struct that maps json of type string to a string.  
S string `json:"s,string"`

When run with that, it gives me the error:
Error: json: invalid use of ,string struct tag, trying to unmarshal "hello" 
into string

I know that it is not really required.  But does it have to error out?
Is the current behavior planned so for any reason?  I was thinking that 
it's quite ok to over-specify the type here and the stand library would 
ignore it.

Full code: https://play.golang.org/p/gepaK1GsTC 

-- 
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://groups.google.com/d/optout.


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

2016-12-15 Thread Sathish VJ
I don't think your analogy is right.  The example you gave is an error, as 
if we wrote: var i = float64("hello")
Whereas, the code I wrote is just being explicit when it is ok to be 
implicit.  So, more like we wrote: 
var i1 = 3.142
var i2 = float64(3.142)
i3 := float64(3.142)

The float64 casting is unnecessary in the latter two cases, but it isn't an 
error.

On Thursday, 15 December 2016 21:01:11 UTC+5:30, Chris Hines wrote:
>
> Suppose instead of `json:"s,string"` you had typed `json:"s,omitemptyy"` 
> when you meant to type `json:"s,omitempty"`. Would you want to be told that 
> you had an error in your struct tag? In general Go has a fail-fast 
> philosophy to help prevent mistakes from persisting in a system unnoticed 
> for a long time. It is this philosophy that warrants producing an error 
> when the encoding/json 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 with that, it gives me the error:
>> Error: json: invalid use of ,string struct tag, trying to unmarshal 
>> "hello" into string
>>
>> I know that it is not really required.  But does it have to error out?
>> Is the current behavior planned so for any reason?  I was thinking that 
>> it's quite ok to over-specify the type here and the stand library would 
>> ignore it.
>>
>> Full code: https://play.golang.org/p/gepaK1GsTC 
>>
>

-- 
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://groups.google.com/d/optout.


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

2016-12-15 Thread Sathish VJ
Oh, ok.  Thank you for clarifying that for me.  

On Thursday, 15 December 2016 21:27:12 UTC+5:30, Chris Hines wrote:
>
> You are right, my analogy was incorrect. I didn't realize that ",string" 
> was a documented annotation in the json package. I've never had cause to 
> use it. My apologies for the misleading comment.
>
> The package docs it say:
>
> The "string" option signals that a field is stored as JSON inside a 
>> JSON-encoded string."
>
>
> A JSON-encoded string of a string looks like this: "\"hello\"". With that 
> change to the data the code does not return an error. 
> https://play.golang.org/p/XmeBN4885-
>
> Chris
>
> On Thursday, December 15, 2016 at 10:44:39 AM UTC-5, Sathish VJ wrote:
>>
>> I don't think your analogy is right.  The example you gave is an error, 
>> as if we wrote: var i = float64("hello")
>> Whereas, the code I wrote is just being explicit when it is ok to be 
>> implicit.  So, more like we wrote: 
>> var i1 = 3.142
>> var i2 = float64(3.142)
>> i3 := float64(3.142)
>>
>> The float64 casting is unnecessary in the latter two cases, but it isn't 
>> an error.
>>
>> On Thursday, 15 December 2016 21:01:11 UTC+5:30, Chris Hines wrote:
>>>
>>> Suppose instead of `json:"s,string"` you had typed `json:"s,omitemptyy"` 
>>> when you meant to type `json:"s,omitempty"`. Would you want to be told that 
>>> you had an error in your struct tag? In general Go has a fail-fast 
>>> philosophy to help prevent mistakes from persisting in a system unnoticed 
>>> for a long time. It is this philosophy that warrants producing an error 
>>> when the encoding/json 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 with that, it gives me the error:
>>>> Error: json: invalid use of ,string struct tag, trying to unmarshal 
>>>> "hello" into string
>>>>
>>>> I know that it is not really required.  But does it have to error out?
>>>> Is the current behavior planned so for any reason?  I was thinking that 
>>>> it's quite ok to over-specify the type here and the stand library would 
>>>> ignore it.
>>>>
>>>> Full code: https://play.golang.org/p/gepaK1GsTC 
>>>>
>>>

-- 
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://groups.google.com/d/optout.


[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 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://groups.google.com/d/optout.


[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 take care of this case?

source: https://play.golang.org/p/xyiDWZh9Rt

-- 
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://groups.google.com/d/optout.


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 > wrote: 
>
> > 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 take care of this 
> > case? 
> > 
> > source: https://play.golang.org/p/xyiDWZh9Rt 
>
> One way around this is to rely on Go's encoding/json doing the Right 
> Thing™ when unmarshaling into a value of type interface{}. 
> This way, you'll get an appropriately-typed value as a result, and 
> could do type switching on it [1]. 
>
> The downside of this approach is that if your "non-error case" JSON 
> streams are compilcated, and you'd like to actually parse them into 
> objects of your custom (struct) types, this approach would require 
> re-parsing the source JSON stream for a non-error case. 
> You can get around this problem by resorting to low-level parsing of 
> the JSON stream and switching the processing logic as soon as you 
> detect you were sent a JSON object (which might contain the 
> field "error" signalizing an error).  Unfortunately, the JSON decoder 
> seems to not support "peeking" at the next token or "pushing back" the 
> just read token so you'll need to resort to a somewhat contrived 
> solution such as [2], which I'd use only if your "non-error case" data 
> streams are large enough to warrant such dancing. 
>
> You could also condider exploring 3rd-party JSON decoders such as [3] or 
> [4] which might contain enough controls to facilitate such fine-grained 
> parsing you need. 
>
> 1. https://play.golang.org/p/VVm6pxN8rh 
> 2. https://play.golang.org/p/6wntcKxKBR 
> 3. https://github.com/ugorji/go 
> 4. https://github.com/clbanning/mxj 
>

-- 
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://groups.google.com/d/optout.


[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 certain cells in a table if it is 
different from that in previous row.

code: https://play.golang.org/p/v-O_M4Rq4N

-- 
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://groups.google.com/d/optout.


[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
/var/folders/ns/kwlq7kfs64z97kyw47lghplrgn/T/go-build269297204/bitbucket.org/me/myproject/_test/_testmain.go:52:
 
cannot use matchString (type func(string, string) (bool, error)) as type 
testing.testDeps in argument to testing.MainStart:
func(string, string) (bool, error) does not implement testing.testDeps 
(missing MatchString method)

My go version is: go version go1.7.1 darwin/amd64

-- 
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://groups.google.com/d/optout.


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

2017-03-14 Thread Sathish VJ
Ok, I don't know what exactly went wrong here.  But I had sometime 
previously downloaded a version of go1.8 to test it out.  If I explicitly 
run the tests with that, it runs fine.

~/golang/go1.8/bin/go test

Is there any reason why there is a conflict on my system?  I don't remember 
making any 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 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
> /var/folders/ns/kwlq7kfs64z97kyw47lghplrgn/T/go-build269297204/
> bitbucket.org/me/myproject/_test/_testmain.go:52: cannot use matchString 
> (type func(string, string) (bool, error)) as type testing.testDeps in 
> argument to testing.MainStart:
> func(string, string) (bool, error) does not implement testing.testDeps 
> (missing MatchString method)
>
> My go version is: go version go1.7.1 darwin/amd64
>

-- 
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://groups.google.com/d/optout.


[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 know what exactly went wrong here.  But I had sometime 
> previously downloaded a version of go1.8 to test it out.  If I explicitly 
> run the tests with that, it runs fine.
>
> ~/golang/go1.8/bin/go test
>
> Is there any reason why there is a conflict on my system?  I don't 
> remember making any 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 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
>> /var/folders/ns/kwlq7kfs64z97kyw47lghplrgn/T/go-build269297204/
>> bitbucket.org/me/myproject/_test/_testmain.go:52: cannot use matchString 
>> (type func(string, string) (bool, error)) as type testing.testDeps in 
>> argument to testing.MainStart:
>> func(string, string) (bool, error) does not implement testing.testDeps 
>> (missing MatchString method)
>>
>> My go version is: go version go1.7.1 darwin/amd64
>>
>

-- 
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://groups.google.com/d/optout.


[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 emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[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 
play.golang.org).

package main


import (
 "fmt"
 "os"
 "time"
)


func f(quit chan bool) {
 for {
   select {
   case <-time.After(0 * time.Second):
 // start long running task immediately.
 for {
   time.Sleep(500 * time.Millisecond)
   fmt.Printf(". ")
 }
   case <-quit:
 fmt.Println("quit called")
 //deallocate resources in other long running task and then return from 
function.
 os.Exit(0) // or return
   }
 }
}


func main() {
 var quit chan bool
 go f(quit)


 println("quit sending ... ")
 quit <- true
 println("after quit sent")


 var i chan int
 <-i
}


-- 
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://groups.google.com/d/optout.


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

2018-03-17 Thread Sathish VJ
Leaving aside the channel being non-nil, none of the others are a clear way 
to solve this.  They all involve either repeatedly checking on a timer or 
checking the value of another field (like polling) to see whether the long 
running task should be stopped.

Is there no other way to do this then?

On Friday, 16 March 2018 20:34:38 UTC+5:30, matthe...@gmail.com wrote:
>
> While this is running, your select won't be receiving on the quit 
>> channel, even if it is non-nil. 
>> If you want to be able to cancel it, you'll need to make the code in 
>> the loop responsive 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 16, 2018 at 9:45:00 AM UTC-5, Sathish VJ wrote:
>>
>> 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 
>> play.golang.org).
>>
>> package main
>>
>>
>> import (
>>  "fmt"
>>  "os"
>>  "time"
>> )
>>
>>
>> func f(quit chan bool) {
>>  for {
>>select {
>>case <-time.After(0 * time.Second):
>>  // start long running task immediately.
>>  for {
>>time.Sleep(500 * time.Millisecond)
>>fmt.Printf(". ")
>>  }
>>case <-quit:
>>  fmt.Println("quit called")
>>  //deallocate resources in other long running task and then return 
>> from function.
>>  os.Exit(0) // or return
>>}
>>  }
>> }
>>
>>
>> func main() {
>>  var quit chan bool
>>  go f(quit)
>>
>>
>>  println("quit sending ... ")
>>  quit <- true
>>  println("after quit sent")
>>
>>
>>  var i chan int
>>  <-i
>> }
>>
>>
>>

-- 
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://groups.google.com/d/optout.


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

2018-03-19 Thread Sathish VJ
Looks like this last one works but also quite complicated.

One question ... what is the effect of having "default" on line 24 as empty?


On 18 March 2018 at 14:21, 'Reinhard Luediger' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

> I came to the following solution for my long running tasks, using
> go-routines & the context package,
>
> https://play.golang.org/p/2V_29lHt4Wn
>
> package main
>
> import (
>"context"
>"fmt"
>"time"
> )
>
> //LongRunningTask
> func LongRunningTask(ctx context.Context, index int) (err error) {
>// we'll signal on that channel when we finished
>var finished chan struct{}
>fmt.Printf("Starting task %d at: %s\n", index, time.Now())
>var cancelWork =  make(chan struct{},0)
>go func() {
>   workloop:
>   for i:= 0 ;i < 10 ;i++{
>  // sleeping for a  long time
>  time.Sleep(time.Second * 2)
>  select {
>  case <-cancelWork:
> fmt.Printf("Canceling work for Index: %d\n",index)
> break workloop
>  default:
>  }
>   }
>   finished <- struct{}{}
>}()
>
>select {
>// when the task finished normal we'll get a notification on the finished 
> channel
>case <-finished:
>   fmt.Printf("Task %d  finished at:%s\n", index, time.Now())
>   return nil
>
>// If the context gets canceled we receive a signal on that channel
>case <-ctx.Done():
>   err := ctx.Err()
>   _=err
>   //the context.Err() method gives us the reason why it was canceled
>   fmt.Printf("task %d aborted reason:%s at: %s\n", index, ctx.Err(), 
> time.Now())
>   cancelWork <- struct{}{}
>   return ctx.Err()
>}
>
> }
>
> func main() {
>var ctx context.Context
>
>// get a new Context and  the corresponding cancel function
>ctx, cancel := context.WithCancel(context.Background())
>
>// create a new context with a timeout value of 4 Seconds derived from the 
> context above
>ctx, _ = context.WithTimeout(ctx, time.Second*4)
>
>// Sleeping for one Second to clarify that the timeout is running from the 
> point where it is created
>time.Sleep(time.Second * 1)
>
>fmt.Printf("Starting background tasks time %s", time.Now())
>for i := 0; i < 7; i++ {
>   go LongRunningTask(ctx, i)
>
>}
>
>// if we sllep longer 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 cancellation 
> information to all child context
>cancel()
>
>// Sleep a while to see the cancellation messages
>time.Sleep(time.Second * 4)
>
> }
>
>
> Am Freitag, 16. März 2018 15:45:00 UTC+1 schrieb 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
>> play.golang.org).
>>
>> package main
>>
>>
>> import (
>>  "fmt"
>>  "os"
>>  "time"
>> )
>>
>>
>> func f(quit chan bool) {
>>  for {
>>select {
>>case <-time.After(0 * time.Second):
>>  // start long running task immediately.
>>  for {
>>time.Sleep(500 * time.Millisecond)
>>fmt.Printf(". ")
>>  }
>>case <-quit:
>>  fmt.Println("quit called")
>>  //deallocate resources in other long running task and then return
>> from function.
>>  os.Exit(0) // or return
>>}
>>  }
>> }
>>
>>
>> func main() {
>>  var quit chan bool
>>  go f(quit)
>>
>>
>>  println("quit sending ... ")
>>  quit <- true
>>  println("after quit sent")
>>
>>
>>  var i chan int
>>  <-i
>> }
>>
>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/golang-nuts/l2A0PS91T0A/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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://groups.google.com/d/optout.


[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 command line
the downloaded src and cmd are put in "~/go"

Macbook 2:
Same as above but "echo $GOPATH" and "go env" show different paths.  

Has anybody else seen this issue?

-- 
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://groups.google.com/d/optout.


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

2018-09-11 Thread Sathish VJ
Wanted to add that both had go 1.11 installed.  Downloaded as a zip/gz file 
and extracted to a known path.

Also, there were 20+ others also there who did the same, but did not face 
that issue. But we were unable to figure out the root cause.

On Tuesday, 11 September 2018 20:00:53 UTC+5:30, 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 env"
> do "go get github.com/username/pkgname" on command line
> the downloaded src and cmd are put in "~/go"
>
> Macbook 2:
> Same as above but "echo $GOPATH" and "go env" show different paths.  
>
> Has anybody else seen this issue?
>

-- 
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://groups.google.com/d/optout.


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, 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 env"
> do "go get github.com/username/pkgname" on command line
> the downloaded src and cmd are put in "~/go"
>
> Macbook 2:
> Same as above but "echo $GOPATH" and "go env" show different paths.
>
> Has anybody else seen this issue?
>
> --
> 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://groups.google.com/d/optout.
>
>
>

-- 
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://groups.google.com/d/optout.


[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 process or something 
else?

-- 
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://groups.google.com/d/optout.


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

2018-09-19 Thread Sathish VJ
So, you are saying it is only for readability?

But even in go we can write convoluted functions like: 
func f(func(*int, *string) *int, []*byte) (func(*int, *float32), error)


On Thursday, 20 September 2018 11:09:23 UTC+5:30, kortschak wrote:
>
> To avoid having to have something 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 
> > 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 process or 
> > something  
> > else? 
> > 
>

-- 
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://groups.google.com/d/optout.


[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 that directory.

package mymath

import (
"fmt"
"regexp"
"strconv"
"testing"
)

func square(i int) int {
return i * i
}


func Benchmark_Square(b *testing.B) {
for i := 0; i < b.N; i++ {
b.StopTimer() 

// do costly setup
r, _ := regexp.Compile("^[0-9]+,")
s := r.FindStringSubmatch("24,32,56")
first := s[0]
first = first[:len(first)-1]
inp, _ := strconv.ParseInt(first, 10, 64)

b.StartTimer()
square(int(inp))
}

}



-- 
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://groups.google.com/d/optout.


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

2018-10-22 Thread Sathish VJ
So, I also tried with 
*go test -v -bench=.  -test.benchtime=0.1s *
and that does complete.  

But is the implication that StopTimer/StartTimer is too costly to use even 
for this simple benchmark?

On Monday, 22 October 2018 21:00:20 UTC+5:30, Jan Mercl wrote:
>
>
>
>
> On Mon, Oct 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 nsec. 
> The non-measured is tens of microseconds or more. Meaning that for every 1 
> nsec measured the code spends several thousans times more in the 
> non-measured path. So 1 sec / 1 nsec * theOverheadRatio is the time to read 
> 1 sec of _measured time.
>
> -- 
>
> -j
>

-- 
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://groups.google.com/d/optout.


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 implication that StopTimer/StartTimer is too costly to use even 
> for this simple benchmark?
>
>
> See https://github.com/golang/go/issues/20875 for more information
>

-- 
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://groups.google.com/d/optout.


[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 
sequence this code?
Is using default not an option here at all?

https://play.golang.org/p/30sI9RYJ1Ed

package main

import "fmt"
//import "time"

var c = make(chan string)
var quit = make(chan bool)

func main() {
go fn()

for {
select {
case msg, ok := <-c:
if !ok {
c = nil
return
} else {
fmt.Println("received: ", msg)
quit <- true
}
}
}
}

func fn() {
for {
select {
case <-quit:
fmt.Println("closin chan c")
close(c)
return
//case <-time.After(time.Nanosecond):  // this is ok
default:   // using default causes deadlock
c <- "Image"
}
}
}



received:  Imagefatal error: all goroutines are asleep - deadlock!

goroutine 1 [chan send]:
main.main()
/tmp/sandbox497027958/main.go:20 +0x100

goroutine 5 [chan send]:
main.fn()
/tmp/sandbox497027958/main.go:35 +0x40
created by main.main
/tmp/sandbox497027958/main.go:10 +0x40



-- 
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://groups.google.com/d/optout.


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 Sathish VJ  > wrote: 
> > 
> > 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 
> sequence this code? 
> > Is using default not an option here at all? 
> > 
> > https://play.golang.org/p/30sI9RYJ1Ed 
> > 
> > package main 
> > 
> > import "fmt" 
> > //import "time" 
> > 
> > var c = make(chan string) 
> > var quit = make(chan bool) 
> > 
> > func main() { 
> > go fn() 
> > 
> > for { 
> > select { 
> > case msg, ok := <-c: 
> > if !ok { 
> > c = nil 
> > return 
> > } else { 
> > fmt.Println("received: ", msg) 
> > quit <- true 
> > } 
> > } 
> > } 
> > } 
> > 
> > func fn() { 
> > for { 
> > select { 
> > case <-quit: 
> > fmt.Println("closin chan c") 
> > close(c) 
> > return 
> > //case <-time.After(time.Nanosecond):  // this is ok 
> > default:   // using default causes deadlock 
> > c <- "Image" 
> > } 
> > } 
> > } 
> > 
> > 
> > 
> > received:  Image 
> > fatal error: all goroutines are asleep - deadlock! 
> > 
> > goroutine 1 [chan send]: 
> > main.main() 
> > /tmp/sandbox497027958/main.go:20 +0x100 
> > 
> > goroutine 5 [chan send]: 
> > main.fn() 
> > /tmp/sandbox497027958/main.go:35 +0x40 
> > created by main.main 
> > /tmp/sandbox497027958/main.go:10 +0x40 
> > 
> > 
> > 
> > -- 
> > 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...@googlegroups.com . 
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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://groups.google.com/d/optout.


[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 
convenient to shift to a mouse/trackpad.

-- 
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/a930fd75-243d-4668-8019-3e456e0c3ce9%40googlegroups.com.


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 not automatically 
fix the 
error for them That would be very confusing. 

>> fair enough

> Shouldn't Run automatically subsume Format and Imports? 

No, it should simply run the code in my opinion, after all that's what 
"run" means 

>> maybe there should be a button to do all of it together. It'd just make 
it easier.

> Also, it would be good to have a keyboard shortcut to run it.  It's not 
> convenient to shift to a mouse/trackpad. 

There is on my computer :P install something like vimperator or use 
quotebrowser 
or some such. 

>> well, me too. with vimium. :-)  But that suggestion was to include 
others also who don't use those extensions.

-- 
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/1d9bf354-9de6-4ebf-9b7b-4b231ff0926e%40googlegroups.com.


[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 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/a57fcacf-f6dd-424b-a405-1714abf3287fn%40googlegroups.com.


[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, 2020 at 10:30:56 AM UTC+2 santhoshth...@gmail.com 
> wrote:
>
>> Hi All,
>>
>> What is best way to know a executable version without executing it 
>> through golang?
>>
>> I tried with reading the executable file through a scanner and matching 
>> every line with regex (like ngnix regx) but this is not working for all 
>> executables.
>>
>> Do you have any idea?
>>
>

-- 
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/eac6fad2-edcf-47c2-8b0e-e1f2d2dd6d56n%40googlegroups.com.


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 not allowed?
> >
> > s := "hello"
> > s[0] = 'a' // compile error: cannot assign to s[0]
> >
> > https://play.golang.org/p/zyJXwhEeKPo
>
> """"
> Strings are immutable: once created, it is impossible to change the
> contents of a string.
> """"
>
> (https://golang.org/ref/spec#String_types)
>

-- 
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/fdb397ce-4417-4c99-8774-87156d6b2412n%40googlegroups.com.