Re: [go-nuts] Trouble exporting function with anonymous struct containing anonymous fields as parameter

2021-11-16 Thread 'Axel Wagner' via golang-nuts
To expand on Kevin's answer: To call a function, the argument must be assignable to the parameter type of the function. In this case, none of the types involved is a defined type, channel, interface, pointer…, so the only case left for them to be assigna

Re: [go-nuts] Why the following code is data race free ?

2021-11-16 Thread 'Axel Wagner' via golang-nuts
On Wed, Nov 17, 2021 at 6:43 AM Ting Yuan wrote: > I am confused, why there is no data race in the above program. I'm using > go1.17.2 linux/amd64 > The race detector is a heuristic. That it doesn't report a race does not mean there is none. Races are non-deterministic, so it's very possible tha

[go-nuts] Why the following code is data race free ?

2021-11-16 Thread Ting Yuan
I wrote a simple function and hope it has a race alarm under the `-race` flag: package main import ( "fmt" "time" ) func main() { a := 1 go func() { fmt.Println(a) // If I remove this instruction, the detector will report a data race

Re: [go-nuts] main.go:1:1: expected 'package', found 'EOF'

2021-11-16 Thread Francis
Thank you all, CRTL + S , was the trick!.. I had a similar problem. On Thursday, April 20, 2017 at 12:45:07 AM UTC rame...@gmail.com wrote: > Thank you, Nico. > > > On Friday, January 23, 2015 at 6:16:15 AM UTC-8, Nico wrote: >> >> Did you save before calling GoRun? >> > -- You received this m

Re: [go-nuts] SSH session.Setenv usage

2021-11-16 Thread Cobe Gu
Thanks for your reply. that's a trick thing to print all embedded errors. After digging more, Setenv function is related to the configuration ' AcceptEnv' of remote server's sshd, if variable name is not accepted by ' AcceptEnv', it will throw out this unclear error 'Failed to set env' 在2021年

[go-nuts] Re: Trouble exporting function with anonymous struct containing anonymous fields as parameter

2021-11-16 Thread 'Kevin Chowski' via golang-nuts
Sorry, I included a typo. I have edited my reply below to fix it. On Tuesday, November 16, 2021 at 8:25:47 PM UTC-7 Kevin Chowski wrote: > It's not clear to me what problem you are solving. Can you clarify *why* > you want to do this? > > For what it's worth, this seems correct to me: a function

[go-nuts] Re: Trouble exporting function with anonymous struct containing anonymous fields as parameter

2021-11-16 Thread 'Kevin Chowski' via golang-nuts
It's not clear to me what problem you are solving. Can you clarify *why* you want to do this? For what it's worth, this seems correct to me: a function defined in package X should not be able to access the unexported fields of a struct in package Y. If you embed a 'byte' into a struct, that is

[go-nuts] Trouble exporting function with anonymous struct containing anonymous fields as parameter

2021-11-16 Thread Óscar Carrasco
Hello, my issue is similar to: https://stackoverflow.com/questions/38784963/exporting-functions-with-anonymous-struct-as-a-parameter-cannot-use-value-type In this particular case, it is fixed by exporting the fields capitalizing the field name. But, what if the struct fields are also anonymous?

[go-nuts] Re: pkg.go.dev jump to broken?

2021-11-16 Thread Brian Candler
Works for me: Chrome 96.0.4664.45, macOS 10.14.6 -- 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

[go-nuts] pkg.go.dev jump to broken?

2021-11-16 Thread Steven Hartland
Clicking the jump to or pressing F on pkg.go.dev seems to be broken here. In Chrome console I'm seeing security warning about eval, which could be the cause: Content Security Policy of your site blocks the use of 'eval' in JavaScript` The Content Security Policy (CSP) prevents the evaluation of ar

Re: [go-nuts] Re: Flag fall through logic review

2021-11-16 Thread Brian Candler
On Tuesday, 16 November 2021 at 14:49:54 UTC leam...@gmail.com wrote: > For the errors in lines 14-19, what other failures do you see needing to > be handled? IMO, programs should handle *all* errors - especially the ones you don't anticipate. But if the filesystem is starting to return EIO o

Re: [go-nuts] atomic.Value : inconsistent types

2021-11-16 Thread 'Axel Wagner' via golang-nuts
I actually thought about it and your way is strictly better, as it supports CAS (if all interface types involved do), which the pointer-method doesn't. On Tue, Nov 16, 2021 at 5:16 PM Stephen Illingworth < stephen.illingwo...@gmail.com> wrote: > > How about just a 'container' type for the interfa

Re: [go-nuts] atomic.Value : inconsistent types

2021-11-16 Thread Stephen Illingworth
> How about just a 'container' type for the interface. >> >> https://play.golang.org/p/WSXVjVHj1Ya >> > >> For what I need, that does the job nicely. The type being stored in the >> atomic.Value isn't changing so it satisfies the atomic.Value constraints >> but I have the flexibility of the con

Re: [go-nuts] atomic.Value : inconsistent types

2021-11-16 Thread 'Axel Wagner' via golang-nuts
On Tue, Nov 16, 2021 at 3:33 PM Stephen Illingworth < stephen.illingwo...@gmail.com> wrote: > How about just a 'container' type for the interface. > > https://play.golang.org/p/WSXVjVHj1Ya > > For what I need, that does the job nicely. The type being stored in the > atomic.Value isn't changing so

Re: [go-nuts] Re: Flag fall through logic review

2021-11-16 Thread Sean Liao
I would go for something more like: https://play.golang.org/p/MyorlUwOL9s and not bother with the intermediate checks, just read directly and report any issues you encounter On Tuesday, November 16, 2021 at 3:49:54 PM UTC+1 leam...@gmail.com wrote: > Brian, thanks! Here's the playground link: >

Re: [go-nuts] Re: Flag fall through logic review

2021-11-16 Thread Leam Hall
Brian, thanks! Here's the playground link: https://play.golang.org/p/Ef8D4CF-kKD For the errors in lines 14-19, what other failures do you see needing to be handled? I'm still not comprehending how to check for "isReadable()", but that would be a useful next step. Of course, when the file is

[go-nuts] Re: Flag fall through logic review

2021-11-16 Thread Brian Candler
(BTW, sharing your code on play.golang.org makes it easier to format and read) On Tuesday, 16 November 2021 at 14:11:54 UTC leam...@gmail.com wrote: > > 14 func exists(filepath string) bool { > 15 if _, err := os.Stat(filepath); errors.Is(err, fs.ErrNotExist) { > 16 return false > 17 } > 18

Re: [go-nuts] atomic.Value : inconsistent types

2021-11-16 Thread Stephen Illingworth
> I've found that the way around this is to create a new instance of >> atomic.Value whenever I have reason to believe that the type to be stored >> has changed. >> > > That seems to be counter to the idea behind `atomic.Value`. Creating and > setting the new `atomic.Value` requires synchroniz

[go-nuts] Flag fall through logic review

2021-11-16 Thread Leam Hall
I'm re-learning Go and building a program to create characters for role-playing games. The program uses text files to build lists, and I'd like to let the user change the lists. For example, a modern day Earth game would only have human characters, but a Star Trek (TNG) game might have other sp

Re: [go-nuts] atomic.Value : inconsistent types

2021-11-16 Thread 'Axel Wagner' via golang-nuts
On Tue, Nov 16, 2021 at 1:25 PM Stephen Illingworth < stephen.illingwo...@gmail.com> wrote: > I've found that the way around this is to create a new instance of > atomic.Value whenever I have reason to believe that the type to be stored > has changed. > That seems to be counter to the idea behind

Re: [go-nuts] atomic.Value : inconsistent types

2021-11-16 Thread Robert Engels
I believe your code is broken. You need to use a lock when checking and making the switch (see double locking problem) or there would be no need to use atomics. If you run it under the race detector I am guessing it will fail. > On Nov 16, 2021, at 6:25 AM, Stephen Illingworth > wrote: > >

[go-nuts] atomic.Value : inconsistent types

2021-11-16 Thread Stephen Illingworth
When using atomic.Values it is important that the type being stored is consistent. Trying to store a different type in an atomic.Value will cause a panic panic: sync/atomic: store of inconsistently typed value into Value I've found that the way around this is to create a new instance of atomic

Re: [go-nuts] SSH session.Setenv usage

2021-11-16 Thread Brian Candler
You resurrected a 7 year old thread for this! :-) The first thing I suggest you do is to print the value of "err" and you may get back some information about why it failed. (Same for everywhere else that err != nil) -- You received this message because you are subscribed to the Google Groups

Re: [go-nuts] Go2 Playground and constraints package

2021-11-16 Thread Johann Höchtl
Thanks for pointing me to the tip-playground. And I like all being discussed in https://github.com/golang/go/issues/48424 Am Di., 16. Nov. 2021 um 08:57 Uhr schrieb Axel Wagner < axel.wagner...@googlemail.com>: > The go2go playground is basically obsolete, as it is based on the > prototype implem