[go-nuts] Re: [ANNOUNCE] for gopher audiophiles.

2018-08-07 Thread Jimmy Tang
this looks interesting, I've been using various go sox bindings for doing 
various sound processing (for machine learning) will your toolkit aim to 
provide similar functionality but in native go?

On Wednesday, 8 August 2018 04:33:48 UTC+1, Scott Cotton wrote:
>
> Hello all,
>
> I am pleased to announce a new project dedicated to rendering "awesome" 
> sound processing and i/o in Go, ZikiChombo ,  The 
> project is in alpha, and this announcement is mostly geared toward people 
> potentially interested 
> in helping.
>
> (you may want to check out the launch blog post 
>  for a more personal introduction).
>
> Best,
> Scott
>
>
>
>

-- 
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: Custom types for use with range (Go 2)

2018-08-07 Thread Christophe Meessen
If considering user defined Ranger interface, I would strongly suggest to 
look at D's equivalent. The interface is simple and there are many use of 
it. It is trivial to develop a reverse range or ranges that traverse data 
structures (e.g. binary trees) in different ways (once you have generics).

My experience with it (as a beginner) was that it makes the code less 
readable. There is a tendency to overuse it because a "for range" is 
concise and looks simple. But it is not because one has to lookup the 
"Ranger" implementation to understand what it is doing. When you know by 
hart what each "Ranger" does, you can still read and understand the code, 
but this is for the elites. It may give an impression of power to those 
mastering it, but it gives an impression of frustration to people learning 
the language. This also adds the burden to decide which "Ranger" to use, or 
to determine if there is a Ranger for what I want to do. 

The power of Go is its simplicity and readability. Let it stay that way. As 
it has already been said, it's only syntactic sugar.

-- 
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] go go1.10.3 fatal error: runtime: netpoll failed

2018-08-07 Thread Dave Cheney
As Ian explained on the GitHub issue you raised, RHEL5 is not supported by any 
version of Go - the 2.6.18 kernel is below our minimum requirements. 

Dave

-- 
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] How to signal(sigint) blocking goroutine

2018-08-07 Thread Ian Lance Taylor
On Tue, Aug 7, 2018 at 7:02 PM,   wrote:
>
> https://play.golang.org/p/d5n9bYmya3r
>
> I'm new to the go language and trying to figure out how to sigint a blocking
> goroutine.  in the playground code I included an infinite for loop to
> simulate the blocking. In my real world use the for block would be a long
> running file save from an external device.  I appreciate any advice or
> direction that is given.

I'm not sure quite what you mean, but in general you can not send a
signal to a goroutine in Go.  Goroutines are not threads.  If you want
a goroutine to be interruptible, you must write the goroutine to check
whether something is trying to interrupt it; the standard library's
"context" package is often used for this purpose.

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] How to signal(sigint) blocking goroutine

2018-08-07 Thread nateandjenn
https://play.golang.org/p/d5n9bYmya3r

I'm new to the go language and trying to figure out how to sigint a 
blocking goroutine.  in the playground code I included an infinite for loop 
to simulate the blocking. In my real world use the for block would be a 
long running file save from an external device.  I appreciate any advice or 
direction that is given.

Thanks.

-- 
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] go go1.10.3 fatal error: runtime: netpoll failed

2018-08-07 Thread neo . ajax1991
 

[root@YF-DGE2 update]# ./watchping

watch agent

watchping: comments to xxx


*The occasional mistake*


[root@YF-DGE2 update]# ./watchping

runtime: epollwait on fd 4 failed with 38

fatal error: runtime: netpoll failed


runtime stack:

runtime.throw(0xc63ded, 0x17)

/usr/local/go_1.10/src/runtime/panic.go:616 +0x81

runtime.netpoll(0x1548caff3150ff00, 0x2b74)

/usr/local/go_1.10/src/runtime/netpoll_epoll.go:75 +0x216

runtime.sysmon()

/usr/local/go_1.10/src/runtime/proc.go:4265 +0x424

runtime.mstart1(0x0)

/usr/local/go_1.10/src/runtime/proc.go:1227 +0xe7

runtime.mstart()

/usr/local/go_1.10/src/runtime/proc.go:1193 +0x76


