Re: [go-nuts] Why GO111MODULE=auto go get does not always work?

2021-02-24 Thread Peng Yu
Hi Shulhan,

> https://golang.org/ref/mod#mod-commands
>
> If you run the "go get" command on directory that does not contains "go.mod"
> file, its basically equal to "GO111MODULE=off go get", without module
> aware.
>
> Where do you get the above commands?

I made them up.

> rsc.io/quote is an example of
> repository to explain of how Go module works and not works if run without Go
> module-aware.
>
> https://github.com/golang/go/issues/26367

So `GO111MODULE=auto go get ` should work for any other packages
except rsc.io/quote?

-- 
Regards,
Peng

-- 
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/CABrM6wnCpiPOH%3DmS%2B5GcLLUJkwO3D8W8UswUFi-QMOv%3DhCNYQw%40mail.gmail.com.


[go-nuts] Why GO111MODULE=auto go get does not always work?

2021-02-24 Thread Peng Yu
Hi,

`GO111MODULE=auto go get` does not always work. What causes this bug? Thanks.

$ GO111MODULE=auto go get golang.org/x/net/html
$ GO111MODULE=auto go get rsc.io/quote
/Users/xxx/go/src/rsc.io/quote/quote.go:8:8: code in directory
/Users/xxx/go/src/rsc.io/quote/v3 expects import "rsc.io/quote"

-- 
Regards,
Peng

-- 
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/CABrM6wmA_T-DAqLbSxj0yuN%2BVWfqAEMzMsZLPN39FtH487dedQ%40mail.gmail.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Peng Yu
>> I don’t understand why ping does not have the same problem. Ping is not
>> based on C library?
>>
>
> Looking at the source code, the ping command on macOS use gethostbyname2()
> [1][2], while the Go on macOS use C library through getaddrinfo [3][4].

If so, I'd consider it as a performance bug of net.Dial() on macOS.
After all, the following command runs quickly to resolve an IP address
from a name (suffixed with .local) in /etc/hosts much faster. So
net.Dial() could (and probably should) just use this (or something
along this line) on macOS to fix the performance problem.

net.ResolveIPAddr("ip4", addr)

-- 
Regards,
Peng

-- 
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/CABrM6w%3Dfb_BXwdbcfJzfrMafRhfj6mxzVZ_5udx9yo5iFpWgSw%40mail.gmail.com.


[go-nuts] ICMP in golang

2021-02-23 Thread Peng Yu
Hi,

I see this ICMP example. But somebody says it is too old. What is the
current way to ping a target in go? Thanks.

https://gist.github.com/lmas/c13d1c9de3b2224f9c26435eb56e6ef3

-- 
Regards,
Peng

-- 
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/CABrM6wmK8Abw%2BSZU5EjqPXr7bN-WXYz70SANWfff%3DuFCmotXuQ%40mail.gmail.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Peng Yu
Hi Robert,

Ian Lance Taylor said the exact opposite. "On Darwin I believe that by
default we pass DNS lookups to the C
library." (I assume "we" means Go developers.)

Are you correct or Ian is correct?

