[go-nuts] Go Create

2021-01-12 Thread Kevin Chadwick
Inspired by: "https://twitter.com/rakyll/status/1348723364894961666; "Yet another couple of hours spent on go.mod and go.sum. If I was giving #golang a first try today, I'd just give up and look for another option. What are we doing as a community to address this?" Couldn't go have a folder

Re: [go-nuts] Go Create

2021-01-12 Thread 'Axel Wagner' via golang-nuts
On Tue, Jan 12, 2021 at 10:26 AM Kevin Chadwick wrote: > Inspired by: > > "https://twitter.com/rakyll/status/1348723364894961666; > > "Yet another couple of hours spent on go.mod and go.sum. If I was giving > #golang > a first try today, I'd just give up and look for another option. What are >

Re: [go-nuts] Go Create

2021-01-12 Thread Kevin Chadwick
On 1/12/21 9:43 AM, Axel Wagner wrote: > git init > go mod init > > I guess you *could* safe the `git init` part, but is that really worth the > added > complexity? Sorry I meant replace keyword, not require in the original mail. Though requiring a domain name is equally unintuitive. I guess

Re: [go-nuts] Go Create

2021-01-12 Thread Artur Vianna
I don't think this tweet is very true, it took me many months of learning Go to start learning about go.mod. I think that's not the first thing one learns about a language, you can just 'vim main.go' and begin experimenting. How do you propose this tool will work? On Tue, 12 Jan 2021, 06:25

Re: [go-nuts] A value saved in an interface{} field in a struct not usable in func with interace{} arg

2021-01-12 Thread Ian Davis
Note the error says that val was nil, so your type assertion will panic. You can read more about how to make type assertions that report success or failure in the Go Tour: https://tour.golang.org/methods/15 Have you tried printing the type of what you receive before attempting the type

Re: [go-nuts] A value saved in an interface{} field in a struct not usable in func with interace{} arg

2021-01-12 Thread Steve Murphy
Ian-- You missed the part about the arguments being "shifted left" above, which kinda looks like a compiler issue. Maybe something I wrote contributed to the problem, but I have no idea what. If this is a known problem, perhaps I can hand-install aa newer version, or something...? murf On

Re: [go-nuts] Go Create

2021-01-12 Thread 'Axel Wagner' via golang-nuts
Hi, I'm having trouble understanding and separating your core problems and what you are suggesting to solve them. The solution to describe, sounds to me a lot like what `-mod vendor` achieves. I don't use that very often, so I don't really understand its shortcomings - so it might be helpful if

Re: [go-nuts] Go Create

2021-01-12 Thread 'Axel Wagner' via golang-nuts
On Tue, Jan 12, 2021 at 1:20 PM Kevin Chadwick wrote: > I guess it's the > > Call code in an external package > "https://golang.org/doc/tutorial/getting-started; > > That is a little hairy. > What is hairy about this? To me, that seems like pretty simple steps: 1. Find the library you need and

Re: [go-nuts] Go Create

2021-01-12 Thread Kevin Chadwick
On 1/12/21 9:39 AM, Artur Vianna wrote: > I don't think this tweet is very true, it took me many months of learning Go > to > start learning about go.mod. I think that's not the first thing one learns > about > a language, you can just 'vim main.go' and begin experimenting. > Fair enough. I had

Re: [go-nuts] Go Create

2021-01-12 Thread Kevin Chadwick
On 1/12/21 12:33 PM, Axel Wagner wrote: > You also talk about onboarding - but I don't understand how the rest of your > message relates to that. The replace-directive is an advanced feature that > newcomers to the language don't need to be concerned with, as far as I can > tell. > It's really

Re: [go-nuts] Go Create

2021-01-12 Thread Kevin Chadwick
On 1/12/21 12:37 PM, Axel Wagner wrote: > Again, would be interesting how other languages can make this simpler, > because I > genuinely can't imagine. The issue is that I believe go avoids files in order to speed up compilation. Which I am thankful for. It's just I don't believe the replace

Re: [go-nuts] Go Create

