Re: [go-nuts] Can we not invoke methods on types referring to generics?

2023-10-19 Thread Kurtis Rader
On Thu, Oct 19, 2023 at 9:56 PM Nurahmadie Nurahmadie wrote: > >> You have changed the question. You are no longer asking about defining >> methods on a type derived from a primitive type. Non-aliased types are >> deliberately distinct types that cannot be "auto downcast" or "auto >> upcast".

Re: [go-nuts] What tool is used in Go Playground's import handling?

2023-10-19 Thread 'Christian Stewart' via golang-nuts
Hi, https://pkg.go.dev/golang.org/x/tools/cmd/goimports goimports -w ./ On Thu, Oct 19, 2023, 8:31 PM Pratik Tamgole wrote: > When I use packages, any packages in general, how does the import("fmt") > line correct itself to include the used packages in the program? What tool > is implemented

Re: [go-nuts] Can we not invoke methods on types referring to generics?

2023-10-19 Thread 'Dan Kortschak' via golang-nuts
On Fri, 2023-10-20 at 11:56 +0700, Nurahmadie Nurahmadie wrote: > why is there no, type coercion, as you said, that allow the new type > to be acknowledged as its underlying type? which will not be a > question if otherwise Go has mechanism to allow methods to be > attached to foreign types.

Re: [go-nuts] Can we not invoke methods on types referring to generics?

2023-10-19 Thread Nurahmadie Nurahmadie
> > > You have changed the question. You are no longer asking about defining > methods on a type derived from a primitive type. Non-aliased types are > deliberately distinct types that cannot be "auto downcast" or "auto > upcast". Arguably the biggest flaw of the C language was its automatic type

Re: [go-nuts] Can we not invoke methods on types referring to generics?

2023-10-19 Thread Kurtis Rader
On Thu, Oct 19, 2023 at 9:03 PM Nurahmadie Nurahmadie wrote: > Adding methods to a primitive type, or more generally adding methods >> to a type defined in a different package, would cause different >> packages to behave differently depending on whether they see the >> methods. That would be

Re: [go-nuts] Can we not invoke methods on types referring to generics?

2023-10-19 Thread Nurahmadie Nurahmadie
> Adding methods to a primitive type, or more generally adding methods > to a type defined in a different package, would cause different > packages to behave differently depending on whether they see the > methods. That would be confusing. It would meant that type > assertions would sometimes

[go-nuts] What tool is used in Go Playground's import handling?

2023-10-19 Thread Pratik Tamgole
When I use packages, any packages in general, how does the import("fmt") line correct itself to include the used packages in the program? What tool is implemented here, I want to put the same in my editor. -- You received this message because you are subscribed to the Google Groups

Re: [go-nuts] Can we not invoke methods on types referring to generics?

2023-10-19 Thread Ian Lance Taylor
On Thu, Oct 19, 2023 at 6:18 PM Nurahmadie Nurahmadie wrote: > > There are two ways to enable this, which are worth discussing further as of > why Go decided to behave this way. > > To use type alias as mentioned before `type MatrixF64 = Matrix[float64]`, > this is generally works but

Re: [go-nuts] Can we not invoke methods on types referring to generics?

2023-10-19 Thread Nurahmadie Nurahmadie
On Fri, 20 Oct 2023 at 07:51, Ian Lance Taylor wrote: > On Thu, Oct 19, 2023 at 5:14 PM Jason E. Aten wrote: > > > > Analogous to > > > > type IntSlice []int > > > > func (p IntSlice) Len() int { return len(p) } > > func (p IntSlice) Less(i, j int) bool { return p[i].val < p[j].val } > > func

Re: [go-nuts] Can we not invoke methods on types referring to generics?

2023-10-19 Thread Ian Lance Taylor
On Thu, Oct 19, 2023 at 5:14 PM Jason E. Aten wrote: > > Analogous to > > type IntSlice []int > > func (p IntSlice) Len() int { return len(p) } > func (p IntSlice) Less(i, j int) bool { return p[i].val < p[j].val } > func (p IntSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } > > and then

[go-nuts] Can we not invoke methods on types referring to generics?

2023-10-19 Thread Jason E. Aten
Analogous to type IntSlice []int func (p IntSlice) Len() int { return len(p) } func (p IntSlice) Less(i, j int) bool { return p[i].val < p[j].val } func (p IntSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } and then calling sort.Sort() on an IntSlice, I figured I could create a type that is

Re: [go-nuts] Re: URL variables with net/http

2023-10-19 Thread Tim Casey
Gin does this directly. There is nothing complicated it does. Something like: group := engine.Group("/service/v1") group.GET("user/:id", handler) And then in the handler: id := c.Param("id") And the rest is what ever is yours. "engine" is a gin engine and 'c' is a gin context. On Thu, Oct

[go-nuts] Re: URL variables with net/http

2023-10-19 Thread TheDiveO
stdlib only with upcoming 1.22 which isn't yet released, see https://eli.thegreenplace.net/2023/better-http-server-routing-in-go-122/ gorilla mux is another 3rd party muxer with variable support https://github.com/gorilla/mux the "best" way using only stdlib mux is to parse the path and

[go-nuts] Re: URL variables with net/http

2023-10-19 Thread j2gg0s
I'm not sure what the best way is. But I think you can refer to the existing solutions. For example gin, mux. Link: https://github.com/gin-gonic/gin/blob/master/tree.go#L116 在2023年10月19日星期四 UTC+8 19:27:59 写道: > Hi everyone. I'm building an api with net/http and I'm having trouble > with url

[go-nuts] URL variables with net/http

2023-10-19 Thread Dejan Duh
Hi everyone. I'm building an api with net/http and I'm having trouble with url variables. How can I get the url variables form the url in the REST way. Example, if I have a url like "http:/localhost:3000/users/:id". I want to get the user with the id given from the url. What is the best way to