On Tue, Feb 23, 2021 at 8:14 AM Robert Engels  wrote:
>
> As I pointed out, Go does not use the C library.
>
> > On Feb 23, 2021, at 7:57 AM, Peng Yu  wrote:
> >
> > This does not answer the question why net.Dial can not be made with
> > the same behavior as ping on MacOSX. If the C library behaves
> > differently on MacOSX and Linux, then the C library should not be
> > relied on in this case. I just want to use /etc/hosts but not
> > resolve.conf.
> >
> >> On 2/22/21, robert engels  wrote:
> >> It looks like the Go runtime implements its own DNS client on *unix
> >> platforms including OSX.
> >>
> >>>> On Feb 22, 2021, at 11:40 PM, Peng Yu  wrote:
> >>>
> >>> I don’t understand why ping does not have the same problem. Ping is not
> >>> based on C library?
> >>>
> >>> On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor  >>> <mailto:i...@golang.org>> wrote:
> >>> On Mon, Feb 22, 2021 at 9:11 PM Peng Yu  >>> <mailto:pengyu...@gmail.com>> wrote:
> >>>>
> >>>> I tried 1.16.
> >>>>
> >>>> $ go version
> >>>> go version go1.16 darwin/amd64
> >>>>
> >>>> The problem still exists. When I change mymachine.local to
> >>>> mymachine_local, the problem is gone. So somehow, this is related to
> >>>> host resolution? It might try to DNS lookup the hostname, when it can
> >>>> not find it via DNS then it look up in /etc/hosts?
> >>>
> >>> On Darwin I believe that by default we pass DNS lookups to the C
> >>> library.  So I think that what you are seeing is the behavior of the C
> >>> library.  Try setting the environment variable GODEBUG=netdns=go.
> >>>
> >>> Ian
> >>>
> >>>
> >>>> On 2/22/21, Ian Lance Taylor mailto:i...@golang.org>>
> >>>> wrote:
> >>>>> On Mon, Feb 22, 2021 at 12:22 PM Peng Yu  >>>>> <mailto:pengyu...@gmail.com>> wrote:
> >>>>>>
> >>>>>> I run the following go program using net.Dial(). Depending on
> >>>>>> whether
> >>>>>> I specify a local hostname (defined in /etc/hosts) or an IP. I get
> >>>>>> very different runtimes.
> >>>>>>
> >>>>>> But `ping mymachine.local` resolves the hostname to an IP address
> >>>>>> instantaneously. So the two calls of the go program should have the
> >>>>>> same runtimes.
> >>>>>>
> >>>>>> Can anybody reproduce the same runtime problem? Does anybody know
> >>>>>> what
> >>>>>> is wrong with the implementation of net.Dial()? Thanks.
> >>>>>>
> >>>>>> $ ./main mymachine.local:22
> >>>>>> 2021/02/22 14:14:25 before
> >>>>>> 2021/02/22 14:14:30 after
> >>>>>> $ ./main 192.168.1.104:22 <http://192.168.1.104:22/>
> >>>>>> 2021/02/22 14:14:30 before
> >>>>>> 2021/02/22 14:14:30 after
> >>>>>> $ cat main.go
> >>>>>> package main
> >>>>>> import (
> >>>>>>  "net"
> >>>>>>  "log"
> >>>>>>  "os"
> >>>>>> )
> >>>>>>
> >>>>>> func main() {
> >>>>>>  dialAddr := os.Args[1]
> >>>>>>  log.Println("before")
> >>>>>>  _, err := net.Dial("tcp", dialAddr)
> >>>>>>  log.Println("after")
> >>>>>>  if err != nil {
> >>>>>>log.Fatalln(err)
> >>>>>>  }
> >>>>>> }
> >>>>>
> >>>>> Which version of Go are you using?  What operating system are you
> >>>>> running
> >>>>> on?
> >>>>>
> >>>>> It is possible that are running into https://golang.org/issue/35305
> >>>>> <https://golang.org/issue/35305>,
> >>>>> which is fixed in 1.16.
> >>>&

Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-23 Thread Peng Yu
This does not answer the question why net.Dial can not be made with
the same behavior as ping on MacOSX. If the C library behaves
differently on MacOSX and Linux, then the C library should not be
relied on in this case. I just want to use /etc/hosts but not
resolve.conf.