2021-01-12 Thread 'Axel Wagner' via golang-nuts
On Tue, Jan 12, 2021 at 2:49 PM Kevin Chadwick wrote: > On 1/12/21 12:37 PM, Axel Wagner wrote: > > Again, would be interesting how other languages can make this simpler, > because I > > genuinely can't imagine. > > The issue is that I believe go avoids files in order to speed up > compilation.

Re: [go-nuts] Go Create

2021-01-12 Thread 'Axel Wagner' via golang-nuts
On Tue, Jan 12, 2021 at 1:49 PM Kevin Chadwick wrote: > Maybe I need to look into -mod vendor as I didn't know that existed. > Otherwise > disconnect your internet and then import a folder of local .go files that > you > use in multiple projects? > Ah, I see. I agree that this could be simpler.

Re: [go-nuts] A value saved in an interface{} field in a struct not usable in func with interace{} arg

2021-01-12 Thread Alex
> newItem = new(KdElem) > if itemfunc(arg, , newItem.size) != 0 "newItem.item" is a "interface{}" with a nil value. Doing "" then turns it into a "*interface{}" That is why you cannot do "var realval *int64 = val.(*int64)" To make it work as what I think you intend to do you would have to do:

Re: [go-nuts] A value saved in an interface{} field in a struct not usable in func with interace{} arg

2021-01-12 Thread Ian Davis
This is highly unlikely to be a compiler issue. Note that there are more arguments in the stack trace than in the signature of your method so you can't assume correspondence by placement. It looks like the first two arguments in the stack trace are the type and value pointers for arg (which is

[go-nuts] Identify mapping between goroutines and OS threads in stack trace

2021-01-12 Thread varun...@gmail.com
Hi, I would like to know how to identify mapping between an OS thread and go-routine from the stack trace i.e. which go-routine is scheduled for execution on a OS thread. *Background:* My application spawns very large number of go-routines (upto 2M) for heavy data processing. In some cases, I

[go-nuts] Re: Identify mapping between goroutines and OS threads in stack trace

2021-01-12 Thread varun...@gmail.com
Looking at all goroutines with runnable state seem to be the solution but I am not very sure about this. *goroutine 15825281 [runnable]* On Tuesday, January 12, 2021 at 9:16:47 PM UTC+5:30 varun...@gmail.com wrote: > Hi, I would like to know how to identify mapping between an OS thread and >

Re: [go-nuts] A value saved in an interface{} field in a struct not usable in func with interace{} arg

2021-01-12 Thread Alex
If you want to move the type info into genbox you can do https://play.golang.org/p/_yhuvOhtLvl On Tuesday, 12 January 2021 at 11:40:27 pm UTC+8 Alex wrote: > > newItem = new(KdElem) > > if itemfunc(arg, , newItem.size) != 0 > > "newItem.item" is a "interface{}" with a nil value. > Doing ""

Re: [go-nuts] Re: Interface Fields

2021-01-12 Thread Dave Protasowski
Found https://github.com/golang/go/issues/23796 On Tue, Jan 12, 2021 at 10:05 PM Henry wrote: > I remember reading some proposals about it somewhere, either here at > golang-nuts or at github. The general consensus was no, because interface > is all about behavior. Struct is for data and

[go-nuts] Re: Interface Fields

2021-01-12 Thread Henry
I remember reading some proposals about it somewhere, either here at golang-nuts or at github. The general consensus was no, because interface is all about behavior. Struct is for data and interface is for behavior, or something like that if I remember it correctly. In your specific example,

Re: [go-nuts] init() in package main won't run :-/

2021-01-12 Thread Marcin Romaszewicz
Your `var db=initDB()` runs before init(), and it returns an error, so the program aborts. Here's a change which initializes db explicitly in the init function, and it works as you expect: https://play.golang.org/p/xsUU2hfnx-w The init function is called after all variable initializations

[go-nuts] init() in package main won't run :-/

2021-01-12 Thread Martin Ziebiker
Hello, please does anyone know why init() won't run? Thank You very much! https://play.golang.org/p/0PDUJlF8X1w -- 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