goroutine 1 [runnable, locked to thread]:

vendor/golang_org/x/net/http2/hpack.newInternalNode(...)

/usr/local/go_1.10/src/vendor/golang_org/x/net/http2/hpack/huffman.go:117

vendor/golang_org/x/net/http2/hpack.addDecoderNode(0xfe20002, 0x1c)

/usr/local/go_1.10/src/vendor/golang_org/x/net/http2/hpack/huffman.go:137 
+0xdf

vendor/golang_org/x/net/http2/hpack.init.0()

/usr/local/go_1.10/src/vendor/golang_org/x/net/http2/hpack/huffman.go:127 
+0x75

-- 
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] buffer.WriteString Error case

2018-08-07 Thread Sam Whited
On Tue, Aug 7, 2018, at 19:43, Ian Lance Taylor wrote:
> So that it implements the (unexported) interface io.stringWriter.

I've wondered about this for a while; I find myself creating a StringWriter 
interface frequently in various projects. With all the other great standard 
interfaces in the io package, I wonder why this one wasn't exported?

—Sam

-- 
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] [ANNOUNCE] for gopher audiophiles.

2018-08-07 Thread Scott Cotton
Hello all,

I am pleased to announce a new project dedicated to rendering "awesome" 
sound processing and i/o in Go, ZikiChombo ,  The 
project is in alpha, and this announcement is mostly geared toward people 
potentially interested 
in helping.

(you may want to check out the launch blog post 
 for a more personal introduction).

Best,
Scott



-- 
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] buffer.WriteString Error case

2018-08-07 Thread Dave Cheney
So that it can be used interchangeably with *bufio.Writer. 

-- 
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] buffer.WriteString Error case

2018-08-07 Thread Ian Lance Taylor
On Tue, Aug 7, 2018 at 10:17 AM, Rohit Jain  wrote:
>
> I Just happened to look at below comment on *WriteString*
>
> ```// WriteString appends the contents of s to the buffer, growing the buffer 
> as
> // needed. The return value n is the length of s; err is always nil. If the
> // buffer becomes too large, WriteString will panic with ErrTooLarge.```
>
> >`err is always nil` and it panics if the buffer is very large
>
> Can someone explain to me why do this method returns an error then?

So that it implements the (unexported) interface io.stringWriter.

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] Re: How to update packages without duplicating distro packages

2018-08-07 Thread Space A.
Hi,

