[go-nuts] Re: go routines not being deallocated
>From further research (and anybody correct me if this is wrong), when the GC does collect memory the profile shrinks, but *no memory is returned to the system*. Any future allocations will try to use memory from the pool of previously collected objects before asking the system for more. This is why things are behaving this way. On Sunday, April 18, 2021 at 12:34:44 PM UTC-5 Trig wrote: > Also, I don't think it's the Stack. If you replace Alloc with > HeapAlloc... it's all there. > > On Sunday, April 18, 2021 at 12:33:20 PM UTC-5 Trig wrote: > >> Correct... the example using time.Sleep didn't run on the playground. >> The original post I made, I provided the link with just a goroutine with an >> empty function. >> >> At least you were able to reproduce what I'm inquiring about. I'll look >> further into this, but surely unused and finished goroutines don't leave >> stuff laying around like that. >> >> On Sunday, April 18, 2021 at 3:47:10 AM UTC-5 Brian Candler wrote: >> >>> What do you mean by "It won't work on the playground"? It runs for me. >>> Are you saying you get different results when running locally? If so, what >>> version of go are you running locally, on what platform, and what do you >>> see? >>> >>> Or are you saying the problem is really with something like this? >>> https://play.golang.org/p/Q91Qd-DvvKx >>> >>> That indeed fails to run in the playground - it exits with signal 9 >>> (128+9=137) >>> >>> Running locally with go 1.16.3 under macOS (Intel) I see: >>> >>> Allocs before: 82696 >>> Allocs while running: 51496728 >>> Allocs after: 40384112 >>> Allocs after: 40384112 >>> Allocs after: 40384112 >>> Allocs after: 40384112 >>> Allocs after: 40384112 >>> >>> That is 40MB that apparently isn't reclaimed, but it does get reused if >>> you run more goroutines: >>> https://play.golang.org/p/YcMTlLYxXAP >>> >>> I don't know why that is. It's about 400 bytes per goroutine. Stack >>> perhaps? >>> >> -- 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/f42e270a-7ae9-4f11-bb85-d94bcbd331f1n%40googlegroups.com.
[go-nuts] Re: go routines not being deallocated
Also, I don't think it's the Stack. If you replace Alloc with HeapAlloc... it's all there. On Sunday, April 18, 2021 at 12:33:20 PM UTC-5 Trig wrote: > Correct... the example using time.Sleep didn't run on the playground. The > original post I made, I provided the link with just a goroutine with an > empty function. > > At least you were able to reproduce what I'm inquiring about. I'll look > further into this, but surely unused and finished goroutines don't leave > stuff laying around like that. > > On Sunday, April 18, 2021 at 3:47:10 AM UTC-5 Brian Candler wrote: > >> What do you mean by "It won't work on the playground"? It runs for me. >> Are you saying you get different results when running locally? If so, what >> version of go are you running locally, on what platform, and what do you >> see? >> >> Or are you saying the problem is really with something like this? >> https://play.golang.org/p/Q91Qd-DvvKx >> >> That indeed fails to run in the playground - it exits with signal 9 >> (128+9=137) >> >> Running locally with go 1.16.3 under macOS (Intel) I see: >> >> Allocs before: 82696 >> Allocs while running: 51496728 >> Allocs after: 40384112 >> Allocs after: 40384112 >> Allocs after: 40384112 >> Allocs after: 40384112 >> Allocs after: 40384112 >> >> That is 40MB that apparently isn't reclaimed, but it does get reused if >> you run more goroutines: >> https://play.golang.org/p/YcMTlLYxXAP >> >> I don't know why that is. It's about 400 bytes per goroutine. Stack >> perhaps? >> > -- 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/10623387-ee28-4b69-b393-6b64d6e48366n%40googlegroups.com.
[go-nuts] Re: go routines not being deallocated
Correct... the example using time.Sleep didn't run on the playground. The original post I made, I provided the link with just a goroutine with an empty function. At least you were able to reproduce what I'm inquiring about. I'll look further into this, but surely unused and finished goroutines don't leave stuff laying around like that. On Sunday, April 18, 2021 at 3:47:10 AM UTC-5 Brian Candler wrote: > What do you mean by "It won't work on the playground"? It runs for me. > Are you saying you get different results when running locally? If so, what > version of go are you running locally, on what platform, and what do you > see? > > Or are you saying the problem is really with something like this? > https://play.golang.org/p/Q91Qd-DvvKx > > That indeed fails to run in the playground - it exits with signal 9 > (128+9=137) > > Running locally with go 1.16.3 under macOS (Intel) I see: > > Allocs before: 82696 > Allocs while running: 51496728 > Allocs after: 40384112 > Allocs after: 40384112 > Allocs after: 40384112 > Allocs after: 40384112 > Allocs after: 40384112 > > That is 40MB that apparently isn't reclaimed, but it does get reused if > you run more goroutines: > https://play.golang.org/p/YcMTlLYxXAP > > I don't know why that is. It's about 400 bytes per goroutine. Stack > perhaps? > -- 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/580701a8-784b-4c6e-99db-6499b906ac9an%40googlegroups.com.
[go-nuts] Re: go routines not being deallocated
Sorry, for clarification... the above should be, if you 'put something like time.Sleep(time.Second * 1) *in the go routine*...' On Sunday, April 18, 2021 at 12:32:39 AM UTC-5 Trig wrote: > Can somebody tell me why this is? It won't work on the playground; > however, put something like time.Sleep(time.Second * 1) and put the last > allocs in a loop... and you'll see it's literally MBs of Allocs used that > never get released. > > What am I doing wrong, or not understanding here? I thought go routines > got completely removed after they've returned (assuming they're not blocked > from doing so). > > https://play.golang.org/p/JfaOVnpMUpf > -- 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/3a2d5a06-dbef-4be2-98f9-fe86c0818313n%40googlegroups.com.
[go-nuts] go routines not being deallocated
Can somebody tell me why this is? It won't work on the playground; however, put something like time.Sleep(time.Second * 1) and put the last allocs in a loop... and you'll see it's literally MBs of Allocs used that never get released. What am I doing wrong, or not understanding here? I thought go routines got completely removed after they've returned (assuming they're not blocked from doing so). https://play.golang.org/p/JfaOVnpMUpf -- 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/9a62f945-2eda-44f7-9c5b-938f9d4dd985n%40googlegroups.com.
[go-nuts] Grouped functions...
So, in Go... you can either define imports, constants, types, variables one at a time... or you can group them using brackets. Why was it decided not to be able to do that with functions? Just curious. func ( main() { fmt.Println(helloWorld()) } helloWorld() string { return "hello, world..." } ) -- 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/243e5beb-903e-4c95-897e-9d53fa1b521dn%40googlegroups.com.
[go-nuts] Structs for JSON APIs and required fields... using pointers
What is the standard practice between required fields of a struct you're expecting to deserialize using JSON, and using pointers for this (if there's any correlation)? API defined a string as required. Do you define it as a string and check for zero-value for that type, or *string and check for nil, etc.? Any other situations/instances were it's best practice to user a pointer for defining struct fields over the standard type? -- 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/26d5e7f0-83e0-40eb-8274-5d9791f29b77n%40googlegroups.com.
[go-nuts] go module name
Is there a way to get the go module name out of the go mod, if modules used, besides opening the go.mod file directly (or another obvious name to get the project name I'm not thinking of)? -- 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/cab873d3-d4a3-4850-8ff6-fc644f2c19c5o%40googlegroups.com.
Re: [go-nuts] Assignment of pointer values in a struct...
And I did it again... posted from another gmail account by accident, and my post is forever in 'approval status', lol. Basically what Robert here said. On Thursday, June 4, 2020 at 9:53:56 AM UTC-5, Robert Engels wrote: > > You need pointers to strings if you need a nil value to be represented > which is often the case in databases. > > > On Jun 4, 2020, at 9:30 AM, Saksham Saxena > wrote: > > > > Yep perfectly fine. MongoDB Driver for Go also uses such a wrapper at > many places where it takes a string as an argument and returns a pointer to > it which is required internally. Not really sure why use a pointer to > strings in Go because they're immutable, but I guess to reach their own. > > > > -- > > 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 golan...@googlegroups.com . > > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/17f2c250-ea5f-41fc-ac1b-0890a69f593b%40googlegroups.com. > > > > -- 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/b52446c0-8750-4f58-818c-ab985962ca25%40googlegroups.com.
[go-nuts] Assignment of pointer values in a struct...
I posted this question the other day and don't see it (may have posted from another gmail account and it's still pending approval)... so here I am again. Let's say I have something like below: type ( Person struct { FirstName *string } ) Usually, I see something like the following when assigning: fn := "John" _ = Person{ FirstName: &fn, } Would something like the following be alright and acceptable practice: _ = Person{ FirstName: pString("John") } func pString(content string) *string { return &content } -- 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/aa31103a-440b-4375-a1af-383f59c353f2%40googlegroups.com.
Re: [go-nuts] getting values from memory addresses within another process...
Kurtis, Thanks... that 'Cheat Engine' is the correct one. Basically, what I am doing is creating a simple service that watches for a particular process (a game, in this instance) and 'monitors' certain values (such as life levels, mana levels, etc.). If my health in the game is low, it simply plays an audio file that let's me know to drink a potion, etc. I'm not needing to write any values to memory (like a bot would actually do)... just be able to read them. On Thursday, April 30, 2020 at 10:43:50 PM UTC-5, Kurtis Rader wrote: > > On Thu, Apr 30, 2020 at 8:25 PM Eric Brown > > wrote: > >> I’ll look into this solution. Thank you for an answer that points me in >> a possible direction. >> > > Gah! I hit the "send" button without providing any useful response in my > previous reply. Note that reading /proc/$pid/mem is only applicable to > Linux. And that solution basically requires your program, written in Go, to > be run as root. > > You need to provide more information about what you're trying to do. > Including any relevant constraints such as particular operating systems you > want to support. You also referenced "Cheat Engine" without providing a > link to a document that explains what you mean by that term. I'm guessing > (emphasis on "guessing") that you are referring to > https://en.wikipedia.org/wiki/Cheat_Engine > > -- > Kurtis Rader > Caretaker of the exceptional canines Junior and Hank > -- 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/6aa2b885-7f13-4743-b2a4-874294a835a9%40googlegroups.com.
[go-nuts] getting values from memory addresses within another process...
I'm attempting to read memory from another process. I've installed 'Cheat Engine' to do this, to make sure I'm pulling the correct value from the address I'm attempting to; however, nothing I found works I did find this article: https://stackoverflow.com/questions/37358478/read-random-memory-locations-with-golang I don't believe that is correct though, as using the address of the location I'm attempting to read doesn't result in a value anywhere near what 'Cheat Engine' is reporting. I've looked at the 'unsafe' and 'syscall' packages; however, there's very little information on them. Also, searched many ways trying to find examples on how to do this. I'm on a Mac (and use Linux). On Windows, I can do this fairly easy. I can't seem to find anything that works (not experienced at all in syscalls) for linux or darwin platforms. Any help appreciated. -- 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/7594fea8-375c-4d90-b829-67ef915444a2%40googlegroups.com.
[go-nuts] Re: Need help with VSCode, GOPATH and intellisense
I only got mine working 99% of the time with a language server configured in my settings: { "go.useLanguageServer": true, "go.languageServerExperimentalFeatures": { "diagnostics": true // for diagnostics as you type }, "[go]": { "editor.snippetSuggestions": "none", "editor.formatOnSave": true, "editor.codeActionsOnSave": { "source.organizeImports": true }, }, "gopls": { "usePlaceholders": true, // add parameter placeholders when completing a function "enhancedHover": true, // experimental to improve quality of hover (will be on by default soon) }, "eslint.autoFixOnSave": true, "prettier.eslintIntegration": true } On Tuesday, May 28, 2019 at 5:32:51 AM UTC-5, Subramanian Sridharan wrote: > > I cannot use intellisense and have my own source packages be recognized at > the same time. > > Golang Server - ON > Infer GOPATH from root - False > GOPATH - Empty > Result - I get details on hover. But my own source package imports fail. > > Golang Server - ON > Infer GOPATH from root - True > GOPATH - Empty > Result - Source package imports don't show error. No information on hover. > > Golang Server - ON > Infer GOPATH from root - False > GOPATH - ~/go:~/dc_native // The src is actually in ~/dc_native/x/y/ > Result - I get details on hover. But my own source package imports fail. > > Golang Server - ON > Infer GOPATH from root - False > GOPATH - ~/go:~dc_native/x/y // Inside which src containing own source > packages are present. > Result - Source package imports don't show error. No information on hover. > > At some point, intellisense was working where I was able to get > suggestions for structure members from another file of the same package. > I can't get that to work now. > > Where am I going wrong? > > PS: The GOPATH paths are actually absolute and not relative. > > > -- 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/30ac3372-a454-4173-8326-cac893894d0a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: How to constant ?!
Whoops... forgot to add the top line to the code syntax. I really wish you could edit existing posts in this group. On Tuesday, May 28, 2019 at 10:03:05 AM UTC-5, Trig wrote: > > package main > > import "fmt" > > const ( > ExposedConstant = "1" // exposed outside of package > internalConstant = "2" // for use anywhere in package only > ) > > func main() { > const functionConstant = "3" // usable anywhere in main func > > fmt.Println(ExposedConstant, internalConstant, functionConstant) > } > > > > On Tuesday, May 28, 2019 at 7:12:06 AM UTC-5, Ashutosh Baghel wrote: >> >> Hello folks, >> >> I want to declare a few variables constant. But I guess there is nothing >> as "Constant" type in GoLang. How do I achieve this in GoLang? >> > -- 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/c9b3b7df-b2da-42ce-bd9e-44ee1eb589ba%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: How to constant ?!
package main import "fmt" const ( ExposedConstant = "1" // exposed outside of package internalConstant = "2" // for use anywhere in package only ) func main() { const functionConstant = "3" // usable anywhere in main func fmt.Println(ExposedConstant, internalConstant, functionConstant) } On Tuesday, May 28, 2019 at 7:12:06 AM UTC-5, Ashutosh Baghel wrote: > > Hello folks, > > I want to declare a few variables constant. But I guess there is nothing > as "Constant" type in GoLang. How do I achieve this in GoLang? > -- 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/77ac85b1-a1d5-4a00-b0de-08681356f32d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Is this possible in Go, and if so how would one do it?
So, I'm creating a package for my service. Let's say I have multiple versions with different features depending on the version and authorization type specified, such as: Authorization Type: ThirdParty Version: 1.0 Utilizes: HMAC_SHA1 hash digest Authorization Type: ThirdParty Version: 1.1 Utilizes: HMAC_SHA1 or HMAC_SHA256 hash digest Authorization Type: Internal Version: 1.0 Utilized: HMAC_SHA512 I'm wanting to construct a configuration setting where the developer using it can set the configuration in a chain, similar to: MyPackage.Initialize(MyPackage.ThirdParty.Version10.HMAC_SHA1) Using intellisense (and using ThirdParty authorization for the example), I only want HMAC_SHA1 to appear if Version10 is specified, and both HMAC_SHA1 and HMAC_SHA256 to appear as options if Version11 in specified in the chain. How would one go about setting this up? I've attempted different strategies utilizing defined types, type functions, etc. and just can't get it to work. Think of it as a treeview. Each section you define only has options available under that specific view... and propagates all the way down the tree. Something like this would be awesome: package MyPackage tree ( ThirdParty { Version10 { HMAC_SHA1 string = "thirdPartyVersion10HmacSha1" } Version11 { HMAC_SHA1 string = "thirdPartyVersion11HmacSha1" HMAC_SHA256 string = "thirdPartyVersion11HmacSha256" } } Internal { Version10 { HMAC_SHA512 string = "internalVersion10HmacSha512" { { } Where the IDE would know to populate intellisense down those paths to the ending defined type (e.g. fmt.Print(MyPackage.ThirdParty.Version11.HMAC_SHA256) would result in "thirdPartyVersion11HmacSha256" being printed)... and the IDE would interpret that and make a map out of it internally or something. Anyhow, hopefully that gives you an idea of what I'm trying to accomplish. Any suggestions would be appreciated! Thanks... -- 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/e2a58aa2-76ec-4099-940d-21996602d317%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Trouble with exiting a for loop that contains bufio.NewScanner.Scan()
When reading from a serial port, there is no EOF between data sets. I may have to use something else besides a scanner to do this. I have a handler function called by a goroutine that just monitors incoming data in a for loop and sends that data coming in back through a channel. If the connection closes, I need a way to signal this loop to close so that the function can return and end. On Sunday, December 30, 2018 at 6:48:21 PM UTC-6, Wagner Riffel wrote: > > Scan() returns false when it reaches EOF or an error, so with what you > provided i assume you're missing to check that. > for ns.Scan() { > ... > } > > or > > for { > if !ns.Scan() { > break > } > > -wgr > > On Sun, Dec 30, 2018 at 10:36 PM Trig > > wrote: > > > > I'm currently utilizing the bufio.NewScanner to read ASCII data from a > serial port. I have the following simple code: > > > > ns := bufio.NewScanner(sPort) > > > > for { > >ns.Scan() > >if ns.Text() != "" { // ignore blank lines > > // handle content here > >} > > } > > > > The problem is ns.Scan() blocks the loop from continuing if there isn't > any data. This leaves me unable to break out of the loop with a for > condition or a select statement also within the loop which is looking for a > close command from a channel before or after it, etc. Am I doing something > wrong, or is there a proper way to handle 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...@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] Trouble with exiting a for loop that contains bufio.NewScanner.Scan()
I'm currently utilizing the bufio.NewScanner to read ASCII data from a serial port. I have the following simple code: ns := bufio.NewScanner(sPort) for { ns.Scan() if ns.Text() != "" { // ignore blank lines // handle content here } } The problem is ns.Scan() blocks the loop from continuing if there isn't any data. This leaves me unable to break out of the loop with a for condition or a select statement also within the loop which is looking for a close command from a channel before or after it, etc. Am I doing something wrong, or is there a proper way to handle 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] Re: go1.11.4.windows-amd64.zip not downloading...
On Thursday, December 20, 2018 at 2:11:59 PM UTC-6, Trig wrote: > > Is anybody able to successfully download from this link? All other > platforms/versions appear to work... just this one isn't doing anything for > me. > > https://golang.org/doc/install?download=go1.11.4.windows-amd64.zip > I take that back. All appear to be working, but it just sits at 0 bytes downloaded and does nothing. If you cancel the download and try again, you never even get the download dialog that usually pops up. -- 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] go1.11.4.windows-amd64.zip not downloading...
Is anybody able to successfully download from this link? All other platforms/versions appear to work... just this one isn't doing anything for me. https://golang.org/doc/install?download=go1.11.4.windows-amd64.zip -- 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] timeout with bufio.Scanner & Scanner.Scan()
I'm currently reading ASCII data from a serial port using the bufio.Scanner (since what's coming back is a line at a time, it's convenient w/ reading using the Scanner.Text()). Problem is, the for loop I use to process the reads lock at the Scanner.Scan() call. Is there a to implement some for loop that utilized the scanner while utilizing a timeout? I've tried: for { select { case <- time.After(time.Second * 3): response <- &Response{ Error: fmt.Errorf("command call took to long for a response"), } break default: myScanner.Scan() if myScanner.Text() == "OK" { response <- &Response{ Content: []responseLines, } break } responseLines = append(responseLines, myScanner.Text()) } } Of course, after looking at it... it makes sense why it's not working as the loop locks at myScanner.Scan() if there is nothing further to Scan. Any help or examples would be appreciated. -- 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 reflect to utilized the call to gob.Register()?
Is it possible, somehow, to use reflection to utilize the call to gob.Register()? Something like: gob.Register(m.Type().In(0)) Problem I'm having is that m.Type().In(0) is a type of *reflect.rtype, so it registers that... and not the actual type being reflected. -- 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] Windows 10 x64 - the program can't start because libz-1.dll is missing from your computer.
Compiled a small app w/ Go 1.11 and only used one 3rd-party import ("github.com/go-vgo/robotgo"). GOARCH=amd64; GOOS=windows. Runs fine on the computer I used to build it. I copy it in a VMWARE instance of Windows 10 x64, and I get that 'libz-1.dll' is missing from your computer when I try to execute it. I thought go binaries contained everything needed to run itself, assuming the platforms for compiling and executing matched? Anybody have any ideas what's going on, and why this happened? -- 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: Any interest for an online "Go programming" degree ?
There are already so many good courses available out there, and most employers either do white-boarding, a coding challenge, or want to see some existing code on a public repo such as Github.com. So, IMHO... even with a 'certificate' or 'degree', that would likely not change these requirements|requests from such employers. They want to see whether you know your stuff, regardless of experience or schooling. That's what matters in the end. On Saturday, February 3, 2018 at 10:45:22 AM UTC-6, Sylvain wrote: > > Hi, > > I am now working as "head of code and design education" at the leading > Online Learning Company in France, operating from the heart of Paris. > > We offer government certified degrees (very important in France! employers > will offer you an interview depending on which degrees you put on your > resume, not what you can do :) ) > > We do Java, PHP, Python, even Ruby... I would love to create a programming > degree based on Go - starting from scratch, so as to learn the good > practises from the beginning > > If you work at a company operating in France, use Go and struggle to hire > good programmers, I would love to hear from you so as to > > 1) make a good case to justify the creation of this degree > 2) make sure the learning objectives align with your needs > > Thanks for your time > > Sylvain > -- 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] Decoder.DisallowUnknownFields() works when passing *struct but not *map[string]interface{}
I dunno... it doesn't seem to satisfy this check, even though the article you sent me states maps are pointers (but does satisfy == reflect.Map). Doesn't the unmarshaller check for a pointer using == reflect.Ptr before it does anything? I haven't looked at it lately (can't atm, so going on memory)... but I think it does. https://play.golang.org/p/lX7P2FtRlMo On Tuesday, January 30, 2018 at 9:29:09 AM UTC-6, Trig wrote: > > I guess it's not needed. I know that the json unmarshaller requires a > pointer to a struct... so for consistency, I was just stating it as a > pointer. I had no idea that make(map) returns *hmap. > > On Tuesday, January 30, 2018 at 9:13:28 AM UTC-6, matthe...@gmail.com > wrote: >> >> Dave talks about map representation here: >> https://dave.cheney.net/2017/04/30/if-a-map-isnt-a-reference-variable-what-is-it >> >> I don’t understand why you need a pointer to a map, can you provide a >> code example? >> >> Matt >> >> On Tuesday, January 30, 2018 at 8:22:54 AM UTC-6, Trig wrote: >>> >>> Appreciate the response. I'm wanting to pass a *map[string]interface{} >>> where the keys (strings) are already populated. I'm thinking of just >>> creating a func which does this itself... checks to see if the keys exists >>> and populate accordingly, and if not... return an error. Don't think this >>> will be too difficult; however, would be a nice feature to discuss about >>> being implemented into the json standard library. >>> >>> On Tuesday, January 30, 2018 at 5:31:01 AM UTC-6, Konstantin Khomoutov >>> wrote: >>>> >>>> On Sun, Jan 28, 2018 at 10:59:58AM -0800, Trig wrote: >>>> >>>> > This works as intended when you pass it a pointer to a Struct; >>>> however, it >>>> > should also work (you would think, since the Unmarshaller can handle >>>> both >>>> > types) a pointer to a *map[string]interface{}; however, it does not. >>>> Are >>>> > there any future plans to implement this option on both types? >>>> >>>> You're talking about [1], are you? >>>> >>>> If yes, the commit [2] which closed it specifically talks about struct >>>> types, so the function behaves as documented. >>>> >>>> On the other hand, I have two questions to narrow the scope of your >>>> claim down. >>>> >>>> - To carry out its intended task, DisallowUnknownFields() has to >>>> operate >>>>on a value which it can use to figure out the set of known fields. >>>> >>>>In the case of a map this suggests that the map passed to that >>>> method >>>>must be populated with the keys which would define the names of >>>>the known fields (and the values assigned to those keys are expected >>>>to be overwritten by the decoding process). Is this what you're >>>> proposing? >>>> >>>> - Why a pointer to a map? >>>> >>>>In my eyes, this suggests that you may legitimately pass a pointer >>>>to an unitialized map value and expect the decoder to create one for >>>>you; is that correct? >>>> >>>>If "yes" is the answer to the both points, they cannot be satisfied >>>>together: to fulfill the first requirement the map value must be >>>> non-nil, >>>>and you cannot expect the decoder to initialize it for you. >>>> >>>> All in all, I suggest you to create a proposal in the issue tracker. >>>> Just be sure to be crystal clear, when laying it out -- to save the >>>> devs >>>> from guessing what you really meant. >>>> >>>> 1. https://github.com/golang/go/issues/15314 >>>> 2. >>>> https://github.com/golang/go/commit/2596a0c075aeddec571cd658f748ac7a712a2b69 >>>> >>>> >>>> -- 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] Decoder.DisallowUnknownFields() works when passing *struct but not *map[string]interface{}
I guess it's not needed. I know that the json unmarshaller requires a pointer to a struct... so for consistency, I was just stating it as a pointer. I had no idea that make(map) returns *hmap. On Tuesday, January 30, 2018 at 9:13:28 AM UTC-6, matthe...@gmail.com wrote: > > Dave talks about map representation here: > https://dave.cheney.net/2017/04/30/if-a-map-isnt-a-reference-variable-what-is-it > > I don’t understand why you need a pointer to a map, can you provide a code > example? > > Matt > > On Tuesday, January 30, 2018 at 8:22:54 AM UTC-6, Trig wrote: >> >> Appreciate the response. I'm wanting to pass a *map[string]interface{} >> where the keys (strings) are already populated. I'm thinking of just >> creating a func which does this itself... checks to see if the keys exists >> and populate accordingly, and if not... return an error. Don't think this >> will be too difficult; however, would be a nice feature to discuss about >> being implemented into the json standard library. >> >> On Tuesday, January 30, 2018 at 5:31:01 AM UTC-6, Konstantin Khomoutov >> wrote: >>> >>> On Sun, Jan 28, 2018 at 10:59:58AM -0800, Trig wrote: >>> >>> > This works as intended when you pass it a pointer to a Struct; >>> however, it >>> > should also work (you would think, since the Unmarshaller can handle >>> both >>> > types) a pointer to a *map[string]interface{}; however, it does not. >>> Are >>> > there any future plans to implement this option on both types? >>> >>> You're talking about [1], are you? >>> >>> If yes, the commit [2] which closed it specifically talks about struct >>> types, so the function behaves as documented. >>> >>> On the other hand, I have two questions to narrow the scope of your >>> claim down. >>> >>> - To carry out its intended task, DisallowUnknownFields() has to >>> operate >>>on a value which it can use to figure out the set of known fields. >>> >>>In the case of a map this suggests that the map passed to that method >>>must be populated with the keys which would define the names of >>>the known fields (and the values assigned to those keys are expected >>>to be overwritten by the decoding process). Is this what you're >>> proposing? >>> >>> - Why a pointer to a map? >>> >>>In my eyes, this suggests that you may legitimately pass a pointer >>>to an unitialized map value and expect the decoder to create one for >>>you; is that correct? >>> >>>If "yes" is the answer to the both points, they cannot be satisfied >>>together: to fulfill the first requirement the map value must be >>> non-nil, >>>and you cannot expect the decoder to initialize it for you. >>> >>> All in all, I suggest you to create a proposal in the issue tracker. >>> Just be sure to be crystal clear, when laying it out -- to save the devs >>> from guessing what you really meant. >>> >>> 1. https://github.com/golang/go/issues/15314 >>> 2. >>> https://github.com/golang/go/commit/2596a0c075aeddec571cd658f748ac7a712a2b69 >>> >>> >>> -- 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] Decoder.DisallowUnknownFields() works when passing *struct but not *map[string]interface{}
Appreciate the response. I'm wanting to pass a *map[string]interface{} where the keys (strings) are already populated. I'm thinking of just creating a func which does this itself... checks to see if the keys exists and populate accordingly, and if not... return an error. Don't think this will be too difficult; however, would be a nice feature to discuss about being implemented into the json standard library. On Tuesday, January 30, 2018 at 5:31:01 AM UTC-6, Konstantin Khomoutov wrote: > > On Sun, Jan 28, 2018 at 10:59:58AM -0800, Trig wrote: > > > This works as intended when you pass it a pointer to a Struct; however, > it > > should also work (you would think, since the Unmarshaller can handle > both > > types) a pointer to a *map[string]interface{}; however, it does not. > Are > > there any future plans to implement this option on both types? > > You're talking about [1], are you? > > If yes, the commit [2] which closed it specifically talks about struct > types, so the function behaves as documented. > > On the other hand, I have two questions to narrow the scope of your > claim down. > > - To carry out its intended task, DisallowUnknownFields() has to operate >on a value which it can use to figure out the set of known fields. > >In the case of a map this suggests that the map passed to that method >must be populated with the keys which would define the names of >the known fields (and the values assigned to those keys are expected >to be overwritten by the decoding process). Is this what you're > proposing? > > - Why a pointer to a map? > >In my eyes, this suggests that you may legitimately pass a pointer >to an unitialized map value and expect the decoder to create one for >you; is that correct? > >If "yes" is the answer to the both points, they cannot be satisfied >together: to fulfill the first requirement the map value must be > non-nil, >and you cannot expect the decoder to initialize it for you. > > All in all, I suggest you to create a proposal in the issue tracker. > Just be sure to be crystal clear, when laying it out -- to save the devs > from guessing what you really meant. > > 1. https://github.com/golang/go/issues/15314 > 2. > https://github.com/golang/go/commit/2596a0c075aeddec571cd658f748ac7a712a2b69 > > -- 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 []Interface{} indexing failing at if statement
Actually, Jan's way is probably the best... as if you wrongfully type convert the wrong type, it'll panic (you'll need to know for sure that arr in this instance will always be a boolean). With Jan's way, you're just making a comparison of value... which will work regardless of the type. On Monday, January 29, 2018 at 1:52:38 PM UTC-6, Trig wrote: > > This... or just specify the type after 'arr' such as: > > if arr.(bool) { > fmt.Println("This is a boolean value") > } > > > On Monday, January 29, 2018 at 5:41:17 AM UTC-6, Jan Mercl wrote: >> >> On Mon, Jan 29, 2018 at 12:36 PM pradam wrote: >> >> > //here its throwing error like: non-boolean condition in if statement >> >> The compiler is right. 'arr' is not a boolean expresion, its type is >> 'interface{}'. Try: https://play.golang.org/p/zwNV9RD2oCs. >> >> -- >> >> -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 []Interface{} indexing failing at if statement
This... or just specify the type after 'arr' such as: if arr.(bool) { fmt.Println("This is a boolean value") } On Monday, January 29, 2018 at 5:41:17 AM UTC-6, Jan Mercl wrote: > > On Mon, Jan 29, 2018 at 12:36 PM pradam > wrote: > > > //here its throwing error like: non-boolean condition in if statement > > The compiler is right. 'arr' is not a boolean expresion, its type is > 'interface{}'. Try: https://play.golang.org/p/zwNV9RD2oCs. > > -- > > -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.
[go-nuts] Re: best package for serial port io access in golang?
I've only used https://github.com/tarm/serial and it hasn't let me down yet. It's simple and light-weight... does its job. Nothing more... nothing less. On Sunday, January 28, 2018 at 1:54:05 PM UTC-6, John Moore wrote: > > Hi, > I need to talk to external devices with serial (probably just over a USB > dongle), and do it from both Windows and Mac. > > I see a few libraries out there but little talk about this. > > Is anyone doing serial work with golang these days? Are there best > libraries? If so, can one avoid hanging forever waiting to receive data > that will never arrive? > > John > -- 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] Decoder.DisallowUnknownFields() works when passing *struct but not *map[string]interface{}
This works as intended when you pass it a pointer to a Struct; however, it should also work (you would think, since the Unmarshaller can handle both types) a pointer to a *map[string]interface{}; however, it does not. Are there any future plans to implement this option on both 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. For more options, visit https://groups.google.com/d/optout.
[go-nuts] json struct tag
I've searched but can't find any good sources on json struct tag options and rules... Does the order in which the options in the tag appear matter (e.g. `json:"first_name,omitempty"` vs `json:"omitempty,first_name"`) ? -- 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 this safe?
for i, user := range myList { if user.Disabled { myList = append(myList[:i], myList[i + 1:]...) // remove user from return list } } Is using append this way (to remove an index), inside of the range loop of the same array I'm working with, safe... since the size of myList is being changed within it? -- 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: Why is there a difference between floating-point multiplication with literals vs. variables in Go?
There are 3rd-party packages/vendors that help with this, such as: https://github.com/shopspring/decimal On Thursday, November 9, 2017 at 5:36:03 PM UTC-6, Erik Swan wrote: > > Why are the following unequal in Go? Is this a bug, or is it by design? If > it's by design, why does this occur and is this type of behavior documented > anywhere? > > https://play.golang.org/p/itEV9zwV2a > > package main > > import ( > "fmt" > ) > > func main() { > x := 10.1 > > fmt.Println("x == 10.1:", x == 10.1) > fmt.Println("x*3.0 == 10.1*3.0:", x*3.0 == 10.1*3.0) > fmt.Println("x*3.0:", x*3.0) > fmt.Println("10.1*3.0: ", 10.1*3.0) > } > > Produces: > > x == 10.1: true > x*3.0 == 10.1*3.0: false > x*3.0: 30.297 > 10.1*3.0: 30.3 > > > -- 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] interface{} as type []interface{}
Is it possible to have an interface{} as type []interface{}? -- 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] Get method/function parameter types with reflect?
Thank you! You lead me in the right direction. It was .In() and .Out() I was looking for. Appreciate it, Ian. On Thursday, October 12, 2017 at 6:12:41 PM UTC-5, Ian Lance Taylor wrote: > > On Thu, Oct 12, 2017 at 3:03 PM, burpswangy > wrote: > > > > Is it possible to use the reflect package to get the parameter/function > > types for a specified method/function? > > I'm not sure precisely what you are asking, but the answer is probably > yes. Start with something like reflect.ValueOf(myFunction).Type(). > > Ian > -- 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.