Re: [go-nuts] problem with generic type switch

2024-04-09 Thread Xiangrong Fang
Thank you for the info. The purpose of using generics is to avoid reflect or interface{}, at least for me :-) 在2024年4月8日星期一 UTC+8 18:35:18 写道: > Yes, the *underlying type* of Class is `byte`, but the type-switch checks > if the dynamic type is *exactly* `byte`. > The only way, currently, to

Re: [go-nuts] Is it possible to "extract" the generic [T] from a reflected type ?

2024-04-09 Thread Ian Lance Taylor
On Tue, Apr 9, 2024 at 9:41 AM Mihai Barbu wrote: > > I need to call some generic functions with types that are now known at > compile time. Is it possible to do this? > See the code below (vastly reduced). > > // fv is a function that returns an unknown type > func Do(fv reflect.Value){ > //

[go-nuts] Re: Go JIT

2024-04-09 Thread 'Mihai' via golang-nuts
Maybe http://golang.org/pkg/types and http://golang.org/pkg/build can help you. On Tuesday, April 9, 2024 at 2:04:03 AM UTC+3 Carl-Philip Hänsch wrote: > Hi, > > I saw in go's source code that all methods and data structures regarding > parsers, the IR and so on are private. > > Is there a way

Re: [go-nuts] Convert html text to pdf using go language .

2024-04-09 Thread 'Mihai' via golang-nuts
Use princexml command line using https://pkg.go.dev/os/exec . There is no native Go package to render html into pdf. The issue is very complicated because both HTML and CSS (and potentially JS) are complex markup language and as no browser was ever written in Go nobody will write HTML and CSS

[go-nuts] Re: using interface{} values in C/C++ bindings

2024-04-09 Thread Mihai Barbu
>>yes, Is there any library code in golang that helps me to read out interface{}'s type information? Yes, there is https://golang.org/pkg/reflect For example: getType(0) getType("hello string") func getType(v interface{}){ t := reflect.TypeOf(v) fmt.Printf("type is %s", t) } On Tuesday,

[go-nuts] Is it possible to "extract" the generic [T] from a reflected type ?

2024-04-09 Thread Mihai Barbu
I need to call some generic functions with types that are now known at compile time. Is it possible to do this? See the code below (vastly reduced). // fv is a function that returns an unknown type func Do(fv reflect.Value){ // get the first returned type by function fv vt :=

Re: [go-nuts] Is json.Marshal deterministic?

2024-04-09 Thread Nagaev Boris
Hi Juliusz, I don't know if JSON serialization is deterministic, but I know a couple of cases when it is not. If the type or some type inside it has a custom JSON marshaller (method MarshalJSON), then if that function's output is not deterministic, the whole JSON for the type is not

[go-nuts] Is json.Marshal deterministic?

2024-04-09 Thread Juliusz Chroboczek
Hi, Suppose that I call json.Marshal on two structures that are deep equal, or on the same structure at different times. Are the outputs guaranteed to be bytewise identical? (The reason I'm asking is that I'm sending JSON over HTTP, and I need to know whether it is correct to send a strong ETag