[go-nuts] Windows Message Loop is getting blocked and resumed intermittently

2017-02-15 Thread fe f
I'm writing a go program that constantly receives and processes windows messages in golang. (Go1.7, GOMAXPROCS=8, Windows 10) Here's my code.. (minimal code) import ( "fmt" "github.com/go-ole/go-ole" "runtime" ) func main () { SetPriorityClass(GetCurrentProcess(),

[go-nuts] Changes to the Code of Conduct

2017-02-15 Thread Andrew Gerrand
Hi golang-nuts, This morning we made a change to the Code of Conduct . This change removes the punitive language and anonymous reporting mechanism from the Code of Conduct document. The changes will go live with the

[go-nuts] Orm Golang

2017-02-15 Thread I Ketut Gunawan
Hi is there any suggestion of using orm in golang with lock feature update record ? Thanks for help -- 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: weak hash for (MongoDb like) data server

2017-02-15 Thread Basile Starynkevitch
On Thursday, February 16, 2017 at 6:42:05 AM UTC+1, Basile Starynkevitch wrote: > > > > On Wednesday, February 15, 2017 at 9:01:58 PM UTC+1, Tamás Gulácsi wrote: > > >> Why do you need this? >> You want the GC do the housekeeping for you, but I'm sure you won't be >> happy with the result,

[go-nuts] go executable cross-compiled for arm5 works on amd64 (and arm5)

2017-02-15 Thread Dan Kortschak
Can someone explain to me why this works? I am cross-compiling for arm5, but the executable works on amd64. $ cat hello.go  package main import "fmt" func main() { fmt.Println("hello") } $ GOARCH=arm GOARM=5 go build hello.go  $ ./hello  hello $ go env GOARCH="amd64" GOBIN="" GOEXE=""

Re: [go-nuts] will GC close unused connection ?

2017-02-15 Thread Jan Mercl
On Thu, Feb 16, 2017 at 8:20 AM wrote: > Will GC close unused connection ? No. At least not directly. A finalizer can possibly do that and finalizers are possibly invoked by the GC. -- -j -- You received this message because you are subscribed to the Google Groups

[go-nuts] Re: Windows Message Loop is getting blocked and resumed intermittently

2017-02-15 Thread martseniuk
check ole.GeMessage error. btw. https://github.com/go-ole/go-ole/blob/master/com_func.go#L163 On Thursday, February 16, 2017 at 7:12:19 AM UTC+3, fe f wrote: > > I'm writing a go program that constantly receives and processes windows > messages in golang. (Go1.7, GOMAXPROCS=8, Windows 10) > >

[go-nuts] Re: Windows Message Loop is getting blocked and resumed intermittently

2017-02-15 Thread martseniuk
check ole.GeMessage error. btw. https://github.com/go-ole/go-ole/blob/master/com_func.go#L163 -- 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: weak hash for (MongoDb like) data server

2017-02-15 Thread Basile Starynkevitch
On Wednesday, February 15, 2017 at 9:01:58 PM UTC+1, Tamás Gulácsi wrote: > Why do you need this? > You want the GC do the housekeeping for you, but I'm sure you won't be > happy with the result, as the GC's policy differs from what you await... > What make you believe I won't be happy with

[go-nuts] will GC close unused connection ?

2017-02-15 Thread caspian46
Will GC close unused connection ? In a particular case, I found that if there's a connection won't be used for a while, it will be closed. If I disable GC, then the connection will not be closed. In the test, I never call the close function manually. But this is a bit hard to reproduce. GC

[go-nuts] building a linux binary with -race on a mac

2017-02-15 Thread Joseph Lorenzini
All: I am writing and building my code on a mac. The code is a linux binary though so its obviously a cross compilation. This works fine: GOOS=linux GOARCH=amd64 go build . This does not: GOOS=linux GOARCH=amd64 go build -race . go build: -race requires cgo; enable cgo by setting

[go-nuts] Re: Why get an element from []interface{} `arr[0] == nil` is not true?

2017-02-15 Thread Volker Dobler
Am Mittwoch, 15. Februar 2017 09:40:35 UTC+1 schrieb Felix Sun: > > https://play.golang.org/p/qYA8Ddnnye > > ``` > > package main > > import ( > "fmt" > ) > > type Obj struct { > One *Obj > } > > func main() { > var o = {} > > var arr = []interface{}{o.One} > > fmt.Println(arr[0]) >

[go-nuts] Why get an element from []interface{} `arr[0] == nil` is not true?

2017-02-15 Thread Felix Sun
https://play.golang.org/p/qYA8Ddnnye ``` package main import ( "fmt" ) type Obj struct { One *Obj } func main() { var o = {} var arr = []interface{}{o.One} fmt.Println(arr[0]) fmt.Println("why this is not true?", arr[0] == nil) } ``` Why `arr[0] == nil` is not true? -- You

Re: [go-nuts] Why get an element from []interface{} `arr[0] == nil` is not true?

2017-02-15 Thread Jan Mercl
On Wed, Feb 15, 2017 at 9:40 AM Felix Sun wrote: Why `arr[0] == nil` is not true? Because it's not a nil interface{}: https://play.golang.org/p/w-od_KHWlc See also https://golang.org/doc/faq#nil_error -- -j -- You received this message because you are subscribed to the

Re: [go-nuts] Why get an element from []interface{} `arr[0] == nil` is not true?

2017-02-15 Thread 'Axel Wagner' via golang-nuts
This is a frequently asked question (it has nothing to do with the slice). On Wed, Feb 15, 2017 at 9:40 AM, Felix Sun wrote: > https://play.golang.org/p/qYA8Ddnnye > > ``` > > package main > > import ( > "fmt" > ) > > type Obj struct { >

[go-nuts] Re: Why get an element from []interface{} `arr[0] == nil` is not true?

2017-02-15 Thread djadala
On Wednesday, February 15, 2017 at 10:40:35 AM UTC+2, Felix Sun wrote: > > https://play.golang.org/p/qYA8Ddnnye > > ``` > > package main > > import ( > "fmt" > ) > > type Obj struct { > One *Obj > } > > func main() { > var o = {} > > var arr = []interface{}{o.One} > > fmt.Println(arr[0]) >

[go-nuts] Re: Why get an element from []interface{} `arr[0] == nil` is not true?

2017-02-15 Thread djadala
On Wednesday, February 15, 2017 at 11:25:16 AM UTC+2, dja...@gmail.com wrote: > > > > On Wednesday, February 15, 2017 at 10:40:35 AM UTC+2, Felix Sun wrote: >> >> https://play.golang.org/p/qYA8Ddnnye >> >> ``` >> >> package main >> >> import ( >> "fmt" >> ) >> >> type Obj struct { >> One

[go-nuts] How to run deferred function in main() on panic() in a goroutine?

2017-02-15 Thread sunyc
Hi, I have a situation that need some advice. I have a main loop that is calling some C code (potentially looping forever). and I need to handle signals like SIGABRT correctly by ensuring a cleanup function was run. func main() { cleanup := func() {} defer cleanup() for {

[go-nuts] Re: how to parse script expression with go and run the script

2017-02-15 Thread howardcshaw
The go/parse package is not really going to help much, as Go is a compiled language. What you are wanting is something akin to a scripting language, something with an 'eval' type function. While it is just barely feasible that you could accomplish something directly with Go using on-the-fly

Re: [go-nuts] CodeReviewComments: Recommendation of gofmt

2017-02-15 Thread howardcshaw
> > > > Side-note: I don't think goimports can actually do what you are saying, > can it? Because, if you run goimports on a valid program, it won't actually > *change* any imports, it might just reformat it. For goimports to change > anything semantically, the program would need to have

Re: [go-nuts] Are the tests in the Go source code considered "Unit" tests?

2017-02-15 Thread Ian Lance Taylor
On Tue, Feb 14, 2017 at 10:35 PM, wrote: > > From my understanding Unit Tests should focus on testing a single feature > and not use the filesystem. > > But in the Go source (https://github.com/golang/go) I saw several tests that > would violate those conditions. > > Should

Re: [go-nuts] How to run deferred function in main() on panic() in a goroutine?

2017-02-15 Thread Ian Lance Taylor
On Wed, Feb 15, 2017 at 10:43 AM, Yucong Sun wrote: > So, to give more background, i am trying to porting a C based > interpreter to Go. In the single threaded C code, the signal is > always handled by interrupting whatever code was executing and > directly exit after

[go-nuts] Re: go/types.Typ is a slice-of-pointer-to-struct yet uses map syntax

2017-02-15 Thread howardcshaw
Invalid, Bool, Int, Int8 there are const integers, and they are specifying the entry's position in the slice, allowing gaps in the list to be implicitly defined. See this example: https://play.golang.org/p/KVqO40R6mP -- You received this message because you are subscribed to the Google Groups

Re: [go-nuts] How to run deferred function in main() on panic() in a goroutine?

2017-02-15 Thread 'Axel Wagner' via golang-nuts
You might also want to consider running the stuff in a separate process. But honestly, you can't really be sure anyway, for asynchronous signals, because they are - as the name suggest - asynchronous. Between you calling kill and the signal actually being delivered and interrupting the process, it

[go-nuts] Re: weak hash for (MongoDb like) data server

2017-02-15 Thread Tamás Gulácsi
> The id of data items is the only way to refer to data items on the > protocol side. So I need a *weak association* between an id and the data > item (if any) of that id. I do not want to keep (in some ordinary Go map, > for example) the association between ids and their data items

Re: [go-nuts] Compressing 2.5 GB data trims files

2017-02-15 Thread Shawn Milochik
You're ignoring the error on os.Stat. -- 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

Re: [go-nuts] How to run deferred function in main() on panic() in a goroutine?

2017-02-15 Thread roger peppe
Could you run the C code in its own OS thread by using LockOSThread and then send a signal to that thread directly? On 15 February 2017 at 18:26, Yucong Sun wrote: > Also, my cleanup function must be tied directly with C loop, because > they are sharing the same underlaying

Re: [go-nuts] How to run deferred function in main() on panic() in a goroutine?

2017-02-15 Thread 'Axel Wagner' via golang-nuts
You misunderstood what I was trying to do (the recover was supposed to recover from any panic raised by the C-code, not from the panic of the main loop). And just added a new requirement. I don't think what you want is possible, from what I know about the go runtime. You could approximate it, by

Re: [go-nuts] How to run deferred function in main() on panic() in a goroutine?

2017-02-15 Thread Yucong Sun
So, to give more background, i am trying to porting a C based interpreter to Go. In the single threaded C code, the signal is always handled by interrupting whatever code was executing and directly exit after executing some "crash()" cleanup function. Now, I ported the main function to Go, as I

Re: [go-nuts] How to run deferred function in main() on panic() in a goroutine?

2017-02-15 Thread 'Axel Wagner' via golang-nuts
First, the code you wrote here doesn't use os/signal, so you can't really fault Ian for giving that advice. Here's my understanding: In general, there are two kinds of signals: synchronous ones, raised e.g. by dereferencing invalid memory. They produce a runtime panic at the site that produced

[go-nuts] [ANN] NYAGOS 4.1.8_0 - Extended CUI Shell for Windows written in Go

2017-02-15 Thread Kaoru HAYAMA
I released NYAGOS (Nihongo Yet Anothoer GOing Shell) 4.1.8_0, which is the extended CUI Shell for Windows written in Golang. - https://github.com/zetamatta/nyagos (Introduction) - https://github.com/zetamatta/nyagos/releases/tag/4.1.8_0 (download) NYAGOS.EXE is like CMD.EXE but is

Re: [go-nuts] How to run deferred function in main() on panic() in a goroutine?

2017-02-15 Thread Ian Lance Taylor
On Wed, Feb 15, 2017 at 10:26 AM, Yucong Sun wrote: > Also, my cleanup function must be tied directly with C loop, because > they are sharing the same underlaying memory/state . If I directly > run cleanup() while C loop was running, there could be race. > > So that leaves

Re: [go-nuts] Why get an element from []interface{} `arr[0] == nil` is not true?

2017-02-15 Thread roger peppe
In addition to what others have said, note that the comparison works as you expected if you use a typed nil: https://play.golang.org/p/jA57mTKbxa On 15 February 2017 at 08:40, Felix Sun wrote: > https://play.golang.org/p/qYA8Ddnnye > > ``` > > package main > > import ( >

Re: [go-nuts] How to run deferred function in main() on panic() in a goroutine?

2017-02-15 Thread Yucong Sun
https://play.golang.org/p/7Vz0o4ZoQF shows that your code doesn't really work. My understanding is once panic reaches the current goroutine's top of callstack, program will crash, there are no attempt to call other goroutine's deferred function. So, in order to do what I want, i must be able

[go-nuts] Re: empty nested template definitions not working as expected

2017-02-15 Thread mhhcbon
Hi, see this play, https://play.golang.org/p/s-GdewdWz_ In my understanding, as the template is empty, it is not added to the templates tree, i suspect it has something to do with that, https://golang.org/src/text/template/parse/parse.go?#L243 Maybe a non breakable space like will do the

Re: [go-nuts] Are the tests in the Go source code considered "Unit" tests?

2017-02-15 Thread so . query
I see, Thank you both for your comments. On Wednesday, February 15, 2017 at 7:23:25 AM UTC-8, Ian Lance Taylor wrote: > > On Tue, Feb 14, 2017 at 10:35 PM, > wrote: > > > > From my understanding Unit Tests should focus on testing a single > feature > > and not use the

Re: [go-nuts] How to run deferred function in main() on panic() in a goroutine?

2017-02-15 Thread Yucong Sun
hi, Maybe I wasn't clear, I am indeed using os.signal package. But it doesn't do what I want! I want to trigger a panic in main function , seems there is no way to do it by using a signal channel . Thanks -- You received this message because you are subscribed to the Google Groups

Re: [go-nuts] CodeReviewComments: Recommendation of gofmt

2017-02-15 Thread roger peppe
On 15 February 2017 at 13:48, wrote: >> >> > Side-note: I don't think goimports can actually do what you are saying, >> > can it? Because, if you run goimports on a valid program, it won't actually >> > *change* any imports, it might just reformat it. For goimports to

Re: [go-nuts] Compressing 2.5 GB data trims files

2017-02-15 Thread Kale Blankenship
Did you try with the example I provided on your GH issue? https://play.golang.org/p/u6eAphPRrk On Wed, Feb 15, 2017 at 10:14 AM Mukund 8kmiles wrote: > Hi , > > Has anyone tried compressing > ~2.5 GB of data using golang. > > The following function compresses files. Files

Re: [go-nuts] How to run deferred function in main() on panic() in a goroutine?

2017-02-15 Thread Yucong Sun
Also, my cleanup function must be tied directly with C loop, because they are sharing the same underlaying memory/state . If I directly run cleanup() while C loop was running, there could be race. So that leaves me with no choice, i must be able to panic on the C loop's go-routine on async

[go-nuts] empty nested template definitions not working as expected

2017-02-15 Thread Manlio Perillo
Hi. I have found an unexpected behavior with the html/template package. This is a sample program: https://play.golang.org/p/Yh7UZJxQOd It will print: Test 2 Test However, suppose I want to "disable" the "head" template; the reasonable solution is to define an empty

[go-nuts] Organizing a lot of implementations for single interface

2017-02-15 Thread Luca Looz
I'm developing a library where i have 1 common interface and a lot of implementations (likely hundreds). A single implementation is not too complex and can reside in a single source file but then i have visibility issues with constants etc. Should i just create a package for each

Re: [go-nuts] Re: go/types.Typ is a slice-of-pointer-to-struct yet uses map syntax

2017-02-15 Thread Will Faught
Ah, I forgot about that syntax. Thanks! On Wed, Feb 15, 2017 at 11:31 AM wrote: > Invalid, Bool, Int, Int8 there are const integers, and they are specifying > the entry's position in the slice, allowing gaps in the list to be > implicitly defined. > > See this example:

[go-nuts] Re: Compressing 2.5 GB data trims files

2017-02-15 Thread Dave Cheney
Or use https://godoc.org/io/ioutil#ReadFile By really you don't need to buffer all the data in memory, io.Copy will do that for you in, err := os.Open(input) check(err) defer in.Close() out, err := os.Create(output) gz := gzip.New.Writer(out) _, err = io.Copy(gz, in) check(err) err = gz.Close()

[go-nuts] encoding/binary partial read errors

2017-02-15 Thread Eric Buth
The ReadUvarint implementation (and ReadVarint which depends on it) reads from a io.ByteReader until it encounters a leading 0 bit indicating the end of the last byte of a varint. If it encounters an io.EOF error at any point, that error is passed back to the caller. The issue is that the

Re: [go-nuts] TLS server to save client certificates after a request is received

2017-02-15 Thread Janne Snabb
The certificate byte stream is available in the Raw field of the Certificate struct. You can for example output received certificates PEM encoded like this: for _, c := range r.TLS.PeerCertificates { pem.Encode(os.Stdout, {Type: "CERTIFICATE", Bytes: c.Raw}) } Or you can just save c.Raw in

[go-nuts] go/types.Typ is a slice-of-pointer-to-struct yet uses map syntax

2017-02-15 Thread Will Faught
The go/types.Typ decl: var Typ = []*Basic{ Invalid: {Invalid, 0, "invalid type"}, Bool: {Bool, IsBoolean, "bool"}, Int: {Int, IsInteger, "int"}, Int8: {Int8, IsInteger, "int8"}, ... } Typ is a slice of pointer to

Re: [go-nuts] How to run deferred function in main() on panic() in a goroutine?

2017-02-15 Thread Yucong Sun
In single threaded C code, The interrupter loop is guaranteed stop when crash() is executing, Now in Go code, however, the interrupter loop could still be executing when crash() is running. because there is no way to interrupt a go routine beside a panic(), but like you said, i can't induce

[go-nuts] Re: Compressing 2.5 GB data trims files

2017-02-15 Thread howardcshaw
While it is not clear from the Buffer documentation, the Reader *interface* documentation (which Buffer.Read implements implicitly) does state "up to len(p) bytes." You are ignoring how many bytes it read and assuming that the one read is reading the whole file. I am not sure that this is

Re: [go-nuts] go/types.Typ is a slice-of-pointer-to-struct yet uses map syntax

2017-02-15 Thread Ian Lance Taylor
On Wed, Feb 15, 2017 at 11:08 AM, Will Faught wrote: > The go/types.Typ decl: > > var Typ = []*Basic{ > Invalid: {Invalid, 0, "invalid type"}, > > Bool: {Bool, IsBoolean, "bool"}, > Int: {Int, IsInteger, "int"}, >

[go-nuts] [ANN] go-getch - a Library to read the console-event (keyboard-hit or screen-resize) on Windows

2017-02-15 Thread Kaoru HAYAMA
I wrote a library to read console-events (key-hit and/or window-resize) on Microsoft-Windows Console. - https://github.com/zetamatta/go-getch Example: e := getch.All() if k := e.Key; k != nil { fmt.Printf("\n%c %08X %08X %08X\n", k.Rune, k.Rune,

Re: [go-nuts] How to run deferred function in main() on panic() in a goroutine?

2017-02-15 Thread Ian Lance Taylor
On Wed, Feb 15, 2017 at 12:35 AM, wrote: > > I have a situation that need some advice. I have a main loop that is calling > some C code (potentially looping forever). and I need to handle signals > like SIGABRT correctly by ensuring a cleanup function was run. > > func main() {