I'm using this approach as workaround:
cd $GOPATH/src && for dir in github.com/*/* golang.org/*/* gopkg.in/*; do 
go get -u $dir; done



понедельник, 6 августа 2018 г., 7:12:58 UTC+3 пользователь Kevin Locke 
написал:
>
> Hello, 
>
> Is there a way to update packages installed using `go get` without 
> duplicating packages that are distributed with Go or by my Linux 
> distribution? 
>
> Background:  I'm not a Go developer (yet).  I am using some programs 
> written in Go, which I installed using `go get`, and would like to 
> keep those programs up to date.  Running `go get -u all` or 
> `cd ~/go && go get -u ./...` both result in many packages being 
> downloaded and rebuilt unnecessarily (and more with each invocation), 
> which slows updates significantly and wastes a lot of disk space. 
> Is there a command which I can run that only updates the packages I 
> have installed and their dependencies without updating packages 
> installed system-wide? 
>
> As a specific example (using Debian golang-go 2:1.10~5): 
>
> $ rm -rf ~/go 
> $ go get -u mvdan.cc/sh/cmd/shfmt 
> $ cd ~/go 
> $ du -hs . 
> 7.8M. 
> $ go list ./... | wc -l 
> 6 
> $ go get -u ./... 
> $ du -hs . 
> 46M. 
> $ go list ./... | wc -l 
> 98 
> $ go get -u ./... 
> $ du -hs . 
> 111M. 
> $ go list ./... | wc -l 
> 160 
> $ du -hs . 
> 181M. 
> $ go list ./... | wc -l 
> 235 
>
> (Since each `go get` takes longer to complete, I have not waited until 
> a stable state is reached.) 
>
> Any suggestions or pointers to documentation that I may have 
> overlooked would be much appreciated. 
>
> Thanks, 
> Kevin 
>

-- 
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: How to update packages without duplicating distro packages

2018-08-07 Thread Space A.
Sorry, this one has correct paths:

cd $GOPATH/src && for dir in github.com/*/* golang.org/*/* gopkg.in/*; do 
echo "go get -u $dir"; done





среда, 8 августа 2018 г., 1:30:53 UTC+3 пользователь Space A. написал:
>
> Hi,
>
> I'm using this approach as workaround:
>
> for dir in src/github.com/*/* src/golang.org/*/* src/gopkg.in/*; do go 
> get -u $dir; done
>
>
>
> понедельник, 6 августа 2018 г., 7:12:58 UTC+3 пользователь Kevin Locke 
> написал:
>>
>> Hello, 
>>
>> Is there a way to update packages installed using `go get` without 
>> duplicating packages that are distributed with Go or by my Linux 
>> distribution? 
>>
>> Background:  I'm not a Go developer (yet).  I am using some programs 
>> written in Go, which I installed using `go get`, and would like to 
>> keep those programs up to date.  Running `go get -u all` or 
>> `cd ~/go && go get -u ./...` both result in many packages being 
>> downloaded and rebuilt unnecessarily (and more with each invocation), 
>> which slows updates significantly and wastes a lot of disk space. 
>> Is there a command which I can run that only updates the packages I 
>> have installed and their dependencies without updating packages 
>> installed system-wide? 
>>
>> As a specific example (using Debian golang-go 2:1.10~5): 
>>
>> $ rm -rf ~/go 
>> $ go get -u mvdan.cc/sh/cmd/shfmt 
>> $ cd ~/go 
>> $ du -hs . 
>> 7.8M. 
>> $ go list ./... | wc -l 
>> 6 
>> $ go get -u ./... 
>> $ du -hs . 
>> 46M. 
>> $ go list ./... | wc -l 
>> 98 
>> $ go get -u ./... 
>> $ du -hs . 
>> 111M. 
>> $ go list ./... | wc -l 
>> 160 
>> $ du -hs . 
>> 181M. 
>> $ go list ./... | wc -l 
>> 235 
>>
>> (Since each `go get` takes longer to complete, I have not waited until 
>> a stable state is reached.) 
>>
>> Any suggestions or pointers to documentation that I may have 
>> overlooked would be much appreciated. 
>>
>> Thanks, 
>> Kevin 
>>
>

-- 
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] Point by Reference in Golang

2018-08-07 Thread paulhay88
Hey guys, just looking for some direction on some good reference material 
on GO's point by reference

Just learning and looking to read up some more on a few things i struggle 
with, any help would be appreciated

Thank you

-- 
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: How to update packages without duplicating distro packages

2018-08-07 Thread Space A.
Hi,

I'm using this approach as workaround:

for dir in src/github.com/*/* src/golang.org/*/* src/gopkg.in/*; do go get 
-u $dir; done



понедельник, 6 августа 2018 г., 7:12:58 UTC+3 пользователь Kevin Locke 
написал:
>
> Hello, 
>
> Is there a way to update packages installed using `go get` without 
> duplicating packages that are distributed with Go or by my Linux 
> distribution? 
>
> Background:  I'm not a Go developer (yet).  I am using some programs 
> written in Go, which I installed using `go get`, and would like to 
> keep those programs up to date.  Running `go get -u all` or 
> `cd ~/go && go get -u ./...` both result in many packages being 
> downloaded and rebuilt unnecessarily (and more with each invocation), 
> which slows updates significantly and wastes a lot of disk space. 
> Is there a command which I can run that only updates the packages I 
> have installed and their dependencies without updating packages 
> installed system-wide? 
>
> As a specific example (using Debian golang-go 2:1.10~5): 
>
> $ rm -rf ~/go 
> $ go get -u mvdan.cc/sh/cmd/shfmt 
> $ cd ~/go 
> $ du -hs . 
> 7.8M. 
> $ go list ./... | wc -l 
> 6 
> $ go get -u ./... 
> $ du -hs . 
> 46M. 
> $ go list ./... | wc -l 
> 98 
> $ go get -u ./... 
> $ du -hs . 
> 111M. 
> $ go list ./... | wc -l 
> 160 
> $ du -hs . 
> 181M. 
> $ go list ./... | wc -l 
> 235 
>
> (Since each `go get` takes longer to complete, I have not waited until 
> a stable state is reached.) 
>
> Any suggestions or pointers to documentation that I may have 
> overlooked would be much appreciated. 
>
> Thanks, 
> Kevin 
>

-- 
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: Custom types for use with range (Go 2)

2018-08-07 Thread Matt Sherman
Sorry for late reply: yes, it’s sugar, and a first implementation might be 
to have the compiler simply rewrite it like a macro, as in your example.

And I realize that my example was more verbose than need be. We don’t call 
an iterator on arrays, maps, etc, so my example should have been:

for t := range tokenizer { 
   // etc 
}

I.e., need to call .Range(), since the point of the ‘interface' is to let 
the compiler infer how to iterate.

It’s quite a lot less boilerplate, while keeping the intent clear, and 
maybe even preventing some classes of user error.


On Friday, July 20, 2018 at 9:24:18 AM UTC-4, Juliusz Chroboczek wrote:
>
> > for t := range tokenizer.Next() { 
> > // etc 
> > } 
>
> Isn't that just syntactic sugar for 
>
> for t, more := f(); more; t, more = f() { 
> ... 
> } 
>
> ? 
>
>
>

-- 
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: looking for a flexible file path resolver

2018-08-07 Thread Marvin Renich
* DrGo  [180806 18:37]:
> There are situations where you need to check (and report back to the user) 
> for file existence no matter how you do that (using Stat or by attempting 
> to open or create it). 

I agree completely.  However, doesn't os.Stat do what you want here
simply and portably?  If not, what would you like from such a function?
Note that path canonicalization is orthogonal to this.

> There are several issues with the approach you described, which is 
> essentially what fileapth.Abs() does, some are discussed here 
> https://github.com/golang/go/issues/17084
>  and here 

The discussion in the first appears to come to the conclusion that in
some cases it is not possible to get a unique canonical name.  Two
different Windows UNC or network paths can point to the same file in a
way that it is not possible for the local machine to be able to
determine this.  The same is true for remotely mounted file systems on
Linux (e.g. NFS or CIFS mounts).

Hard links (both Windows and Linux) are problematic at best.  You could
arbitrarily say that the alphabetically first name was the canonical one
(or use other criteria), but in order to determine all possible names
still requires (worst case) traversing the entire file system directory
structure; from a performance POV, I would not want to do this.

The second link really just describes Java's getCanonicalPath and
related functions, but doesn't really say much else.  The Java doc for
this claims to return a "unique" name, but says nothing about how that
is done for either of the two cases described above.  This is not the
only place where the Java documentation left me wondering how it handled
edge conditions.

A simple test shows that it fails to recognize that a single file with
two hard links in the same directory are the same file.  This is not any
different from failing to replace symbolic links.

So the real question is what are you trying to accomplish with a
canonicalization function?  Are you simply looking for
Abs(EvalSymlinks(path)) except with a guarantee in the documentation for
EvalSymlinks that says both the 8.3 and long file names for the same
file will give identical results?  What transformations do you want it
to perform and what transformations are acceptable to ignore?

* DrGo  [180806 02:00]:
> Thanks,
> filepath.Abs does some of what I want, but as far as I could tell, it does
> not handle resolving relative paths

Can you give an example of how it does not handle relative paths the way
you would like?

I'm having trouble identifying what you believe are the shortcomings of
the simple solutions provided in this thread and the link you gave
above.

...Marvin

-- 
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] wireguardctrl: enables control of WireGuard devices on multiple platforms

2018-08-07 Thread Matt Layher
Hi all, I'm here to share a project I've been working on:

https://github.com/mdlayher/wireguardctrl

I'm not quite finished with this package yet (see issues), but now that 
I've got both the kernel and userspace APIs working, I figured it was time 
to share it to a more broad audience.

For those who aren't familiar, WireGuard (https://www.wireguard.com/) is a 
next-generation VPN that's in the process of being upstreamed into the 
Linux kernel. On top of that, there's a Go userspace implementation which 
works on other platforms as well.

This has been a fun project so far, and I'd appreciate your feedback. 
Thanks!

- Matt

-- 
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] buffer.WriteString Error case

2018-08-07 Thread Rohit Jain
I Just happened to look at below comment on *WriteString*

```// WriteString appends the contents of s to the buffer, growing the
buffer as
// needed. The return value n is the length of s; err is always nil. If the
// buffer becomes too large, WriteString will panic with ErrTooLarge.```

>`err is always nil` and it panics if the buffer is very large

Can someone explain to me why do this method returns an error then?


Thanks
-- 
Rohit Jain

-- 
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: "declared local variable must be used once", is it enforced by Go spec? or just a behavior of gc?

2018-08-07 Thread kristijankantoci
Inside of [] cyles through. Between brackets.

-- 
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: "declared local variable must be used once", is it enforced by Go spec? or just a behavior of gc?

2018-08-07 Thread kristijankantoci
! returns 1; . returns 0;

Op zaterdag 28 juli 2018 15:48:39 UTC+2 schreef T L:
>
> .
>

-- 
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: go/format ouputs spurious newlines

2018-08-07 Thread naha
I think my problem might be related to the logic around line 982 
of https://golang.org/src/go/printer/printer.go.  I don't yet understand 
the distinction between the impliedSemi local variable and the impliedSemi 
field of printer.

How would I fetch and build the go/printer code and install it in my 
development environment to try some experiments?

On Wednesday, July 4, 2018 at 6:38:44 PM UTC-4, Mark Nahabedian wrote:
>
> I'm using go/ast and friends to generate go code.  I'm having trouble
> with spurious newlines being added to the output.  These cause the
> compiler to balk.
>
> For broader context, my code can be found at
>
> https://github.com/MarkNahabedian/Goshua/tree/master/rete/rule_compiler/rule_compiler.go
> .
>
> The point of the code below is to build a map from strings that are
> the names of go types to a function that returns true when invoked on
> an object of that type.  This because I've not found a way to use
> types as first class objects.
>
> // line 214
> e := parseExpression(fmt.Sprintf(
> `rete.EnsureTypeTestRegistered("%s", func(i interface{}) bool { _, ok := 
> i.(%s); return ok })`,
> pType, pType))
> initFunc.Body.List = append(initFunc.Body.List,
> &ast.ExprStmt{ X: e})
>
> // line 221
> newAstFile.Decls = append(newAstFile.Decls, initFunc)
>
> // line 224
> writeFile(fset, newAstFile, outname)
>
>
> parseExpression is defined in ast_helpers.go.  It calls
> parser.ParseExpr and panics if there'sd an error.
>
> writeFile is defined in utils.go.  It calls format.Node to
> serialize the generated source code.
>
>
> Here is some sample output that illustrates the problem I'm observing.
> Note that the spurious whitespace is not added consistently.  Two of
> these three return statements get the error "not enough arguments to
> return" which go away if the extra newlines are removed.
>
> rete.EnsureTypeTestRegistered("Couple", func(i interface{}) bool {
> _, ok := i.(Couple)
> return
>
> ok
> })
> rete.EnsureTypeTestRegistered("FaceToFace", func(i interface{}) bool {
> _,
> ok := i.(FaceToFace)
> return ok
> })
> rete.EnsureTypeTestRegistered("Tandem", func(i interface{}) bool {
> _, ok := i.(Tandem)
> return
>
> ok
> })
>
> Also observe that in the middle case spurious whitespace is added to
> the assignment/declaration statement rather that the return statement.
>
> Why is this happening and how do I prevent it?
>
> Thanks.
>
>

-- 
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] How to refactor out this function

2018-08-07 Thread Tong Sun
Thanks a lot Sam. 

A follow up question, what's the Go way of naming such functions?

Java would name it like "somethingFactory", C# would name it like 
"GetHelloFunction". 

what's the typical Go naming, for a factory function that generates Hello 
handling function? 

thx


On Tuesday, August 7, 2018 at 8:37:45 AM UTC-4, Sam Whited wrote:
>
> You'd want to use a function that returns another function and takes the 
> dependencies as arguments, something like this: 
>
> func Sender(b *B) func(m *tb.Message) { 
> return func(m *tb.Message) { 
> b.Send(m.Sender, "hello world") 
> } 
> } 
>
> s := Sender(b) 
> b.Handle("/hello", s) 
> b.Handle("/hi", s) 
>
>
> —Sam 
>
> On Tue, Aug 7, 2018, at 07:29, Tong Sun wrote: 
> > Hi, 
> > 
> > Consider this function: 
> > 
> > b.Handle("/hello", func(m *tb.Message) { 
> > b.Send(m.Sender, "hello world") 
> > }) 
> > 
> > 
> > I tried to refactor the above function to func sayHi(m *tb.Message) 
> {...}, 
> >  so that I can give an alias to the above /hello command (say to define 
> a 
> > /hi command), but found that I cannot use bwithin it any more. 
> > 
> > So, how to refactor out this function? 
>
>
> -- 
> Sam Whited 
> s...@samwhited.com  
>

-- 
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] CGO - convert a c.char array to string

2018-08-07 Thread Ian Lance Taylor
On Mon, Aug 6, 2018 at 11:34 PM, nicolas_boiteux via golang-nuts
 wrote:
>
> yes i used the code from this page:
>
> func Float64bits(f float64) uint64 {
> return *(*uint64)(unsafe.Pointer(&f))
> }
>
> adapted to my use case
>
> *(*int)(unsafe.Pointer(limit)

As the docs say, that is only permissible when T2 is no larger than T1
and the two share an equivalent memory layout.  In your case T2 is the
Go type `int` and T1 is the C type `int`.  On 64-bit systems the C
type `int` is 32 bits and the Go type `int` is 64 bits.  So T2 is
larger than T1 and your conversion is not permitted by the unsafe
rules.

Ian


> Le lundi 6 août 2018 19:53:07 UTC+2, Ian Lance Taylor a écrit :
>>
>> On Sun, Aug 5, 2018 at 10:29 PM, nicolas_boiteux via golang-nuts
>>  wrote:
>> >
>> > thanks you, the A3 community finaly help me to solve the last problem
>> >
>> > for index := C.int(0); index < argc; index++ {
>> > out = append(out, C.GoString(*argv))
>> > argv = (**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(argv)) +
>> > offset))
>> > }
>> >
>> > I dont really understand why but it seems there was a problem with my
>> > casting method with unsafe
>> >
>> > *(*int)(unsafe.Pointer(limit)
>>
>> See https://golang.org/pkg/unsafe for the exact ways that you are
>> permitted to use unsafe.Pointer.
>>
>> Ian
>>
>> > Le dimanche 5 août 2018 15:02:47 UTC+2, Jan Mercl a écrit :
>> >>
>> >> On Sun, Aug 5, 2018 at 2:50 PM nicolas_boiteux via golang-nuts
>> >>  wrote:
>> >>
>> >> > not sure to understand cause the iteration in your example is done on
>> >> > os
>> >> > interface from golang not from c char array :(
>> >>
>> >> Not sure what you mean by 'os interface'. Here's the part that iterates
>> >> **C.char, except pointers are transformed to uintptrs. Other that that
>> >> it's
>> >> what you're, I think, after
>> >>
>> >> // Xmain is defined at main.c:3:5
>> >> func Xmain(tls crt.TLS, _argc int32, _argv uintptr /* **int8 */) (r
>> >> int32)
>> >> {
>> >> var _p uintptr // **int8
>> >>
>> >> _p = _argv
>> >> _1:
>> >> if (*(*uintptr)(unsafe.Pointer(_p))) == 0 {
>> >> goto _3
>> >> }
>> >>
>> >> crt.Xprintf(tls, ts+0 /* "%s\n" */, *(*uintptr)(unsafe.Pointer(_p)))
>> >> _p += 8
>> >> goto _1
>> >>
>> >> _3:
>> >> return r
>> >> }
>> >>
>> >> Manually converting (untested again):
>> >>
>> >> func foo(argv **C.char) []string {
>> >> var a []string
>> >> for p := argv; *p != nil; *(*uintptr)(unsafe.Pointer(p)) +=
>> >> unsafe.Sizeof(*p) {
>> >> a = append(a, GoString(*p))
>> >> }
>> >> rerurn a
>> >> }
>> >>
>> >>
>> >> --
>> >>
>> >> -j
>> >
>> > --
>> > 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...@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> 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.

