[go-nuts] Breaking change: reflect.StructOf: field 0 has no name

2017-12-10 Thread mihai
I had some code that I didn't touch for a while and now it seems it's 
broken. It panics with `reflect.StructOf: field 0 has no name` at runtime. 
Wasn't Go supposed to have some sort of compatibility promise? 

After a while I've found this[1]  issue which seems to be the reason why my 
program panics now and my question is why is a struct field without a name 
invalid ? Anonymous fields are supposed to have no field names, right? 

 https://github.com/golang/go/issues/20600 

Mihai. 

-- 
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] Breaking change: reflect.StructOf: field 0 has no name

2017-12-11 Thread mihai
Is there any reason why this breaking change is not mentioned in any of the 
release notes? 

On Monday, December 11, 2017 at 8:22:28 AM UTC+2, Ian Lance Taylor wrote:
>
> On Sun, Dec 10, 2017 at 8:46 AM,   wrote: 
> > 
> > I had some code that I didn't touch for a while and now it seems it's 
> > broken. It panics with `reflect.StructOf: field 0 has no name` at 
> runtime. 
> > Wasn't Go supposed to have some sort of compatibility promise? 
> > 
> > After a while I've found this[1]  issue which seems to be the reason why 
> my 
> > program panics now and my question is why is a struct field without a 
> name 
> > invalid ? Anonymous fields are supposed to have no field names, right? 
> > 
> >  https://github.com/golang/go/issues/20600 
>
> Yes, unfortunately we had to change the way that it worked.  To make 
> an anonymous field, set the name to the type name and set Anonymous to 
> true. 
>
> 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.


[go-nuts] gomobile - SIGPIPE

2018-02-05 Thread mihai
I'm trying to develop a gomobile application using a http server serving 
html and a swift client serving the content from localhost through a 
WKWebView. All the work happens inside the http handlers(i.e. http requests 
to external API servers). 
  The issue is that after several requests the application crashes with 
SIGPIPE. I've searched through issues and it seems this was a known issue 
and apparently  was fixed in [0]. How can I debug this further or is there 
any known fix? 


libsystem_kernel.dylib`mach_msg_trap:

0x180c5b560 <+0>: movx16, #-0x1f

0x180c5b564 <+4>: svc#0x80

->  0x180c5b568 <+8>: ret




$ go version
go version go1.9.2 darwin/amd64


https://github.com/golang/go/issues/17393

-- 
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: gomobile - SIGPIPE

2018-02-12 Thread mihai
 I managed to get a small reproducible test case. The issue is easy to 
reproduce. Basically if you spawn some http requests immediately after the 
application comes back from background you get SIGPIPE. 
Step by step:
1. Open ios remote.xcodeproj in XCode
2. Run the application on a real device.
3. Put the application in background (press the "stand by/lock-in" button)
4. Get it out of background (i.e. unlock the phone)
5. You get SIGPIPE 

https://github.com/themihai/testios


gomobile version
gomobile version +5704e18 Mon Jan 22 17:02:51 2018 + (android,ios); 
androidSDK=

Mihai.



On Tuesday, February 6, 2018 at 12:53:06 AM UTC+2, Elias Naur wrote:
>
> It's hard to know what's causing the SIGPIPE without more information. 
> Ideally, a standalone recipe to reproduce the problem.
>
> Make sure you have the latest version of gomobile as well.
>
>  - elias
>
> On Monday, February 5, 2018 at 10:53:09 PM UTC+1, mi...@ubo.ro wrote:
>>
>> I'm trying to develop a gomobile application using a http server serving 
>> html and a swift client serving the content from localhost through a 
>> WKWebView. All the work happens inside the http handlers(i.e. http requests 
>> to external API servers). 
>>   The issue is that after several requests the application crashes with 
>> SIGPIPE. I've searched through issues and it seems this was a known issue 
>> and apparently  was fixed in [0]. How can I debug this further or is there 
>> any known fix? 
>>
>>
>> libsystem_kernel.dylib`mach_msg_trap:
>>
>> 0x180c5b560 <+0>: movx16, #-0x1f
>>
>> 0x180c5b564 <+4>: svc#0x80
>>
>> ->  0x180c5b568 <+8>: ret
>>
>>
>>
>>
>> $ go version
>> go version go1.9.2 darwin/amd64
>>
>>
>> https://github.com/golang/go/issues/17393
>>
>

