Re: [go-nuts] Printf
Luca, thanks for your answerr El viernes, 2 de febrero de 2024 a la(s) 3:06:17 p.m. UTC-3, Luca Pascali escribió: > you forgot the \n in the printf format string > > without it, next is written right after the end of the printf > > > Psk > > Il ven 2 feb 2024, 17:56 Juan Mamani ha scritto: > >> Hi everybody! >> >> I was checking consistency behavior of fmt.Printf with some basic >> samples. And for my surprise never expected what I found. >> >> My context: >> OS: Linux, debian 8,9,10,11 >> Go version 1.21 >> >> What I was doing? Learning about fmt.Printf >> Expecting fmt.Printf behavior be the same output for any use case. >> >> Source code: https://go.dev/play/p/oKifC9Lw-JO >> >> >> Ouput: >> g_x 15.9259995 >> 15.91.6241.624<- for me this is freaking weird ouput >> -- >> x2: 1.624 >> x2: 1.624 >> x1: 15.9259996 >> -- >> j: 4 >> k: 5 >> p: 1.624 >> >> May be I found compiler bug? Can someone help me to figure out what is >> going on. >> >> Thank you for your attention >> >> -- >> > 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. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/0b8e4c5a-ceef-49e8-8546-bcd51200ff35n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/0b8e4c5a-ceef-49e8-8546-bcd51200ff35n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- 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/02f81760-5bab-4a0a-b35b-2c6e652e18bdn%40googlegroups.com.
Re: [go-nuts] Printf
Kurtis, thanks for your reply. El viernes, 2 de febrero de 2024 a la(s) 2:12:55 p.m. UTC-3, Kurtis Rader escribió: > I think you're being confused by the lack of newlines in the output. Add > "\n" to the end of the printf format. > > On Fri, Feb 2, 2024 at 8:56 AM Juan Mamani wrote: > >> Hi everybody! >> >> I was checking consistency behavior of fmt.Printf with some basic >> samples. And for my surprise never expected what I found. >> >> My context: >> OS: Linux, debian 8,9,10,11 >> Go version 1.21 >> >> What I was doing? Learning about fmt.Printf >> Expecting fmt.Printf behavior be the same output for any use case. >> >> Source code: https://go.dev/play/p/oKifC9Lw-JO >> >> >> Ouput: >> g_x 15.9259995 >> 15.91.6241.624<- for me this is freaking weird ouput >> -- >> x2: 1.624 >> x2: 1.624 >> x1: 15.9259996 >> -- >> j: 4 >> k: 5 >> p: 1.624 >> >> May be I found compiler bug? Can someone help me to figure out what is >> going on. >> >> Thank you for your attention >> >> -- >> 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. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/0b8e4c5a-ceef-49e8-8546-bcd51200ff35n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/0b8e4c5a-ceef-49e8-8546-bcd51200ff35n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > 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/4231a4fe-c9e5-461b-8d94-bfcd25260a5cn%40googlegroups.com.
[go-nuts] Printf
Hi everybody! I was checking consistency behavior of fmt.Printf with some basic samples. And for my surprise never expected what I found. My context: OS: Linux, debian 8,9,10,11 Go version 1.21 What I was doing? Learning about fmt.Printf Expecting fmt.Printf behavior be the same output for any use case. Source code: https://go.dev/play/p/oKifC9Lw-JO Ouput: g_x 15.9259995 15.91.6241.624<- for me this is freaking weird ouput -- x2: 1.624 x2: 1.624 x1: 15.9259996 -- j: 4 k: 5 p: 1.624 May be I found compiler bug? Can someone help me to figure out what is going on. Thank you for your attention -- 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/0b8e4c5a-ceef-49e8-8546-bcd51200ff35n%40googlegroups.com.
Re: [go-nuts] Understind how to apply timeout using gouritine
Hi Brian, Thanks for your help. I will try out to implement your samples in my project. But still studying Goroutines and now Context. El miércoles, 26 de febrero de 2020, 10:41:26 (UTC-3), Brian Candler escribió: > > Perhaps slightly clearer: > https://play.golang.org/p/DDZxqaEFi-T > > -- 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/9461a095-a8a5-4511-8436-e0f314817568%40googlegroups.com.
Re: [go-nuts] Understind how to apply timeout using gouritine
Hi Michel, I've tried your sample with this result: 2020/02/25 23:12:51.854561 Stop in 2s 2020/02/25 23:12:51.854710 Hey! 2020/02/25 23:12:57.854967 Bye Bye! But function still running."Bye Bye" appeared +6s later. I will check Context package as you recomended me. Thanks! El martes, 25 de febrero de 2020, 5:43:00 (UTC-3), Michel Levieux escribió: > > Hi Juan, > > You cannot terminate a function execution from its caller if you did not > pass it an argument (most likely a channel) which it can use to communicate > with its caller, and terminate itself when the timeout is reached. > The simplest example I can think of is the following: > https://play.golang.org/p/KVQ7uhiWr7H, though I'm not quite sure this is > your question, since it looks like you've already experimented with this > construct. > > You can trick with signals and other constructs but channels are designed > for that kind of need, so I suppose this is the best way to go. If you want > something that wraps this behaviour because you need the timeout to follow > the logic of your program, maybe package https://golang.org/pkg/context/ > can help you. > > Hope this was useful! > > Le mar. 25 févr. 2020 à 00:45, Juan Mamani > a écrit : > >> Sorry again. Well, I followed your advice. Here is the link >> https://play.golang.org/p/7DigEVsKbdx >> How can I cancel goToSleep() when timeout is reached? >> >> >> El lunes, 24 de febrero de 2020, 14:16:32 (UTC-3), Jake Montgomery >> escribió: >>> >>> Your code will still not compile. In this group, it is often helpful to >>> include a link to your code in the playground (https://play.golang.org/) >>> using the "Share" button. That is in addition to, or instead of, posting >>> your code in the message. This will allow others to easily run your code, >>> but also will allow you to make sure it compiles. >>> >>> On Monday, February 24, 2020 at 10:01:01 AM UTC-5, Juan Mamani wrote: >>>> >>>> Sorry}, here is the right code: ( just was the effect to b working til >>>> At 5:20am sleepy and lost) >>>> >>>> Expected behaviour is to end anonyimous func when 3s timeout is >>>> reached. >>>> >>>> // >>>> package main >>>> >>>> import( >>>> //"fmt" >>>> "time" >>>> "math/rand" >>>> "log" >>>> ) >>>> >>>> func main(){ >>>> >>>> for{ >>>>log.Println("-Start") >>>>Task() >>>>log.Println("-End") >>>> >>>> } >>>> >>>> } >>>> >>>> >>>> // Trying to adapt from Concurrency in Go by Katherine Cox-Buday >>>> func Task(){ >>>> >>>> doWork := func( done <-chan interface{}, strings <-chan string, ) >>>> <-chan interface{} { //1 >>>> terminated := make(chan interface{}) >>>> go func() { >>>> defer log.Println("doWork exited.") >>>> defer close(terminated) >>>> for { >>>> goToSleep() >>>> select { >>>> //case s := <-strings: >>>> // case s := ran(): >>>> // Do something interesting >>>> //fmt.Println(s) >>>> case <-done: //2 >>>> return >>>> } >>>> } >>>> }() >>>> return terminated >>>> } >>>> >>>> done := make(chan interface{}) >>>> terminated := doWork(done, nil) >>>> >>>> go func() { //3 >>>> // Cancel the operation after 3 second. >>>> time.Sleep(3 * time.Second) >>>> log.Println("Canceling doWork goroutine reach 3s...") >>>> close(done) >>>> }() >>>> >>>> <-terminated //4 >>>> log.Println("Done.") >>>> } >>>> >>>> done := make(chan interface{}) >>>> terminated := doWork(done, nil) >>>> >>>> go func() { //3 >>>> // Cancel the operation after 3 second. >>>> time.Sleep(3 * time.Second) >>>> log.Println
Re: [go-nuts] Understind how to apply timeout using gouritine
Ok, you are right. But I was confused with this: 2009/11/10 23:00:00 -Start 2009/11/10 23:00:00 Sleeping 8 seconds..2009/11/10 23:00:03 Canceling doWork goroutine reach 3s...2009/11/10 23:00:08 Done sleeping! 2009/11/10 23:00:08 doWork exited. 2009/11/10 23:00:08 Done. 2009/11/10 23:00:08 -End My previous questions were: How can I cancel execution of goToSleep() function? How can I break it? Because I expect code to stop function gotoTosleep() at 3s, but I saw still running at 8s because prints "Done sleeping!".. But Michael Levieux got the idea and repliedr:"You cannot terminate a function execution from its caller.." . So I was wrong in my understanding how to implement "cancel" or "break" goroutinea. El martes, 25 de febrero de 2020, 13:45:03 (UTC-3), Jake Montgomery escribió: > > Expected behaviour is to end anonyimous func when 3s timeout is reached. >> > > So what is the problem? The whole thing *does *exit after 3 seconds. Of > course, your main() is a loop, so it starts again. > > 2009/11/10 23:00:00 -Start > 2009/11/10 23:00:03 Canceling doWork goroutine reach 3s... > 2009/11/10 23:00:03 doWork exited. > 2009/11/10 23:00:03 Done. > 2009/11/10 23:00:03 -End > > > What exactly did you expect to see other than that? > > On Monday, February 24, 2020 at 6:45:26 PM UTC-5, Juan Mamani wrote: >> >> Sorry again. Well, I followed your advice. Here is the link >> https://play.golang.org/p/7DigEVsKbdx >> How can I cancel goToSleep() when timeout is reached? >> >> >> El lunes, 24 de febrero de 2020, 14:16:32 (UTC-3), Jake Montgomery >> escribió: >>> >>> Your code will still not compile. In this group, it is often helpful to >>> include a link to your code in the playground (https://play.golang.org/) >>> using the "Share" button. That is in addition to, or instead of, posting >>> your code in the message. This will allow others to easily run your code, >>> but also will allow you to make sure it compiles. >>> >>> On Monday, February 24, 2020 at 10:01:01 AM UTC-5, Juan Mamani wrote: >>>> >>>> Sorry}, here is the right code: ( just was the effect to b working til >>>> At 5:20am sleepy and lost) >>>> >>>> Expected behaviour is to end anonyimous func when 3s timeout is >>>> reached. >>>> >>>> // >>>> package main >>>> >>>> import( >>>> //"fmt" >>>> "time" >>>> "math/rand" >>>> "log" >>>> ) >>>> >>>> func main(){ >>>> >>>> for{ >>>>log.Println("-Start") >>>>Task() >>>>log.Println("-End") >>>> >>>> } >>>> >>>> } >>>> >>>> >>>> // Trying to adapt from Concurrency in Go by Katherine Cox-Buday >>>> func Task(){ >>>> >>>> doWork := func( done <-chan interface{}, strings <-chan string, ) >>>> <-chan interface{} { //1 >>>> terminated := make(chan interface{}) >>>> go func() { >>>> defer log.Println("doWork exited.") >>>> defer close(terminated) >>>> for { >>>> goToSleep() >>>> select { >>>> //case s := <-strings: >>>> // case s := ran(): >>>> // Do something interesting >>>> //fmt.Println(s) >>>> case <-done: //2 >>>> return >>>> } >>>> } >>>> }() >>>> return terminated >>>> } >>>> >>>> done := make(chan interface{}) >>>> terminated := doWork(done, nil) >>>> >>>> go func() { //3 >>>> // Cancel the operation after 3 second. >>>> time.Sleep(3 * time.Second) >>>> log.Println("Canceling doWork goroutine reach 3s...") >>>> close(done) >>>> }() >>>> >>>> <-terminated //4 >>>> log.Println("Done.") >>>> } >>>> >>>> done := make(chan interface{}) >>>> terminated := doWork(done, nil) >>>> >>>&
Re: [go-nuts] Understind how to apply timeout using gouritine
Reallly thanks for your help and guide! El martes, 25 de febrero de 2020, 5:45:17 (UTC-3), Michel Levieux escribió: > > Edit: I said "communicate with its caller" but in practice it might as > well be another goroutine or the caller of the caller, either way the > construct and the logic standing behind it are exactly the same :) > > Le mar. 25 févr. 2020 à 09:42, Michel Levieux > a écrit : > >> Hi Juan, >> >> You cannot terminate a function execution from its caller if you did not >> pass it an argument (most likely a channel) which it can use to communicate >> with its caller, and terminate itself when the timeout is reached. >> The simplest example I can think of is the following: >> https://play.golang.org/p/KVQ7uhiWr7H, though I'm not quite sure this is >> your question, since it looks like you've already experimented with this >> construct. >> >> You can trick with signals and other constructs but channels are designed >> for that kind of need, so I suppose this is the best way to go. If you want >> something that wraps this behaviour because you need the timeout to follow >> the logic of your program, maybe package https://golang.org/pkg/context/ >> can help you. >> >> Hope this was useful! >> >> Le mar. 25 févr. 2020 à 00:45, Juan Mamani > > a écrit : >> >>> Sorry again. Well, I followed your advice. Here is the link >>> https://play.golang.org/p/7DigEVsKbdx >>> How can I cancel goToSleep() when timeout is reached? >>> >>> >>> El lunes, 24 de febrero de 2020, 14:16:32 (UTC-3), Jake Montgomery >>> escribió: >>>> >>>> Your code will still not compile. In this group, it is often helpful to >>>> include a link to your code in the playground (https://play.golang.org/) >>>> using the "Share" button. That is in addition to, or instead of, posting >>>> your code in the message. This will allow others to easily run your code, >>>> but also will allow you to make sure it compiles. >>>> >>>> On Monday, February 24, 2020 at 10:01:01 AM UTC-5, Juan Mamani wrote: >>>>> >>>>> Sorry}, here is the right code: ( just was the effect to b working >>>>> til At 5:20am sleepy and lost) >>>>> >>>>> Expected behaviour is to end anonyimous func when 3s timeout is >>>>> reached. >>>>> >>>>> // >>>>> package main >>>>> >>>>> import( >>>>> //"fmt" >>>>> "time" >>>>> "math/rand" >>>>> "log" >>>>> ) >>>>> >>>>> func main(){ >>>>> >>>>> for{ >>>>>log.Println("-Start") >>>>>Task() >>>>>log.Println("-End") >>>>> >>>>> } >>>>> >>>>> } >>>>> >>>>> >>>>> // Trying to adapt from Concurrency in Go by Katherine Cox-Buday >>>>> func Task(){ >>>>> >>>>> doWork := func( done <-chan interface{}, strings <-chan string, ) >>>>> <-chan interface{} { //1 >>>>> terminated := make(chan interface{}) >>>>> go func() { >>>>> defer log.Println("doWork exited.") >>>>> defer close(terminated) >>>>> for { >>>>> goToSleep() >>>>> select { >>>>> //case s := <-strings: >>>>> // case s := ran(): >>>>> // Do something interesting >>>>> //fmt.Println(s) >>>>> case <-done: //2 >>>>> return >>>>> } >>>>> } >>>>> }() >>>>> return terminated >>>>> } >>>>> >>>>> done := make(chan interface{}) >>>>> terminated := doWork(done, nil) >>>>> >>>>> go func() { //3 >>>>> // Cancel the operation after 3 second. >>>>> time.Sleep(3 * time.Second) >>>>> log.Println("Canceling doWork goroutine reach 3s...") >>>>> close(done) >>>>> }
Re: [go-nuts] Understind how to apply timeout using gouritine
Sorry again. Well, I followed your advice. Here is the link https://play.golang.org/p/7DigEVsKbdx How can I cancel goToSleep() when timeout is reached? El lunes, 24 de febrero de 2020, 14:16:32 (UTC-3), Jake Montgomery escribió: > > Your code will still not compile. In this group, it is often helpful to > include a link to your code in the playground (https://play.golang.org/) > using the "Share" button. That is in addition to, or instead of, posting > your code in the message. This will allow others to easily run your code, > but also will allow you to make sure it compiles. > > On Monday, February 24, 2020 at 10:01:01 AM UTC-5, Juan Mamani wrote: >> >> Sorry}, here is the right code: ( just was the effect to b working til >> At 5:20am sleepy and lost) >> >> Expected behaviour is to end anonyimous func when 3s timeout is >> reached. >> >> // >> package main >> >> import( >> //"fmt" >> "time" >> "math/rand" >> "log" >> ) >> >> func main(){ >> >> for{ >>log.Println("-Start") >>Task() >>log.Println("-End") >> >> } >> >> } >> >> >> // Trying to adapt from Concurrency in Go by Katherine Cox-Buday >> func Task(){ >> >> doWork := func( done <-chan interface{}, strings <-chan string, ) <-chan >> interface{} { //1 >> terminated := make(chan interface{}) >> go func() { >> defer log.Println("doWork exited.") >> defer close(terminated) >> for { >> goToSleep() >> select { >> //case s := <-strings: >> // case s := ran(): >> // Do something interesting >> //fmt.Println(s) >> case <-done: //2 >> return >> } >> } >> }() >> return terminated >> } >> >> done := make(chan interface{}) >> terminated := doWork(done, nil) >> >> go func() { //3 >> // Cancel the operation after 3 second. >> time.Sleep(3 * time.Second) >> log.Println("Canceling doWork goroutine reach 3s...") >> close(done) >> }() >> >> <-terminated //4 >> log.Println("Done.") >> } >> >> done := make(chan interface{}) >> terminated := doWork(done, nil) >> >> go func() { //3 >> // Cancel the operation after 3 second. >> time.Sleep(3 * time.Second) >> log.Println("Canceling doWork goroutine reach 3s...") >> close(done) >> }() >> >> <-terminated //4 >> log.Println("Done.") >> } >> >> >> >> func goToSleep(){ >> >> >> >> >> rand.Seed(time.Now().UnixNano()) >> n := rand.Intn(12) // n will be between 0 and 10 >> log.Println("Sleeping ",n,"seconds..") >> time.Sleep(time.Duration(n)*time.Second) >> log.Println("Done sleeping!") >> } >> >> // >> >> >> >> El lunes, 24 de febrero de 2020, 6:09:09 (UTC-3), Lutz Horn escribió: >>> >>> > I've tried to adapt from from "Concurrency in Go by Katherine >>> Cox-Buday" to >>> > understand how to apply timeout. But I don't get it. >>> >>> What are you trying to do? What is the expected behaviour, what happens >>> instead? >>> >>> BTW, this code does not compile, there are same unbalanced curly >>> brackets. >>> >>> Lutz >>> >> -- 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/b0828575-fddf-4024-bec0-8faf5b9858a4%40googlegroups.com.
Re: [go-nuts] Understind how to apply timeout using gouritine
Sorry}, here is the right code: ( just was the effect to b working til At 5:20am sleepy and lost) Expected behaviour is to end anonyimous func when 3s timeout is reached. // package main import( //"fmt" "time" "math/rand" "log" ) func main(){ for{ log.Println("-Start") Task() log.Println("-End") } } // Trying to adapt from Concurrency in Go by Katherine Cox-Buday func Task(){ doWork := func( done <-chan interface{}, strings <-chan string, ) <-chan interface{} { //1 terminated := make(chan interface{}) go func() { defer log.Println("doWork exited.") defer close(terminated) for { goToSleep() select { //case s := <-strings: // case s := ran(): // Do something interesting //fmt.Println(s) case <-done: //2 return } } }() return terminated } done := make(chan interface{}) terminated := doWork(done, nil) go func() { //3 // Cancel the operation after 3 second. time.Sleep(3 * time.Second) log.Println("Canceling doWork goroutine reach 3s...") close(done) }() <-terminated //4 log.Println("Done.") } done := make(chan interface{}) terminated := doWork(done, nil) go func() { //3 // Cancel the operation after 3 second. time.Sleep(3 * time.Second) log.Println("Canceling doWork goroutine reach 3s...") close(done) }() <-terminated //4 log.Println("Done.") } func goToSleep(){ rand.Seed(time.Now().UnixNano()) n := rand.Intn(12) // n will be between 0 and 10 log.Println("Sleeping ",n,"seconds..") time.Sleep(time.Duration(n)*time.Second) log.Println("Done sleeping!") } // El lunes, 24 de febrero de 2020, 6:09:09 (UTC-3), Lutz Horn escribió: > > > I've tried to adapt from from "Concurrency in Go by Katherine Cox-Buday" > to > > understand how to apply timeout. But I don't get it. > > What are you trying to do? What is the expected behaviour, what happens > instead? > > BTW, this code does not compile, there are same unbalanced curly brackets. > > Lutz > -- 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/abe7d907-a8b9-4e88-9451-1114ab577199%40googlegroups.com.
[go-nuts] Understind how to apply timeout using gouritine
Hi everybody, I've tried to adapt from from "Concurrency in Go by Katherine Cox-Buday" to understand how to apply timeout. But I don't get it. What I'm doing wrong? Here the code: package main import( //"fmt" "time" "math/rand" "log" ) func main(){ // infinity loop for{ log.Println("-Start") Task() log.Println("-End") } } // Trying to adapt from Concurrency in Go by Katherine Cox-Buday func Task(){ doWork := func( done <-chan interface{}, strings <-chan string, ) <-chan interface{} { //1 terminated := make(chan interface{}) go func() { defer log.Println("doWork exited.") defer close(terminated) for { goToSleep() select { //case s := <-strings: // case s := ran(): // Do something interesting //fmt.Println(s) case <-done: //2 return } } }() } done := make(chan interface{}) terminated := doWork(done, nil) go func() { //3 // Cancel the operation after 3 second. time.Sleep(3 * time.Second) log.Println("Canceling doWork goroutine reach 3s...") close(done) }()
Re: [go-nuts] Issue using json with array
Thanks Tomás! now reading info about Marshal El sábado, 2 de febrero de 2019, 20:24:36 (UTC-3), Tomás González Dowling escribió: > > Not sure if that was a question, Juan. But you can use Marshal method in > the encoding/json package to avoid using make. There are some examples in > the official docs: https://golang.org/pkg/encoding/json/#example_Marshal > > Hope that it helps :) > > El mié., 19 dic. 2018 a las 9:44, Juan Mamani ( >) escribió: > >> Thanks a lot for your reply!! You are right it's working. >> >> But, it could be possible to avoid calling "make"... >> >> El mié., 19 de dic. de 2018 a la(s) 08:14, Ozone Kawakami ( >> kawakam...@gmail.com ) escribió: >> >>> Your code `make(pos, 1)` seems to be typo. >>> The fixed version works well. >>> https://play.golang.org/p/gnLe_Xi2-nb >>> >>> 2018年12月19日(水) 10:40 Juan Mamani >: >>> >>>> I'm not an expert but I do my best. >>>> >>>> Original json format required: >>>> { "pos": [{ "lp" : "WISE-12", "lat": "-33,43565400", "lon" : >>>> "-70,60552700", "speed" : "102" }] >>>> } >>>> >>>> Json autogenerated from: https://mholt.github.io/json-to-go/ (lazy >>>> style but it works. Even more when my boss is surrounding like a shark! >>>> jajaa) >>>> >>>> type AutoGenerated struct { Pos []struct { Lp string >>>> `json:"license_plate"` Lat string `json:"lat"` Lon string `json:"lon"` >>>> Speed string `json:"speed"` } `json:"pos"` } >>>> >>>> So I tried more fancy style but it doesn´t work:( >>>> >>>> type track struct{ Lp string `json:"license_plate"` Lat string >>>> `json:"lat"` Lon string `json:"lon"` >>>> Speed string `json:"speed"` >>>> } type pos struct{ Position []track `json:"pos"` } >>>> >>>> x := pos{ Position:[{Lp:"DEMO" , >>>> Lat:"-33.3244",Lon:"-33.391134",Speed:"80", } ]} >>>> >>>> Somebody gave me a hand with this: >>>> >>>> track := make(pos,1) >>>> track[0].Lp = "EEE" >>>> track[0].Lat = "-23.243423" >>>> track[0].Lon = "-24.2344123" >>>> track[0].Speed = "50" >>>> >>>> Data2Send := pos{track} >>>> >>>> But it doesn't keep "pos" when I check Data2Send with >>>> fmt.Printf("%v",Data2Send). >>>> Any idea? "Is any out there?" >>>> >>>> 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...@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...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > Tomás González Dowling | Comtom Tech > -- 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: Issue using json with array
Thanks Victor! for now reading about.. El lunes, 4 de febrero de 2019, 10:56:53 (UTC-3), Victor Giordano escribió: > > Implemeting the Stringer interface could solve your problem > > El martes, 18 de diciembre de 2018, 22:40:45 (UTC-3), Juan Mamani escribió: >> >> I'm not an expert but I do my best. >> >> Original json format required: >> { "pos": [{ "lp" : "WISE-12", "lat": "-33,43565400", "lon" : >> "-70,60552700", "speed" : "102" }] >> } >> >> Json autogenerated from: https://mholt.github.io/json-to-go/ (lazy style >> but it works. Even more when my boss is surrounding like a shark! jajaa) >> >> type AutoGenerated struct { Pos []struct { Lp string >> `json:"license_plate"` Lat string `json:"lat"` Lon string `json:"lon"` >> Speed string `json:"speed"` } `json:"pos"` } >> >> So I tried more fancy style but it doesn´t work:( >> >> type track struct{ Lp string `json:"license_plate"` Lat string >> `json:"lat"` Lon string `json:"lon"` >> Speed string `json:"speed"` >> } type pos struct{ Position []track `json:"pos"` } >> >> x := pos{ Position:[{Lp:"DEMO" , >> Lat:"-33.3244",Lon:"-33.391134",Speed:"80", } ]} >> >> Somebody gave me a hand with this: >> >> track := make(pos,1) >> track[0].Lp = "EEE" >> track[0].Lat = "-23.243423" >> track[0].Lon = "-24.2344123" >> track[0].Speed = "50" >> >> Data2Send := pos{track} >> >> But it doesn't keep "pos" when I check Data2Send with >> fmt.Printf("%v",Data2Send). >> Any idea? "Is any out there?" >> >> 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Issue using json with array
Thanks a lot for your reply!! You are right it's working. But, it could be possible to avoid calling "make"... El mié., 19 de dic. de 2018 a la(s) 08:14, Ozone Kawakami ( kawakami.oz...@gmail.com) escribió: > Your code `make(pos, 1)` seems to be typo. > The fixed version works well. > https://play.golang.org/p/gnLe_Xi2-nb > > 2018年12月19日(水) 10:40 Juan Mamani : > >> I'm not an expert but I do my best. >> >> Original json format required: >> { "pos": [{ "lp" : "WISE-12", "lat": "-33,43565400", "lon" : >> "-70,60552700", "speed" : "102" }] >> } >> >> Json autogenerated from: https://mholt.github.io/json-to-go/ (lazy style >> but it works. Even more when my boss is surrounding like a shark! jajaa) >> >> type AutoGenerated struct { Pos []struct { Lp string >> `json:"license_plate"` Lat string `json:"lat"` Lon string `json:"lon"` >> Speed string `json:"speed"` } `json:"pos"` } >> >> So I tried more fancy style but it doesn´t work:( >> >> type track struct{ Lp string `json:"license_plate"` Lat string >> `json:"lat"` Lon string `json:"lon"` >> Speed string `json:"speed"` >> } type pos struct{ Position []track `json:"pos"` } >> >> x := pos{ Position:[{Lp:"DEMO" , >> Lat:"-33.3244",Lon:"-33.391134",Speed:"80", } ]} >> >> Somebody gave me a hand with this: >> >> track := make(pos,1) >> track[0].Lp = "EEE" >> track[0].Lat = "-23.243423" >> track[0].Lon = "-24.2344123" >> track[0].Speed = "50" >> >> Data2Send := pos{track} >> >> But it doesn't keep "pos" when I check Data2Send with >> fmt.Printf("%v",Data2Send). >> Any idea? "Is any out there?" >> >> 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. >> 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] Issue using json with array
I'm not an expert but I do my best. Original json format required: { "pos": [{ "lp" : "WISE-12", "lat": "-33,43565400", "lon" : "-70,60552700", "speed" : "102" }] } Json autogenerated from: https://mholt.github.io/json-to-go/ (lazy style but it works. Even more when my boss is surrounding like a shark! jajaa) type AutoGenerated struct { Pos []struct { Lp string `json:"license_plate"` Lat string `json:"lat"` Lon string `json:"lon"` Speed string `json:"speed"` } `json:"pos"` } So I tried more fancy style but it doesn´t work:( type track struct{ Lp string `json:"license_plate"` Lat string `json:"lat"` Lon string `json:"lon"` Speed string `json:"speed"` } type pos struct{ Position []track `json:"pos"` } x := pos{ Position:[{Lp:"DEMO" , Lat:"-33.3244",Lon:"-33.391134",Speed:"80", } ]} Somebody gave me a hand with this: track := make(pos,1) track[0].Lp = "EEE" track[0].Lat = "-23.243423" track[0].Lon = "-24.2344123" track[0].Speed = "50" Data2Send := pos{track} But it doesn't keep "pos" when I check Data2Send with fmt.Printf("%v",Data2Send). Any idea? "Is any out there?" 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] I cannot access global var from package. Any idea?
Thanks for comments. Good idea is to implement "package qualifier". I will try it. (Conclusion: Go's rule doesn't apply for subdirectories. If I'm wrong let me know=) Thanks again! El vie., 16 de nov. de 2018 a la(s) 10:53, Jan Mercl (0xj...@gmail.com) escribió: > > On Fri, Nov 16, 2018 at 2:40 PM Juan Mamani > wrote: > > > Why can not access global var MyGlobalVar? Any idea? > > Go has no global scope. It has universe scope, but you cannot define > anything there. `MyGlobalVar` has package scope. To access an exported > identifier imported from pacakge foo, you must use the package qualifier, > like in `foo.MyGlobalVar` - in the first approximation. For other options > lookup "dot imports" but that's seldom a good choice. > > > > According Golang docs should be possible. > > No. > > > It works when both files are in the same directory. > > Yes, package scope contains all TLD declarations in a package. visible > everywhere in the package. > > > But when db.go is in another doesn't work. > > WAI > > -- > > -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] I cannot access global var from package. Any idea?
The sample code: // main.go in varglobal/ package main import( "fmt" "varglobal/db" ) var MyGlobalVar string ="Any value :)" func main(){ db.TryDisplayMyVar() } // db.go in varglobal/db/ package db import "fmt" func TryDisplayMyVar(){ fmt.Println("Value:",MyGlobalVar) } Results of compilation: # varglobal/db db/db.go:15:23: undefined: MyGlobalVar Why can not access global var MyGlobalVar? Any idea? According Golang docs should be possible. It works when both files are in the same directory. But when db.go is in another doesn't work. I tried this sample because I need to update big bunch of code implementing one global variable from packages. Some good samaritan out there? -- 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.