-- 
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: Checking if two map variables refer to the same map

2018-08-07 Thread mike
Sorry for bumping a very old thread, but I absolutely disagree with the 
people stating that this problem is contrived, and I got here from a Google 
search, so this might be relevant for some people.

A very real use-case for reference-comparing maps is when testing .Clone() 
methods. You want to make sure that the clone is an actual clone, and that 
all the properties of the cloned object are also a clone, etc. In these 
cases you want to reference-compare everything.

That said, reflect.ValueOf(xxx).Pointer is more than sufficient for this 
use-case.

On Monday, July 15, 2013 at 3:50:01 AM UTC+3, Yi DENG wrote:
>
> There're always something that is not comparable. You can consider map as 
> one of this. If you have to check, use the pointer form.
>
> David
>
> On Saturday, July 13, 2013 7:35:55 PM UTC+8, Jsor wrote:
>>
>> I ask for maps because for slices this seems potentially problematic: 
>> what does "same reference" entail for a slice? Overlapping underlying 
>> arrays? Same starting pointer regardless of whether their len matches? Same 
>> start, end, len, and cap? And so on. Though I guess "reference-equality" 
>> would be pretty well defined for channels.
>>
>> However, for maps determining "sameness" at a reference level seems like 
>> a much more well defined question, and a much simpler one to answer. Yet I 
>> can't figure out a good way to do it. Perhaps with 
>> reflect.Value.UnsafePointer (would that even work)? Either way, that seems 
>> like overcomplicating things. The "easiest" way to do it seems to be 
>> something like this, dreamt up on the go-nuts IRC when I asked this: 
>> http://play.golang.org/p/6Ffxfx7zBb
>>
>> But I think we can all agree that that's a rather silly and limited 
>> solution (and to be fair wasn't suggested in earnest).
>>
>> I can see why == isn't defined on maps, too many people would likely 
>> mistake it for a deep equality test (if that was indeed the reason), but it 
>> seems like there should be some semi-trivial way to see if two map 
>> variables refer to the same map. Perhaps a need just wasn't seen for such 
>> an operation? Maybe it's really a more difficult/expensive test than I 
>> assumed?
>>
>

-- 
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: How should I avoid - literal copies lock value from

2018-08-07 Thread Dave Cheney
Pass a pointer, *Set into your Diff method. 

-- 
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] CGO-How to access C struct pointer correctly