On 2/22/21, robert engels  wrote:
> It looks like the Go runtime implements its own DNS client on *unix
> platforms including OSX.
>
>> On Feb 22, 2021, at 11:40 PM, Peng Yu  wrote:
>>
>> I don’t understand why ping does not have the same problem. Ping is not
>> based on C library?
>>
>> On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor > <mailto:i...@golang.org>> wrote:
>> On Mon, Feb 22, 2021 at 9:11 PM Peng Yu > <mailto:pengyu...@gmail.com>> wrote:
>> >
>> > I tried 1.16.
>> >
>> > $ go version
>> > go version go1.16 darwin/amd64
>> >
>> > The problem still exists. When I change mymachine.local to
>> > mymachine_local, the problem is gone. So somehow, this is related to
>> > host resolution? It might try to DNS lookup the hostname, when it can
>> > not find it via DNS then it look up in /etc/hosts?
>>
>> On Darwin I believe that by default we pass DNS lookups to the C
>> library.  So I think that what you are seeing is the behavior of the C
>> library.  Try setting the environment variable GODEBUG=netdns=go.
>>
>> Ian
>>
>>
>> > On 2/22/21, Ian Lance Taylor mailto:i...@golang.org>>
>> > wrote:
>> > > On Mon, Feb 22, 2021 at 12:22 PM Peng Yu > > > <mailto:pengyu...@gmail.com>> wrote:
>> > >>
>> > >> I run the following go program using net.Dial(). Depending on
>> > >> whether
>> > >> I specify a local hostname (defined in /etc/hosts) or an IP. I get
>> > >> very different runtimes.
>> > >>
>> > >> But `ping mymachine.local` resolves the hostname to an IP address
>> > >> instantaneously. So the two calls of the go program should have the
>> > >> same runtimes.
>> > >>
>> > >> Can anybody reproduce the same runtime problem? Does anybody know
>> > >> what
>> > >> is wrong with the implementation of net.Dial()? Thanks.
>> > >>
>> > >> $ ./main mymachine.local:22
>> > >> 2021/02/22 14:14:25 before
>> > >> 2021/02/22 14:14:30 after
>> > >> $ ./main 192.168.1.104:22 <http://192.168.1.104:22/>
>> > >> 2021/02/22 14:14:30 before
>> > >> 2021/02/22 14:14:30 after
>> > >> $ cat main.go
>> > >> package main
>> > >> import (
>> > >>   "net"
>> > >>   "log"
>> > >>   "os"
>> > >> )
>> > >>
>> > >> func main() {
>> > >>   dialAddr := os.Args[1]
>> > >>   log.Println("before")
>> > >>   _, err := net.Dial("tcp", dialAddr)
>> > >>   log.Println("after")
>> > >>   if err != nil {
>> > >> log.Fatalln(err)
>> > >>   }
>> > >> }
>> > >
>> > > Which version of Go are you using?  What operating system are you
>> > > running
>> > > on?
>> > >
>> > > It is possible that are running into https://golang.org/issue/35305
>> > > <https://golang.org/issue/35305>,
>> > > which is fixed in 1.16.
>> > >
>> > > Ian
>> > >
>> >
>> >
>> > --
>> > Regards,
>> > Peng
>> --
>> Regards,
>> Peng
>>
>> --
>> 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
>> <mailto:golang-nuts+unsubscr...@googlegroups.com>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3D8Orgj3t4MW3%3DMs7L0vy0nFS_EeGjRZ8n%2BTvQOrHAO9g%40mail.gmail.com
>> <https://groups.google.com/d/msgid/golang-nuts/CABrM6w%3D8Orgj3t4MW3%3DMs7L0vy0nFS_EeGjRZ8n%2BTvQOrHAO9g%40mail.gmail.com?utm_medium=email_source=footer>.
>
>


-- 
Regards,
Peng

-- 
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/CABrM6wkmMj7GgAckj6%3DcHZqd0vxnH0735%2BAc4n7zV%3D%3DBhD4Z8Q%40mail.gmail.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread Peng Yu
I don’t understand why ping does not have the same problem. Ping is not
based on C library?

On Mon, Feb 22, 2021 at 11:20 PM Ian Lance Taylor  wrote:

