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
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
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
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,
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
> 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
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
:
>
> 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
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))
}
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
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
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
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
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
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
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
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
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
>
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
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
, 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
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
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
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
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
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
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"
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
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
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
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
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
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
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
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
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
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
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.
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
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
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
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
42 matches
Mail list logo