-- 
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] Re: How to update a module's direct dependencies only

2019-09-05 Thread Mihai Borobocea
On Thu, Sep 5, 2019 at 3:28 PM Tamás Gulácsi  wrote:

> Ain't Go 1.13's "go get -u" does exactly this?
> And the old behaviour with "go get -u all" ?
>
Thanks for the input but:

> I cannot use 'go get -u -t -d ./...' here because that brings in the
>> indirect dependency 'goB' into my go.mod.
>>
> In my minimal concrete example at https://github.com/MihaiB/goMain and
described in the first message in this thread.

-- 
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/CAMXRBmj2YCXMLHYQd3T_nv2osQ-0vz_Y21JOaPoyKG8Bc%3DNgbg%40mail.gmail.com.


Re: [go-nuts] Re: v1.13: Altered go.mod file in project after updating vim-go binaries

2019-09-05 Thread Mihai Borobocea
On Thu, Sep 5, 2019 at 10:18 PM Jan Mercl <0xj...@gmail.com> wrote:
> `go get` should do just one thing and do it well. Automagically
> adjusting `go.mod` if one is found in the current directory (or in any
> of its parents) when outside $GOPATH is IMO neither of that. Or it
> should be enabled by a flag, like -um (update go.mod) or this is maybe
> a job for some `go mod foo` command, not `go get`.

A-ha, I think I understand the problem: 'go get' can be used for two
unrelated purposes:
1) to add/update dependencies in the current Go module
2) to install a program globally: 'go get golang.org/x/lint/golint'
produces ~/go/bin/golint

One normally wants to perform (2) from anywhere: like 'apt-get install
...' (or perhaps 'npm install -g ...'), it doesn't matter what the
current directory is. But if the current directory happens to be
inside a module, the user inadvertently also performed (1).

If this is the case, it seems an issue worth addressing.
However, I have only a basic understanding of go commands and modules.
I might miss important details.

-- 
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/CAMXRBmi_Gpa9_DrmDXP8NKNP7YR2xi-ZSxuRGKcdqHbidZytcQ%40mail.gmail.com.


Re: [go-nuts] Re: v1.13: Altered go.mod file in project after updating vim-go binaries

2019-09-05 Thread Mihai Borobocea
On Thu, Sep 5, 2019 at 9:22 PM Jan Mercl <0xj...@gmail.com> wrote:
>
> > Running 'go get ...' inside a module can add indirect dependencies to 
> > go.mod.
>
> I'm surprised. There's probably some rationale behind `go get` having
> such side effects. Can anyone please shed some light on this?

$ go help module-get
The 'go get' command changes behavior depending on whether the
go command is running in module-aware mode or legacy GOPATH mode.
…
Get resolves and adds dependencies to the current development module
and then builds and installs them.

If you are inside a module (there is a go.mod file in your current dir
or a parent dir) you can just type
$ go help get
But the output of this command changes depending on your current dir
(describes either module-aware or legacy GOPATH behavior).

Other resources are https://tip.golang.org/doc/go1.13#modules (with a
subsection on go get), https://github.com/golang/go/wiki/Modules and
this series of blog posts https://blog.golang.org/using-go-modules
These are what I've looked at to get a sense of modules and stop using
GOPATH now that go 1.13 is out.

I posted this related message with a minimal example of module
dependencies and thoughts/questions on how to update my module's
direct dependencies without mentioning indirect dependencies:
https://groups.google.com/forum/#!topic/golang-nuts/FrWNhWsLDVY

My impression is that Go modules and dependency management are well
thought through and the commands have well defined behavior. But it is
not a small topic/scenario, so getting a sense of how things work
takes some effort and experimentation.

Mihai

-- 
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/CAMXRBmjATyYQqYFhP7ff7_frWwE7M55%2BxVhSXCGoT4Ss-S0Kyg%40mail.gmail.com.


Re: [go-nuts] Re: How to update a module's direct dependencies only

2019-09-05 Thread Mihai Borobocea
On Thu, Sep 5, 2019 at 4:33 AM t hepudds  wrote:

> To upgrade your direct dependencies to their latest release (with your
> indirect dependencies using versions selected based on the requirements of
> your direct dependencies), this should work in most cases:
>
>   go get $(go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m
> all)
>
Thank you for this shorter solution and its GitHub issue.
To run it on any module (including modules without dependencies and with no
.go files in the module root) this checks that the list of dependencies
isn't empty:

go list -f '{{if not (or .Main .Indirect)}}{{.Path}}{{end}}' -m all | xargs
--no-run-if-empty go get

Then my remaining question is: How to find out if one of my dependencies
has a newer major version?
Is there, or should there be, a way using the standard tools to query for
this?
I found a couple of GitHub issues about upgrading to /v2+ (like changing
the /vN import suffix automatically) once the user knows about a new major
version. But I didn't find an issue about discovering that there is a new
major version without manually checking.

Regards,
Mihai

-- 
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/CAMXRBmgsS_qzJoT6fFd%3D%2Baag9bh%3DnXp6WrFtSY_05WDUOyxf8A%40mail.gmail.com.


[go-nuts] Re: wasm - Browser gets stuck due memory usage

2019-11-10 Thread mihai barbulescu
It seems in the end the issue was actually a deadlock in the event loop. I 
fixed it by  spawning go routines on all the functions interacting with the 
dom.

---
>
> I'm trying to build a web/client app using Go (compiled to wasm). The 
> issue is that the browser(both FF and Chrome) gets stuck(i.e and I get a 
> notice "A page is slowing your browser | Stop it | Wait" ) shortly after 
> some minimal interaction (initial page is loaded and a form is processed).
> I took a Memory sample using firefox developer tools(see the print-screen) 
> but I can't find what exactly the culprit. Any idea what could cause it or  
> how to better debug it? Most of the memory seems to go into 
> runtime.ScheduleTimeoutEvent. 
> The program is built using Go tip. 
>

-- 
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/f17bddca-876a-43ae-95c8-e3e0d378264f%40googlegroups.com.


[go-nuts] Re: Go WebAssembly(wasm) testing fails - fatal error: unexpected signal during runtime execution

2019-11-14 Thread mihai barbulescu
- Are you able to provide the code which causes this crash ?
 Not really...it's a big code-base... I will try to reproduce a smaller 
testcase and update the post.
- Which Go version are you using ?
go tip
- Are you testing this in the browser or in Node ? Please give details of 
either.
In the browser (sort of ) 

https://github.com/golang/go/wiki/WebAssembly#running-tests-in-the-browser