> On Mon, Feb 22, 2021 at 9:11 PM Peng Yu  wrote:
> >
> > I tried 1.16.
> >
> > $ go version
> > go version go1.16 darwin/amd64
> >
> > The problem still exists. When I change mymachine.local to
> > mymachine_local, the problem is gone. So somehow, this is related to
> > host resolution? It might try to DNS lookup the hostname, when it can
> > not find it via DNS then it look up in /etc/hosts?
>
> On Darwin I believe that by default we pass DNS lookups to the C
> library.  So I think that what you are seeing is the behavior of the C
> library.  Try setting the environment variable GODEBUG=netdns=go.
>
> Ian
>
>
> > On 2/22/21, Ian Lance Taylor  wrote:
> > > On Mon, Feb 22, 2021 at 12:22 PM Peng Yu  wrote:
> > >>
> > >> I run the following go program using net.Dial(). Depending on whether
> > >> I specify a local hostname (defined in /etc/hosts) or an IP. I get
> > >> very different runtimes.
> > >>
> > >> But `ping mymachine.local` resolves the hostname to an IP address
> > >> instantaneously. So the two calls of the go program should have the
> > >> same runtimes.
> > >>
> > >> Can anybody reproduce the same runtime problem? Does anybody know what
> > >> is wrong with the implementation of net.Dial()? Thanks.
> > >>
> > >> $ ./main mymachine.local:22
> > >> 2021/02/22 14:14:25 before
> > >> 2021/02/22 14:14:30 after
> > >> $ ./main 192.168.1.104:22
> > >> 2021/02/22 14:14:30 before
> > >> 2021/02/22 14:14:30 after
> > >> $ cat main.go
> > >> package main
> > >> import (
> > >>   "net"
> > >>   "log"
> > >>   "os"
> > >> )
> > >>
> > >> func main() {
> > >>   dialAddr := os.Args[1]
> > >>   log.Println("before")
> > >>   _, err := net.Dial("tcp", dialAddr)
> > >>   log.Println("after")
> > >>   if err != nil {
> > >> log.Fatalln(err)
> > >>   }
> > >> }
> > >
> > > Which version of Go are you using?  What operating system are you
> running
> > > on?
> > >
> > > It is possible that are running into https://golang.org/issue/35305,
> > > which is fixed in 1.16.
> > >
> > > Ian
> > >
> >
> >
> > --
> > Regards,
> > Peng
>
-- 
Regards,
Peng

-- 
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/CABrM6w%3D8Orgj3t4MW3%3DMs7L0vy0nFS_EeGjRZ8n%2BTvQOrHAO9g%40mail.gmail.com.


Re: [go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread Peng Yu
I tried 1.16.

$ go version
go version go1.16 darwin/amd64

The problem still exists. When I change mymachine.local to
mymachine_local, the problem is gone. So somehow, this is related to
host resolution? It might try to DNS lookup the hostname, when it can
not find it via DNS then it look up in /etc/hosts?

On 2/22/21, Ian Lance Taylor  wrote:
> On Mon, Feb 22, 2021 at 12:22 PM Peng Yu  wrote:
>>
>> I run the following go program using net.Dial(). Depending on whether
>> I specify a local hostname (defined in /etc/hosts) or an IP. I get
>> very different runtimes.
>>
>> But `ping mymachine.local` resolves the hostname to an IP address
>> instantaneously. So the two calls of the go program should have the
>> same runtimes.
>>
>> Can anybody reproduce the same runtime problem? Does anybody know what
>> is wrong with the implementation of net.Dial()? Thanks.
>>
>> $ ./main mymachine.local:22
>> 2021/02/22 14:14:25 before
>> 2021/02/22 14:14:30 after
>> $ ./main 192.168.1.104:22
>> 2021/02/22 14:14:30 before
>> 2021/02/22 14:14:30 after
>> $ cat main.go
>> package main
>> import (
>>   "net"
>>   "log"
>>   "os"
>> )
>>
>> func main() {
>>   dialAddr := os.Args[1]
>>   log.Println("before")
>>   _, err := net.Dial("tcp", dialAddr)
>>   log.Println("after")
>>   if err != nil {
>> log.Fatalln(err)
>>   }
>> }
>
> Which version of Go are you using?  What operating system are you running
> on?
>
> It is possible that are running into https://golang.org/issue/35305,
> which is fixed in 1.16.
>
> Ian
>


-- 
Regards,
Peng

-- 
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/CABrM6wkj52WUD-ozY%3Djt2mnGXTpYf0wTmRNmLi18OfbA2hccdg%40mail.gmail.com.


[go-nuts] Why can net.Dial be very slow on a hostname defined in /etc/hosts?

2021-02-22 Thread Peng Yu
Hi,

I run the following go program using net.Dial(). Depending on whether
I specify a local hostname (defined in /etc/hosts) or an IP. I get
very different runtimes.

But `ping mymachine.local` resolves the hostname to an IP address
instantaneously. So the two calls of the go program should have the
same runtimes.

Can anybody reproduce the same runtime problem? Does anybody know what
is wrong with the implementation of net.Dial()? Thanks.

$ ./main mymachine.local:22
2021/02/22 14:14:25 before
2021/02/22 14:14:30 after
$ ./main 192.168.1.104:22
2021/02/22 14:14:30 before
2021/02/22 14:14:30 after
$ cat main.go
package main
import (
  "net"
  "log"
  "os"
)

func main() {
  dialAddr := os.Args[1]
  log.Println("before")
  _, err := net.Dial("tcp", dialAddr)
  log.Println("after")
  if err != nil {
log.Fatalln(err)
  }
}

-- 
Regards,
Peng

-- 
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/CABrM6w%3DavxDHaK%2BOu_KaSdKmvpWhERyfLSoUL0q_UtowbD-%3DEg%40mail.gmail.com.


[go-nuts] Best batch processing example in go

2018-01-23 Thread Peng Yu
Hi,

I'd like to implement batch processing in go. There should be a goroutine
for reading input and several worker goroutines for processing the input in
chunks. The workers may not finish  processing the chunks in the same order
as they are in the input. But the processing results should be output in
the same order as the chunks in the input.

I see a number of resources that are relevant to the above goal. But I am
not sure what is the best solution in terms of how easy the code is and how
much less performance overhead there is. Does anyone have any advice on the
best solution to this problem? Thanks.

P.S., here is one webpage, but it does not allow multiple workers.

https://blog.drkaka.com/batch-get-from-golangs-buffered-channel-9638573f0c6e
-- 
Regards,
Peng

-- 
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] What is go concurrency based on?