2018-08-07 Thread Jan Mercl
On Tue, Aug 7, 2018 at 2:42 PM 陈一剑  wrote:


> I want to print 333,but the result is strange.

The answer is provided by the compiler itself:

jnml@r550:~/src/tmp> cat main.go
package main

import (
"fmt"
/*
   struct Test{
int ID;
   };


   struct Test * test(){
struct Test test;
test.ID=333;
return &test;
   };
*/
"C"
)

func main() {
b := C.test()
fmt.Println(b.ID)
}
jnml@r550:~/src/tmp> go run main.go
# command-line-arguments
./main.go: In function ‘test’:
./main.go:14:6: warning: function returns address of local variable
[-Wreturn-local-addr]
  return &test;
  ^
1
jnml@r550:~/src/tmp>
-- 

-j

-- 
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: How should I avoid - literal copies lock value from

2018-08-07 Thread Kasun Vithanage
Error is gone when used 

mux *sync.Mutex



On Tuesday, August 7, 2018 at 6:12:26 PM UTC+5:30, Kasun Vithanage wrote:
>
> I'm implementing some thread safe data structures
>
> type Set struct {
>m   map[string]int
>mux sync.Mutex
> }
>
>
> func New() *Set {
>return &Set{m: make(map[string]int)}
> }
>
>
>
> In my Diff function i need to pass an array of sets to do a diff on 
> another set
>
> func (set *Set) DiffS(sets []Set) *Set {
>set.mux.Lock()
>defer set.mux.Unlock()
>dup := duplicateMap(set.m)
>
>for i := 0; i < len(sets); i++ {
>   for _, key := range sets[i].Elems() {
>  delete(dup, key)
>   }
>}
>
>return &Set{m: dup}
> }
>
>
> Code works fine, i ve written a unit test like this
>
> func TestSet_Diff(t *testing.T) {
>set1 := New()
>set2 := New()
>set3 := New()
>
>set1.Add([]string{"a", "b", "c", "d"})
>set2.Add([]string{"c"})
>set3.Add([]string{"a", "b"})
>
>el := set1.Diff([]Set{*set2, *set3})
>testsuite.ContainsElements(t, []string{"d"}, el)
> }
>
>
> This Unit Test passes fine
>
> But when i run the vet command with 
> go vet ./...
>
> I get the following error
> internal\types\set\set_test.go:41: literal copies lock value from *set2: 
> set.Set contains sync.Mutex
> internal\types\set\set_test.go:41: literal copies lock value from *set3: 
> set.Set contains sync.Mutex
>
> What is the ideal solution for this? 
>
>
>