joi, 14 noiembrie 2019, 18:33:48 UTC+2, Agniva De Sarker a scris:
>
> Please provide more information so that it helps people to debug the 
> issue. Such as:
>
> - Are you able to provide the code which causes this crash ?
> - Which Go version are you using ?
> - Are you testing this in the browser or in Node ? Please give details of 
> either.
>
>
>
> On Thursday, 14 November 2019 18:52:49 UTC+5:30, mihai barbulescu wrote:
>>
>> I'm building a client-side webapp and part of this I would like to run 
>> tests. It seems testing fails . Is it a known issue ?
>>
>>
>> Mihai
>>
>> server thetv$ GOOS=js GOARCH=wasm go test 
>> --- FAIL: TestServer (3.00s)
>> fatal error: unexpected signal during runtime execution
>>
>> runtime stack:
>> runtime: unexpected return pc for syscall.fsCall called from 
>> 0x15d70a5c1ade6900
>> stack: frame={sp:0xb23170, fp:0xb23208} stack=[0xb21698,0xb23298)
>> 00b23070:  00143b44  002a 
>> 00b23080:  00b00de0  10e20003 
>>  
>> 00b23090:  0001  000b52bf 
>> 00b230a0:  5bab0011   
>> 00c3e368 
>> 00b230b0:  00c3e3b8  105e001a 
>>  
>> 00b230c0:    00b231e8 
>> 00b230d0:  0005   
>> 00b230e0:  109e0010   
>>  
>> 00b230f0:  0003  0005 
>> 00b23100:  008affbb0c00  0001 
>> 00b23110:  15d709d10001  15d70a5c1ade6900 
>> 00b23120:  00c32300  00c30058 
>> 00b23130:    008e6901 
>> 00b23140:  105d0002   
>> 00c3 
>> 00b23150:  00b231e8  0001 
>> 00b23160:  00b06600  1512000d  
>> 00b23170: <00c3  00b231e8 
>> 00b23180:  12250010   
>> 00010001 
>> 00b23190:  0001  00c3e3b8 
>> 00b231a0:    00c305d8 
>> 00b231b0:  15d709d10005  00c3 
>> 00b231c0:  00050004  00b00de0 
>> 00b231d0:  15d709d11b235d00  00c3 
>> 00b231e0:  1248005e   
>>  
>> 00b231f0:     
>> 00b23200: !15d70a5c1ade6900 >10a0 
>>  
>> 00b23210:  00ac0820  1354 
>>  
>> 00b23220:  10a0   
>> 00b00de0 
>> 00b23230:  00c00c90  0006 
>> 00b23240:  1251002b   
>> 00c3 
>> 00b23250:  00c00c00  00c00900 
>> 00b23260:  00040002   
>> 00b23270:  00b00de0  13b40001  
>> 00b23280:  00c00c00  00b232c0 
>> 00b23290:  0100 
>> syscall.fsCall(0x10a0, 0xac0820, 0x1354, 0x10a0, 0xb00de0, 
>> 0xc00c90, 0x6, 0x1251002b)
>> /Users/thetv/goroot/src/syscall/fs_js.go:513 +0xd
>>
>> goroutine 1 [chan receive]:
>> testing.(*T).Run(0xca4100, 0x137b68, 0xa, 0x14f008, 0x155b0002)
>> /Users/thetv/goroot/src/testing/testing.go:977 +0x31
>> testing.runTests.func1(0xca4000)
>> /Users/thetv/goroot/src/testing/testing.go:1218 +0x5
>> testing.tRunner(0xca4000, 0xc56e28)
>> /Users/thetv/goroot/src/testing/testing.go:925 +0xc
>> testing.runTests(0xc0a240, 0xaee440, 0x1, 0x1, 0x0)
>> /Users/thetv/goroot/src/testing/testing.go:1216 +0x28
>> testing.(*M).Run(0xca2000, 0x0)
>> /Users/thetv/goroot/src/testing/testing.go:1133 +0x1b
>> main.main()
>> _testmain.go:44 +0xd
>>
>> goroutine 6 [waiting]:
>> syscall/js.Value.Call(0x7ff8000a, 0x13655c, 0x5, 0xc76aa0, 0x6, 
>> 0xa, 0x5)
>> /Users/thetv/goroot/src/syscall/js/js.go:326 +0x3
>> syscall.fsCall(0x13655c, 0x5, 0xc58bf8, 0x5, 0x5, 0x401, 0x1378ac0, 
>> 0x3)
>> /Us

[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 := fv.Type().Out(0)
   // how to call `Hello` with `v` ?
  // Obviously the code below is incorrect
Hello[vt]()
}