2018-01-22 Thread Peng Yu
Hi, I'd like to know what go concurrency is based on. For example, nodejs
is based on libev, making nodejs more efficient than using multithreading
to handle concurrency. What is go based on to make go concurrency more
effecient than multithreading?
-- 
Regards,
Peng

-- 
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] Is there something similar to cmp in python?

2018-01-21 Thread Peng Yu
This only applies to string but not other types like int.

On Sun, Jan 21, 2018 at 8:18 AM Arie van Wingerden <xapw...@gmail.com>
wrote:

> https://golang.org/src/strings/compare.go
>
> 2018-01-21 14:42 GMT+01:00 Peng Yu <pengyu...@gmail.com>:
>
>> Hi, cmp() in python can return three values -1, 0, 1. Is there a
>> comparison function in golang that also return three values? Thanks.
>>
>> https://docs.python.org/2/library/functions.html#cmp
>>
>
>> --
>> Regards,
>> Peng
>>
>> --
>> 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.
>>
> --
Regards,
Peng

-- 
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] Is there something similar to cmp in python?

2018-01-21 Thread Peng Yu
Hi, cmp() in python can return three values -1, 0, 1. Is there a
comparison function in golang that also return three values? Thanks.

https://docs.python.org/2/library/functions.html#cmp

-- 
Regards,
Peng

-- 
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] Can go files be nested in package?

2018-01-20 Thread Peng Yu
Hi,

The following example shows that go files cannot be nested in a
package. Is it so that the go files in a package must be at the root
level of the package?

==> main.go <==
// vim: set noexpandtab tabstop=2:

package main

import (
"fmt"
"./mypackage"
)

func main() {
fmt.Println(mypkg.Add(1, 2))
fmt.Println(mypkg.Double(2))
}
==> mypackage/myfile/myfile.go <==
// vim: set noexpandtab tabstop=2:

package mypkg

func Add(x, y int) int {
return x + y
}

==> mypackage/myfile2/myfile2.go <==
// vim: set noexpandtab tabstop=2:

package mypkg

func Double(x int) int {
return Add(x, y)
}


-- 
Regards,
Peng

-- 
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 import local go files?

2018-01-20 Thread Peng Yu
OK. In this example, if there are multiple the files in mypackage
directory. All of them will be loaded. Is there a way to only import a
single go file when there are multiple go files in a package
directory?

On Sat, Jan 20, 2018 at 4:32 PM, Jan Mercl <0xj...@gmail.com> wrote:
> Look for the term "exported" in the language specification.
>
> On Sat, Jan 20, 2018, 23:30 Peng Yu <pengyu...@gmail.com> wrote:
>>
>> Why is only Add allowed? Where is this documented?
>
> --
>
> -j