-- 
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] archive/tar and @LongLink

2018-08-07 Thread clewis . cl136
How do I delete these files and delete off my SD card?? 

-- 
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] How should I avoid - literal copies lock value from

2018-08-07 Thread Kasun Vithanage
I'm implementing some thread safe data structures

type Set struct {
   m   map[string]int
   mux sync.Mutex
}


func New() *Set {
   return &Set{m: make(map[string]int)}
}



In my Diff function i need to pass an array of sets to do a diff on another 
set

func (set *Set) DiffS(sets []Set) *Set {
   set.mux.Lock()
   defer set.mux.Unlock()
   dup := duplicateMap(set.m)

   for i := 0; i < len(sets); i++ {
  for _, key := range sets[i].Elems() {
 delete(dup, key)
  }
   }

   return &Set{m: dup}
}


Code works fine, i ve written a unit test like this

func TestSet_Diff(t *testing.T) {
   set1 := New()
   set2 := New()
   set3 := New()

   set1.Add([]string{"a", "b", "c", "d"})
   set2.Add([]string{"c"})
   set3.Add([]string{"a", "b"})

   el := set1.Diff([]Set{*set2, *set3})
   testsuite.ContainsElements(t, []string{"d"}, el)
}


This Unit Test passes fine

But when i run the vet command with 
go vet ./...