func Hello[T any](){
 // do something with T
 json.Marshal(new(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/229fac8f-c948-4686-9885-1c114b662764n%40googlegroups.com.


[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, April 9, 2024 at 2:04:01 AM UTC+3 Carl-Philip Hänsch wrote:

> Hi,
>
> I am currently developing a JITable interpreter for a scripting language 
> where users can define user-defined functions with the signature
>
> func (...interface{}) interface{}
>
> that can interoperate with the scripts. interface{} can be bool, int, 
> string, []interface{} or another func(...interface{}) interface{} or one of 
> many more.
>
> Now I want to create a C/C++ library that offers additional functions with 
> exactly this signature. My questions:
>
>- interface{} is represented as a value (ptruint) and a type 
>information pointer. Is there a way to somehow pass this information to 
>C/C++?
>- Does C/C++ (more specific: LLVM) have a calling convention that is 
>ABI compatible to golang? (so I can use interface{} as a pair of 
>parameters?)
>- Is there any library code in golang that helps me to read out 
>interface{}'s type information?
>
>

-- 
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/c0f20438-989c-4276-b82d-8c3861697c80n%40googlegroups.com.


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 renderers in Go. 

On Saturday, April 6, 2024 at 12:32:05 PM UTC+3 KRITIKA AWASTHI wrote:

> Thanks for suggestion but i want a package for go language .
> weasyprint is for python.
>
> On Friday, April 5, 2024 at 9:54:32 PM UTC+5:30 Harmen wrote:
>
>> On Fri, Apr 05, 2024 at 06:45:03AM -0700, KRITIKA AWASTHI wrote: 
>> > I want to convert html text to pdf using go language . 
>> > Previously, I used chromedp 
>> >  to create PDFs, but 
>> it 
>> > was consuming too much server capacity. So, currently I am using using 
>> > wkhtmltopdf  package which 
>> is 
>> > deprecated . 
>> > There is one more package, gofpdf 
>> > , which is also 
>> deprecated 
>> > and no longer maintained . 
>> > I would appreciate if you suggest some other alternatives of these 
>> > packages . 
>>
>> We use weasyprint with plain `cmd := exec.Command(Exe, "--stylesheet", 
>> cssfile, "-", "-")` and some Go templating. Nothing fancy, works, looks 
>> nice. 
>>
>

-- 
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/37bf8c29-6393-4767-ad9f-32b30f099b03n%40googlegroups.com.


[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 to import go's parser and compiler as a library and start 
> compiling .go files, building IR code at runtime and finally (with some 
> implementation effort) JITing them?
>
> My goal is to "specialize" go code for certain data. For instance a 
> interpreter loop with a big switch v.(type) {} shall be copied and 
> rewritten as if v is known.
>
> Regards
>

-- 
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/2793dc9c-bf55-4a8a-883c-8c2b17d09924n%40googlegroups.com.


[go-nuts] WebAssembly as a target

2016-06-19 Thread 'Mihai B' via golang-nuts
I don't think we can expect anything before wasm supports GC (i.e. Phase 3 on 
wasm roadmap). Once GC is supported(not very soon) Go could be compiled through 
llgo[0]. One issue could be the binary size(.i.e due /reflect)

- Mihai
[0] https://llvm.org/svn/llvm-project/llgo/trunk/README.TXT

-- 
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] Unmarshalling and tags

2016-06-19 Thread 'Mihai B' via golang-nuts
Hi there,

I have a struct that needs to be marshalled/unmarshalled using various 
serialization formats(xml, json, name/value). The tags start to represent a 
considerable effort[0] so I'm wondering if this is a common use case and if 
a change[1] to the encoding packages to specify the tag key/selectors would 
be a bad idea. Another option would be to use a standard tag key as default 
(e.g. "encoding") but I think it may violate  the Go1 backward 
compatibility.

Mihai.


[0]
type Payment struct {
ActionType paypal.ActionType `query:"actionType,omitempty" 
json:"actionType,omitempty"  xml:"actionType,omitempty"`
ReceiverList paypal.ReceiverList `query:"actionType,omitempty" 
json:"receiverList,omitempty"  xml:"receiverList,omitempty"`
}


[1] (dec *Decoder)SetTagKey(key string)

-- 
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{} constrains on specific types

2016-06-24 Thread 'Mihai B' via golang-nuts
 I'm developing a json schema generator (json schema from Go ast and the 
other way around). There is a keyword "oneOf" which requires  exactly one 
schema to be valid in this keyword's value. In Go I translate it by using 
an empty interface{}. The issue is that when I convert the interface{} to 
json schema I can only say that the object can be of any type even if I 
know that it can hold only a small subset.
 Therefore I'm wondering if placing some constrains on the types that could 
be implemented by the interface would be a good idea. For example instead 
of `type interface{}` which implements any type we could define the types 
it can implement (e.g.  type  X interface{T1, T2, T3} ). This way we don't 
have a totally black box so it improves the documentation/semantics and we 
avoid specific bugs using static analysis. Currently the practice seems to 
be documenting the types in pure comments[0] which cannot be analysed 
statically. Another option that I'm considering now is to use the empty 
interface but with specific tags [1] and use an external tool. This might 
have been proposed before but I can't find it on the mailing list. What do 
you think?

[0]  https://golang.org/pkg/go/ast/#Object 
[1]  

type Object struct {
Name string   // declared 
name
Decl interface{} `interface:"Field,FuncDecl,LabeledStmt,external.Scope" 
//
   
}

-- 
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] reflect, is it possible to get the [body + sign] of a func as text at runtime ?

2016-09-18 Thread 'Mihai B' via golang-nuts
The body is compiled so you can't get it via reflection.

-- 
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.