-- 
Regards,
Peng

-- 
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 import local go files?

2018-01-20 Thread Peng Yu
Why is only Add allowed? Where is this documented? Thanks.

On Sat, Jan 20, 2018 at 2:49 PM, Jan Mercl <0xj...@gmail.com> wrote:
>
> On Sat, Jan 20, 2018 at 9:29 PM Peng Yu <pengyu...@gmail.com> wrote:
>
> s/add/Add/g
>
>
> --
>
> -j



-- 
Regards,
Peng

-- 
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 import local go files?

2018-01-20 Thread Peng Yu
Hi,

I would like to import go files local. But I got the following error
when I try use `add()`. Does anybody know how to fix the error?
Thanks.

$ cat.sh mypackage/myfile.go main.go
==> mypackage/myfile.go <==
package mypackage

import "fmt"

type Export struct {
}

func (c Export) DoMagic() {
  fmt.Println("Magic function was called")
}

func (c Export) String() string {
  return fmt.Sprint("ta da! \n")
}

func add(x, y int) int {
  return x + y
}

==> main.go <==
package main

import (
  "fmt"
  "./mypackage"
)

func main() {
  var value mypackage.Export
  value.DoMagic()
  fmt.Printf("%s", value)
  fmt.Print(mypackage.add(1, 2))
}
$ go build main.go
# command-line-arguments
./main.go:12:13: cannot refer to unexported name mypackage.add
./main.go:12:13: undefined: mypackage.add


-- 
Regards,
Peng

-- 
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] Is there something like peekable in python?

2018-01-20 Thread Peng Yu
Hi, the concept of peekable iterator from python is very convenient.
Is there something similar in golang.

https://github.com/erikrose/more-itertools/blob/master/more_itertools/more.py#L134

-- 
Regards,
Peng

-- 
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 bufio.Write with a length specified?

2018-01-18 Thread Peng Yu
Dan & Bruno,

I didn't realize that it is as simple as that :) Thanks.

Does it involve any extra copy of the byte slice? Or f.Write literally
access the memory of d and only access 2 bytes of data for writing to
the buffer?

On Thu, Jan 18, 2018 at 5:13 PM, Dan Kortschak
<dan.kortsc...@adelaide.edu.au> wrote:
> If you want to write a length shorter than the slice, make the slice
> shorter. No, seriously...
>
> n, err := f.Write(d[:2])
>
> On Thu, 2018-01-18 at 17:04 -0600, Peng Yu wrote:
>> Hi,
>>
>> The following example shows how to write a byte slice to a buffer.
>> But
>> what if I want only write a length shorter (say 2 instead of 5) than
>> the size of the slice. Is there a function that allows users to
>> specify the length to write? Thanks.
>>
>> $ cat main.go
>> #!/usr/bin/env gorun
>> // vim: set noexpandtab tabstop=2:
>> package main
>>
>> import (
>> "os"
>> "bufio"
>> "fmt"
>> )
>>
>> func main() {
>> f := bufio.NewWriter(os.Stdout)
>> d := []byte{'s', 'o', 'm', 'e', '\n'}
>> n, err := f.Write(d)
>> f.Flush()
>> fmt.Printf("wrote %d bytes, error %q\n", n, err)
>> }
>>
>> --
>> Regards,
>> Peng
>>



-- 
Regards,
Peng

-- 
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 bufio.Write with a length specified?

2018-01-18 Thread Peng Yu
Hi,

The following example shows how to write a byte slice to a buffer. But
what if I want only write a length shorter (say 2 instead of 5) than
the size of the slice. Is there a function that allows users to
specify the length to write? Thanks.

$ cat main.go
#!/usr/bin/env gorun
// vim: set noexpandtab tabstop=2:
package main

import (
"os"
"bufio"
"fmt"
)

func main() {
f := bufio.NewWriter(os.Stdout)
d := []byte{'s', 'o', 'm', 'e', '\n'}
n, err := f.Write(d)
f.Flush()
fmt.Printf("wrote %d bytes, error %q\n", n, err)
}

-- 
Regards,
Peng

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