I get the following error
internal\types\set\set_test.go:41: literal copies lock value from *set2: set
.Set contains sync.Mutex
internal\types\set\set_test.go:41: literal copies lock value from *set3: set
.Set contains sync.Mutex

What is the ideal solution for this? 


-- 
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] CGO-How to access C struct pointer correctly

2018-08-07 Thread 陈一剑
package main


import (
"fmt"
/*
   struct Test{
int ID;
   };


   struct Test * test(){
struct Test test;
test.ID=333;
return &test;
   };
*/
"C"
)


type c struct {
ID int
}
type Test struct {
a string
b string
}


func main() {
var b *C.struct_Test=C.test()
fmt.Println(b.ID)
}


-
I want to print 333,but the result is strange.

Thanks
Chen


-- 
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] How to refactor out this function

2018-08-07 Thread Sam Whited
You'd want to use a function that returns another function and takes the 
dependencies as arguments, something like this:

func Sender(b *B) func(m *tb.Message) {
return func(m *tb.Message) {
b.Send(m.Sender, "hello world")
}
}

s := Sender(b)
b.Handle("/hello", s)
b.Handle("/hi", s)


—Sam

On Tue, Aug 7, 2018, at 07:29, Tong Sun wrote:
> Hi, 
> 
> Consider this function:
> 
>   b.Handle("/hello", func(m *tb.Message) {
>   b.Send(m.Sender, "hello world")
>   })
> 
> 
> I tried to refactor the above function to func sayHi(m *tb.Message) {...}, 
>  so that I can give an alias to the above /hello command (say to define a 
> /hi command), but found that I cannot use bwithin it any more.
> 
> So, how to refactor out this function?


-- 
Sam Whited
s...@samwhited.com

-- 
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] How to refactor out this function

2018-08-07 Thread Tong Sun
Hi, 

Consider this function:

b.Handle("/hello", func(m *tb.Message) {
b.Send(m.Sender, "hello world")
})


I tried to refactor the above function to func sayHi(m *tb.Message) {...}, 
 so that I can give an alias to the above /hello command (say to define a 
/hi command), but found that I cannot use bwithin it any more.

So, how to refactor out this function?

thx

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