[go-nuts] Re: Context on one-shot structs

2021-01-12 Thread 'Jean de Klerk' via golang-nuts
Er, lifetime of the struct * On Tue, Jan 12, 2021 at 8:11 AM Jean de Klerk wrote: > Hi all, > > I'm looking into how contexts are used, and wondering: does anybody know > of an idiomatic use of context on a struct for the sake of a one-shot? > > (a one-shot being some struct that gets used

[go-nuts] Context on one-shot structs

2021-01-12 Thread 'Jean de Klerk' via golang-nuts
Hi all, I'm looking into how contexts are used, and wondering: does anybody know of an idiomatic use of context on a struct for the sake of a one-shot? (a one-shot being some struct that gets used once, like an RPC or http request) For example, http.Request has a context on its struct. But, I

[go-nuts] Creating a serde-like framework for Go using generics?

2021-01-12 Thread Keith Wipf
If you've ever worked with Rust, you've probably sceen the serde framework. My question is, once Go has generics, would it be possible to write something like this in Go? This seems like something that could really benefit the language. The only drawback I can see so far as that you'd have to

Re: [go-nuts] Go Create

2021-01-12 Thread Jim Ancona
I have a third use case for replace: 3. Simultaneously developing a library and client for that library. For example, if I have a library to access a network service or piece of hardware and want to extend its API, I find that working on the client along with the library helps me iterate to a

Re: [go-nuts] Need to read file in double loop

2021-01-12 Thread Tong Sun
Ops. sorry, it is. Wonder why it wasn't working before (tried at least twice). On Tue, Jan 12, 2021 at 3:12 PM Tong Sun wrote: > > That's a typo. Changing it to "E" you'd think the problem is solved? > > On Mon, Jan 11, 2021 at 10:14 PM Kurtis Rader wrote: > > > > You should start by asking

Re: [go-nuts] Go Create

2021-01-12 Thread Rob Pike
Jim, I used replace this way just yesterday. It works fine, but is not easily discoverable as a process and it took me a minute or two to figure it out. Also, one must be sure to remove the replace directive before releasing the code, which is an easy detail to forget. The same trick (and

Re: [go-nuts] Creating a serde-like framework for Go using generics?

2021-01-12 Thread Ian Lance Taylor
On Tue, Jan 12, 2021 at 12:29 PM Keith Wipf wrote: > > Also, will Go generics support specialization? I thought that I saw > somewhere that you would be able to switch on a type parameter at > compile time. I'm thinking you'd need this to serialize ints and other > primitive types because you

Re: [go-nuts] Need to read file in double loop

2021-01-12 Thread Tong Sun
That's a typo. Changing it to "E" you'd think the problem is solved? On Mon, Jan 11, 2021 at 10:14 PM Kurtis Rader wrote: > > You should start by asking yourself why your program outputs "1", "2" and > "S". Hint: after seeing "S" you don't break out of the inner loop until > another "S" is

Re: [go-nuts] Creating a serde-like framework for Go using generics?

2021-01-12 Thread Sebastien Binet
With 'go/types' and the like, one can relatively easily automatically generate the (de)serialization code. See: - go-hep.org/x/hep/brio IIRC, specialization is off the table at the moment. -s Original Message On Jan 12, 2021, 21:14, Keith Wipf < keithwi...@gmail.com> wrote:

Re: [go-nuts] Go Create

2021-01-12 Thread Kevin Chadwick
>If you are using replace as part of your regular workflow, I do agree >that >you are probably misusing it. It's just hard to understand why, from >what >you said so far (barring the "I don't have an internet connection and >want >to use something from my module cache" case, which I find

[go-nuts] Interface Fields

2021-01-12 Thread Dave Protasowski
I'm doing some due-diligence and wondering if there's any old topics about extending interfaces to support field sets. ie. type WithID interface { ID string } type X struct { ID string } type Y struct { ID string } func PrintID(item WithID) { fmt.Println(item.ID) } In the above the PrintID