Re: [go-nuts] Bug? go/src/all.bash on master branch fails in go/build test with Go1.18

2022-04-06 Thread 'Axel Wagner' via golang-nuts
The master branch is used for the active development and not for general
consumption. It is not unusual for builds/tests to fail on it occasionally.
You can always check the build dashboard  to see
if that's currently the case.
Generally, I would tend to assume that there is something wrong with your
setup, especially if it also happens on the release-branch.go1.18 branch.

On Thu, Apr 7, 2022 at 12:25 AM tenkoh  wrote:

> I'm unsure whether this is a bug or not, so let me ask here.
>
> *### What version of Go are you using (`go version`)?*
> go version go1.18 linux/arm64
>
> *### Does this issue reproduce with the latest release?*
> Yes
>
> *### What operating system and processor architecture are you using (`go
> env`)?*
> using docker image: golang:1.18
>
> GO111MODULE=""
> GOARCH="arm64"
> GOBIN=""
> GOCACHE="/root/.cache/go-build"
> GOENV="/root/.config/go/env"
> GOEXE=""
> GOEXPERIMENT=""
> GOFLAGS=""
> GOHOSTARCH="arm64"
> GOHOSTOS="linux"
> GOINSECURE=""
> GOMODCACHE="/go/pkg/mod"
> GONOPROXY=""
> GONOSUMDB=""
> GOOS="linux"
> GOPATH="/go"
> GOPRIVATE=""
> GOPROXY="https://proxy.golang.org,direct;
> GOROOT="/usr/local/go"
> GOSUMDB="sum.golang.org"
> GOTMPDIR=""
> GOTOOLDIR="/usr/local/go/pkg/tool/linux_arm64"
> GOVCS=""
> GOVERSION="go1.18"
> GCCGO="gccgo"
> AR="ar"
> CC="gcc"
> CXX="g++"
> CGO_ENABLED="1"
> GOMOD="/go.mod"
> GOWORK=""
> CGO_CFLAGS="-g -O2"
> CGO_CPPFLAGS=""
> CGO_CXXFLAGS="-g -O2"
> CGO_FFLAGS="-g -O2"
> CGO_LDFLAGS="-g -O2"
> PKG_CONFIG="pkg-config"
> GOGCCFLAGS="-fPIC -pthread -fmessage-length=0
> -fdebug-prefix-map=/tmp/go-build2526966007=/tmp/go-build
> -gno-record-gcc-switches"
> GOROOT/bin/go version: go version go1.18 linux/arm64
> GOROOT/bin/go tool compile -V: compile version go1.18
> uname -sr: Linux 5.10.47-linuxkit
> /lib/aarch64-linux-gnu/libc.so.6: GNU C Library (Debian GLIBC
> 2.31-13+deb11u2) stable release version 2.31.
>
> *### What did you do?*
> Get master branch, then run build & test using "all.bash"
>
> ```
> $ cd /
> $ mkdir build
> $ cd build
> $ git clone https://go.googlesource.com/go
> $ cd go/src
> $ ./all.bash
> ```
>
> *### What did you expect to see?*
> Success in build and all tests.
>
>
> *### What did you see instead?*
> --- FAIL: TestImportPackageOutsideModule (0.00s)
> build_test.go:647: error when importing package when no go.mod is
> present: got "no required module provides package example.com/p; to add
> it:\n\tgo get example.com/p"; want "go.mod file not found in current
> directory or any parent directory"
> FAIL
> FAILgo/build0.948s
>
>
> The error occurs in go/src/go/build/build_test.go.
> The same test passed with go 1.17.8.
>
> Best 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/a5ae452c-c991-4a95-8ccb-c698672447bdn%40googlegroups.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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfHTK%3DUnog3Nj0nttgDTOdRgHFAhuURnEBCn6kdX4tY4xg%40mail.gmail.com.


[go-nuts] Bug? go/src/all.bash on master branch fails in go/build test with Go1.18

2022-04-06 Thread tenkoh
I'm unsure whether this is a bug or not, so let me ask here.

*### What version of Go are you using (`go version`)?*
go version go1.18 linux/arm64

*### Does this issue reproduce with the latest release?*
Yes

*### What operating system and processor architecture are you using (`go 
env`)?*
using docker image: golang:1.18

GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct;
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_arm64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -pthread -fmessage-length=0 
-fdebug-prefix-map=/tmp/go-build2526966007=/tmp/go-build 
-gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.18 linux/arm64
GOROOT/bin/go tool compile -V: compile version go1.18
uname -sr: Linux 5.10.47-linuxkit
/lib/aarch64-linux-gnu/libc.so.6: GNU C Library (Debian GLIBC 
2.31-13+deb11u2) stable release version 2.31.

*### What did you do?*
Get master branch, then run build & test using "all.bash"

```
$ cd /
$ mkdir build
$ cd build
$ git clone https://go.googlesource.com/go
$ cd go/src
$ ./all.bash 
```

*### What did you expect to see?*
Success in build and all tests.


*### What did you see instead?*
--- FAIL: TestImportPackageOutsideModule (0.00s)
build_test.go:647: error when importing package when no go.mod is 
present: got "no required module provides package example.com/p; to add 
it:\n\tgo get example.com/p"; want "go.mod file not found in current 
directory or any parent directory"
FAIL
FAILgo/build0.948s


The error occurs in go/src/go/build/build_test.go.
The same test passed with go 1.17.8.

Best 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/a5ae452c-c991-4a95-8ccb-c698672447bdn%40googlegroups.com.


[go-nuts] TMTP messaging protocol

2022-04-06 Thread Liam Breck
TMTP is a protocol [1] to let Internet sites message customers/members
directly, instead of unreliable, insecure email or costly custom apps.

https://mnmnotmail.org
https://twitter.com/mnmnotmail

The open source client [2] and server [3] are written in Go. The client UI
runs in a localhost browser tab, rendered by Vue.js. Feedback &
contributions welcome!

[1] https://github.com/networkimprov/mnm/blob/master/Protocol.md
[2] https://github.com/networkimprov/mnm-hammer
[3] https://github.com/networkimprov/mnm

-- 
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/CAKvHMgTW%3DPnEwg6F3tXVZEFa0pG%2BtmEAdmW-HaOWXiQMgfLpcA%40mail.gmail.com.


Re: [go-nuts] Can generics save virtual function calls?

2022-04-06 Thread Amit Lavon
Thank you!

On Tuesday, April 5, 2022 at 10:05:40 PM UTC+3 Ian Lance Taylor wrote:

> On Tue, Apr 5, 2022 at 11:05 AM Amit Lavon  wrote:
> >
> > When we use an interface as a type parameter, does it mean that calls to 
> that interface will be replaced with calls to the concrete type?
> >
> > To demonstrate, consider https://go.dev/play/p/j4N8G_n-3uG .
> > Will the compiler create a static call to MyDoer.Do instead of a virtual 
> call to Doer.Do?
>
> Occasionally, yes. In general, no. It depends, and it will likely
> vary between different Go compilers and different releases of the same
> Go compiler.
>
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2a760092-7cca-42c0-a806-89223b6f2851n%40googlegroups.com.


[go-nuts] Re: go mod tidy doesn't rewrite go.mod file (shows go: warning "all" matched no packages)

2022-04-06 Thread 'Bryan C. Mills' via golang-nuts
Do you have a go.work file? If so, does it include the module in that 
directory?
(Compare https://go.dev/issue/51604.)

What do `go env GOMOD` and `go env GOWORK` report?

On Friday, April 1, 2022 at 10:05:57 AM UTC-4 vaastav...@gmail.com wrote:

> There is definitely source code in that folder. There is a main.go file as 
> well as 3 other packages. 
> So, go.mod should not be removing all the entries from the go.mod file.
>
> On Friday, 1 April 2022 at 15:43:30 UTC+2 Brian Candler wrote:
>
>> I just updated to 1.18 (from 1.17.6) - on macOS 12.3.1 - and indeed:
>> - with just go.mod, I get the warning and go.mod is cleaned up
>> - with go.mod plus main.go, I get no warning and go.mod is cleaned up
>>
>> This looks to me like a bug fix.  If there is no source code, then by 
>> definition go.mod should not have any dependent modules.
>>
>> On Friday, 1 April 2022 at 13:30:40 UTC+1 vaastav...@gmail.com wrote:
>>
>>> Ok, I just tested this. I only see this behaviour with go 1.18. I tried 
>>> using go mod tidy with go1.17 and it worked as expected.
>>>
>>> On Friday, 1 April 2022 at 14:15:14 UTC+2 vaastav...@gmail.com wrote:
>>>
 I see this behaviour even in the presence of a main.go file in the same 
 directory. This is why I am baffled as to why I am seeing this warning 
 even 
 if the source code is present.
 It was working fine until I upgraded from go1.17 to go1.18

 On Friday, 1 April 2022 at 11:36:04 UTC+2 Brian Candler wrote:

> Interesting.  If I put that go.mod file in an empty directory, then I 
> see the warning:
>
> $ go mod tidy
>
> go: warning: "all" matched no packages
> $ go mod tidy
>
> go: warning: "all" matched no packages
> > But when I run `go mod tidy`, it simply prints out the 
> aforementioned warning and the new go.mod file looks like this
>
> I see the same behaviour if I create a main.go file.  Then the warning 
> vanishes and the go.mod file is tidied:
>
> $ mv main.go.x main.go
> $ cat main.go
> package main
>
> func main() {
> }
> $ go mod tidy
> $ cat go.mod
> module module_name_obfuscated
>
> go 1.17
> $ 
>
> This of course is expected behaviour: it's the job of go mod tidy to 
> update the go.mod file so that it matches the source code in the module. 
> See "go help mod tidy":
>
>
>
>
> *"Tidy makes sure go.mod matches the source code in the module.It adds 
> any missing modules necessary to build the current module'spackages and 
> dependencies, and it removes unused modules thatdon't provide any 
> relevant 
> packages."*
>
> So I presume the warning you see is only when go mod tidy can't find 
> any source code in the current directory.
>
> On Thursday, 31 March 2022 at 20:18:52 UTC+1 vaastav...@gmail.com 
> wrote:
>
>> Here are the contents of the go.mod file
>>
>> ```
>> module module_name_obfuscated
>>
>> go 1.18
>>
>> require (
>> github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b
>> github.com/go-redis/redis/v8 v8.11.4
>> github.com/go-sql-driver/mysql v1.6.0
>> github.com/otiai10/copy v1.7.0
>> github.com/rabbitmq/amqp091-go v1.3.0
>> github.com/tracingplane/tracingplane-go 
>> v0.0.0-20171025152126-8c4e6f79b148
>> gitlab.mpi-sws.org/cld/tracing/tracing-framework-go 
>> v0.0.0-20211206181151-6edc754a9f2a
>> go.mongodb.org/mongo-driver v1.7.4
>> go.opentelemetry.io/otel/exporters/jaeger v1.2.0
>> go.opentelemetry.io/otel/exporters/zipkin v1.6.0
>> go.opentelemetry.io/otel/sdk v1.6.0
>> go.opentelemetry.io/otel/trace v1.6.0
>> golang.org/x/mod v0.5.1
>> )
>>
>> require (
>> github.com/cespare/xxhash/v2 v2.1.2 // indirect
>> github.com/dgryski/go-rendezvous 
>> v0.0.0-20200823014737-9f7001d12a5f // indirect
>> github.com/go-logr/logr v1.2.3 // indirect
>> github.com/go-logr/stdr v1.2.2 // indirect
>> github.com/go-stack/stack v1.8.0 // indirect
>> github.com/golang/protobuf v1.5.2 // indirect
>> github.com/golang/snappy v0.0.4 // indirect
>> github.com/klauspost/compress v1.13.6 // indirect
>> github.com/openzipkin/zipkin-go v0.4.0 // indirect
>> github.com/pkg/errors v0.9.1 // indirect
>> github.com/xdg-go/pbkdf2 v1.0.0 // indirect
>> github.com/xdg-go/scram v1.0.2 // indirect
>> github.com/xdg-go/stringprep v1.0.2 // indirect
>> github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // 
>> indirect
>> go.opentelemetry.io/otel v1.6.0 // indirect
>> golang.org/x/crypto v0.0.0-20210920023735-84f357641f63 // 
>> indirect
>> golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
>> golang.org/x/sys 

[go-nuts] Re: I cannot generate public keys in sequence.

2022-04-06 Thread Brian Candler
If you have a problem using the go-ethereum library then you're probably 
best asking at the tracker or discussion group for that software.

However, the error message seems pretty clear: you're trying to pass a 
value of type []byte to a function which takes a string.  You can convert 
one to the other, but it has to be requested explicitly:
https://go.dev/play/p/67C3mySRegN

Note also that your code posted is badly formatted (it's missing line 
breaks) which means it won't compile.  Using go.dev/play/ to make a 
self-contained program which demonstrates the problem is always a good 
idea, since it can be edited in-situ to fix.

On Wednesday, 6 April 2022 at 19:30:35 UTC+1 sdsa...@gmail.com wrote:

> func Public(PrivateKey string) (publicKey string) { var e 
> ecdsa.PrivateKey e.D, _ = new(big.Int).SetString(PrivateKey, 16) 
> e.PublicKey.Curve = secp256k1.S256() e.PublicKey.X, e.PublicKey.Y = 
> e.PublicKey.Curve.ScalarBaseMult(e.D.Bytes()) return fmt.Sprintf("%x", 
> elliptic.MarshalCompressed(secp256k1.S256(), e.X, e.Y))
>
> _
> i tried this
>
> package main
>   import
> ( "crypto/ecdsa" "crypto/elliptic" "fmt" "math/big" "
> github.com/ethereum/go-ethereum/crypto/secp256k1" )
>   func Public(PrivateKey string) (publicKey string) { var e 
> ecdsa.PrivateKey e.D, _ = new(big.Int).SetString(PrivateKey, 16) 
> e.PublicKey.Curve = secp256k1.S256() e.PublicKey.X, e.PublicKey.Y = 
> e.PublicKey.Curve.ScalarBaseMult(e.D.Bytes()) return fmt.Sprintf("%x", 
> elliptic.MarshalCompressed(secp256k1.S256(), e.X, e.Y)) }
>   func main() { count, one := big.NewInt(1), big.NewInt(1) 
> count.SetString("9404625697166532776746648320380374280100293470930272690489102837043110636674",10)
>  
> PrivateKey := make([]byte, 32)
>   for { count.Add(count, one) copy(PrivateKey[32-len(count.Bytes()):], 
> count.Bytes()) fmt.Printf("%x\n",Public(PrivateKey)) } }   
>
> ___
> output: ./ keysgo.go: 33: 33: unable to use PrivateKey (type [] byte) as 
> type string in argument in Public
>
> ___
>
> I hope for your help. A thousand 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/32248607-da5b-4bda-8b91-379820e4a486n%40googlegroups.com.


[go-nuts] I cannot generate public keys in sequence.

2022-04-06 Thread ass sds
func Public(PrivateKey string) (publicKey string) { var e ecdsa.PrivateKey 
e.D, _ = new(big.Int).SetString(PrivateKey, 16) e.PublicKey.Curve = 
secp256k1.S256() e.PublicKey.X, e.PublicKey.Y = 
e.PublicKey.Curve.ScalarBaseMult(e.D.Bytes()) return fmt.Sprintf("%x", 
elliptic.MarshalCompressed(secp256k1.S256(), e.X, e.Y))
_
i tried this

package main
  import
( "crypto/ecdsa" "crypto/elliptic" "fmt" "math/big" 
"github.com/ethereum/go-ethereum/crypto/secp256k1" )
  func Public(PrivateKey string) (publicKey string) { var e 
ecdsa.PrivateKey e.D, _ = new(big.Int).SetString(PrivateKey, 16) 
e.PublicKey.Curve = secp256k1.S256() e.PublicKey.X, e.PublicKey.Y = 
e.PublicKey.Curve.ScalarBaseMult(e.D.Bytes()) return fmt.Sprintf("%x", 
elliptic.MarshalCompressed(secp256k1.S256(), e.X, e.Y)) }
  func main() { count, one := big.NewInt(1), big.NewInt(1) 
count.SetString("9404625697166532776746648320380374280100293470930272690489102837043110636674",10)
 
PrivateKey := make([]byte, 32)
  for { count.Add(count, one) copy(PrivateKey[32-len(count.Bytes()):], 
count.Bytes()) fmt.Printf("%x\n",Public(PrivateKey)) } }   
___
output: ./ keysgo.go: 33: 33: unable to use PrivateKey (type [] byte) as 
type string in argument in Public
___

I hope for your help. A thousand 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/ed039fa4-4f11-4ac0-af22-30fe6f83bf82n%40googlegroups.com.


[go-nuts] Re: Execution of goroutines

2022-04-06 Thread Brian Candler
> Is there maybe something blocking involved in http.Get()?

Yes of course - first establishing a TCP connection across the network, 
then sending data over it and waiting for the response.

Each of these is a point where the goroutine gets descheduled because it 
has nothing more to do; it's waiting for an external event which may not 
come for several milliseconds (an aeon in computer time).

On Wednesday, 6 April 2022 at 14:43:15 UTC+1 golf_mike wrote:

> Hi,
>
> As a fun way of getting into Go I decided to create a "random" number 
> generator by timing a number of requests to a specific URL, and reducing 
> the results to one number. For practice pusposes I made a  "naive" version 
> with just a for loop and a version that uses goroutines.
> As I am interested in the timings for each individual request, there was 
> an interesting result. Implemented in the for loop, each request was timed 
> as expected. For the goroutines however the timings incremented for each 
> individual timing, where the last timing was equal or a microsecond or so 
> below the total timing for all requests.
> Upon further inspection, it seems that the time.Now() for the startTime is 
> called almost immediately for all, but the time.Now() for the stopSub is 
> called much later.
> How is it possible that all goroutines start execution at the same time, 
> but finish not at the same time? Is there maybe something blocking involved 
> in http.Get()?
> I posted all code for this on Stackoverflow a couple of days ago but no 
> answers there yet (go - Unexpected behaviour of time.Now() in goroutine - 
> Stack Overflow 
> ).
>  
> See below for the goroutine and how it is called.
>
> Execution of goroutines:
> *start := time.Now()*
> *ch := make(chan int64, 100)*
> *url := "https://www.nu.nl "*
> *for i := 0; i < len(timings_parallel); i++ {*
> *wg.Add(1)*
> *go func() {*
> *defer wg.Done()*
> *doGet(url, ch)*
> *}()*
> *}*
> *wg.Wait()*
> *close(ch)*
> *// feed the results from the channel into the result array*
> *count := 0*
> *for ret := range ch {*
> *timings_parallel[count] = ret*
> *count++*
> *}*
> *// get total running time for this part*
> *time_parallel := time.Since(start).Milliseconds()*
> Goroutine:
> *func doGet(address string, channel chan int64) {*
> *startTime := time.Now()*
> *startSub := startTime.UnixMilli()*
>
> *_, err := http.Get(address)*
> *if err != nil {*
> *log.Fatalln(err)*
> *}*
> *stopSub := time.Now().UnixMilli()*
> *delta := stopSub - startSub*
>
> *channel <- delta*
> *}*
>
>
>

-- 
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/e9a22dae-054a-45e5-b09a-093f56073c1bn%40googlegroups.com.


Re:[go-nuts] Re: How go.work knows which module refers to which folder

2022-04-06 Thread 'Jack Li' via golang-nuts
Thanks.


I think I may get it.


If there's go.work, the `import example.com/module` will try those local 
directories in go.work first. If not found, it will try online repositories. 
And module names like this `example.com/module`, `github.com/golang/glog`, etc. 
are unique, so there will be no ambiguous. Am I thinking right?





--Original--
From:   
 "thepud...@gmail.com"  
  
From the Go workspaces reference (https://go.dev/ref/mod#workspaces) :

 A 'use' adds a module on disk to the set of main modules in a workspace. 
Its argument is a relative path to the directory containing the module’s go.mod 
file. A 'use' directive does not add modules contained in subdirectories of its 
argument directory. Those modules may be added by the directory containing 
their go.mod file in separate 'use' directives.

Hope that helps, and sorry if that does not address your question.

Regards,
thepudds


On Wednesday, April 6, 2022 at 9:43:12 AM UTC-4 Jack Li wrote:

Hi group,


In the go.mod replace way, there’s a one-to-one mapping relationship, for 
example, the module example.com/hello is mapped to folder …/hello


```
$ go mod edit -replace example.com/hello=../hello
$ view go.mod
replace example.com/hello = ../hello
$
```


Now with the go.work way. If I've got three repos or modules like this:


```
module main
go 1.18
require example1.com/hello v1.0.0
require example2.com/hello v1.0.0
require example3.com/hello v1.0.0
```


How can go.work know which module above, refers to ./hello ?


```
go.work:
use ./hello
```


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.
 To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7c90c2a4-7a81-4e16-b1fe-8ddd19b72f12n%40googlegroups.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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/tencent_92E509C4160EBDE79705E7628818074DAA0A%40qq.com.


[go-nuts] Re: How go.work knows which module refers to which folder

2022-04-06 Thread thepud...@gmail.com
Hi there,

I might be misunderstanding your question, but a 'use' directive in a 
go.work file points to a directory. 

In your example, there would not be any ambiguity -- 'use ./hello' in a 
go.work file would refer to whatever module you have located in the 'hello' 
directory in your local filesystem immediately below the go.work file.

>From the Go workspaces reference (https://go.dev/ref/mod#workspaces) :

> A 'use' adds a module on disk to the set of main modules in a workspace. 
Its argument is a relative path to the directory containing the module’s 
go.mod file. A 'use' directive does not add modules contained in 
subdirectories of its argument directory. Those modules may be added by the 
directory containing their go.mod file in separate 'use' directives.

Hope that helps, and sorry if that does not address your question.

Regards,
thepudds

On Wednesday, April 6, 2022 at 9:43:12 AM UTC-4 Jack Li wrote:

> Hi group,
>
> In the go.mod replace way, there’s a one-to-one mapping relationship, for 
> example, the module example.com/hello is mapped to folder …/hello
>
> ```
> $ go mod edit -replace example.com/hello=../hello
> $ view go.mod
> replace example.com/hello => ../hello 
> $
> ```
>
> Now with the go.work way. If I've got three repos or modules like this:
>
> ```
> module main
> go 1.18
> require example1.com/hello v1.0.0
> require example2.com/hello v1.0.0
> require example3.com/hello v1.0.0
> ```
>
> How can go.work know which module above, refers to ./hello ?
>
> ```
> go.work:
> use ./hello
> ```
>
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7c90c2a4-7a81-4e16-b1fe-8ddd19b72f12n%40googlegroups.com.


Re: [go-nuts] Handle 1 million concurrent connections with 50 lines Go code

2022-04-06 Thread Robert Engels
Yes. Go uses “green threads” with its own scheduler and uses facilities like 
epoll under the covers. 

> On Apr 6, 2022, at 8:43 AM, 'Jack Li' via golang-nuts 
>  wrote:
> 
> 
> Hi group,
> 
> I am going through this page: https://studygolang.com/articles/22820 , It 
> claims that the 50 lines of Go code handles 1 million concurrent connections 
> from network clients, on 1 single server machine with a 4-Core CPU and 16G 
> memory.
> 
> Does the package net already utilize IO Multiplexing internally, like epoll 
> (epoll_create, epoll_ctl, epoll_wait)? So I can just use package net and gain 
> the epoll ability automatically without calling epoll apis manually in Go?
> 
> Thanks
> 
> Server:
> ```
> package main
> 
> import (
> "fmt"
> "net"
> "os"
> "time"
> )
> 
> var array []byte = make([]byte, 10)
> 
> func checkError(err error, info string) (res bool) {
> 
> if err != nil {
> fmt.Println(info + "  " + err.Error())
> return false
> }
> return true
> }
> 
> func Handler(conn net.Conn) {
> for {
> _, err := conn.Write(array)
> if err != nil {
> return
> }
> time.Sleep(10 * time.Second)
> }
> }
> 
> func main() {
> 
> for i := 0; i < 10; i += 1 {
> array[i] = 'a'
> }
> 
> service := ":"
> tcpAddr, _ := net.ResolveTCPAddr("tcp4", service)
> l, _ := net.ListenTCP("tcp", tcpAddr)
> 
> for {
> conn, err := l.Accept()
> if err != nil {
> fmt.Printf("accept error, err=%s\n", err.Error())
> os.Exit(1)
> }
> go Handler(conn)
> }
> 
> }
> ```
> 
> Client:
> 
> ```
> package main
> 
> import (
> "flag"
> "fmt"
> "net"
> "os"
> "time"
> )
> 
> var RemoteAddr *string
> var ConcurNum *int
> var LocalAddr *string
> 
> func init() {
> RemoteAddr = flag.String("remote-ip", "127.0.0.1", "ip addr of remote 
> server")
> ConcurNum = flag.Int("concurrent-num", 100, "concurrent number of client")
> LocalAddr = flag.String("local-ip", "0.0.0.0", "ip addr of remote server")
> }
> 
> func consume() {
> 
> laddr := {IP: net.ParseIP(*LocalAddr)}
> 
> var dialer net.Dialer
> dialer.LocalAddr = laddr
> 
> conn, err := dialer.Dial("tcp", *RemoteAddr+":")
> if err != nil {
> fmt.Println("dial failed:", err)
> os.Exit(1)
> }
> defer conn.Close()
> 
> buffer := make([]byte, 512)
> 
> for {
> _, err2 := conn.Read(buffer)
> if err2 != nil {
> fmt.Println("Read failed:", err2)
> return
> }
> 
> //  fmt.Println("count:", n, "msg:", string(buffer))
> 
> }
> 
> }
> 
> func main() {
> flag.Parse()
> for i := 0; i < *ConcurNum; i++ {
> go consume()
> }
> time.Sleep(3600 * time.Second)
> }
> ```
> -- 
> 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/tencent_BEE3D2499F3C9358D7A1CD7C88E0228C6D07%40qq.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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/DF3ECA69-BFD3-48B8-8EF1-CF8E538EEA20%40ix.netcom.com.


[go-nuts] Re: Handle 1 million concurrent connections with 50 lines Go code

2022-04-06 Thread Amnon
Yes, the Go runtime does use epoll internally and schedules gorountines 
when their data is available. 
See 
https://github.com/golang/go/blob/17b2fb1b656a275906b5071c562439d50a27f167/src/runtime/netpoll_epoll.go
It does scale nicely and can handle tens of thousands or even hundreds of 
thousands of concurrent connections, without the "Thundering 
Herd" type behaviour which one would expect from such systems.
I have not tried it with millions of connection, but if you are interested, 
then run a test, but the consume side of your test will run out of ports.

On Wednesday, 6 April 2022 at 14:43:16 UTC+1 Jack Li wrote:

> Hi group,
>
> I am going through this page: https://studygolang.com/articles/22820 , It 
> claims that the 50 lines of Go code handles 1 million concurrent 
> connections from network clients, on 1 single server machine with a 4-Core 
> CPU and 16G memory.
>
> Does the package net already utilize IO Multiplexing internally, like 
> epoll (epoll_create, epoll_ctl, epoll_wait)? So I can just use package net 
> and gain the epoll ability automatically without calling epoll apis 
> manually in Go?
>
> Thanks
>
> Server:
> ```
> package main
>
> import (
> "fmt"
> "net"
> "os"
> "time"
> )
>
> var array []byte = make([]byte, 10)
>
> func checkError(err error, info string) (res bool) {
>
> if err != nil {
> fmt.Println(info + "  " + err.Error())
> return false
> }
> return true
> }
>
> func Handler(conn net.Conn) {
> for {
> _, err := conn.Write(array)
> if err != nil {
> return
> }
> time.Sleep(10 * time.Second)
> }
> }
>
> func main() {
>
> for i := 0; i < 10; i += 1 {
> array[i] = 'a'
> }
>
> service := ":"
> tcpAddr, _ := net.ResolveTCPAddr("tcp4", service)
> l, _ := net.ListenTCP("tcp", tcpAddr)
>
> for {
> conn, err := l.Accept()
> if err != nil {
> fmt.Printf("accept error, err=%s\n", err.Error())
> os.Exit(1)
> }
> go Handler(conn)
> }
>
> }
> ```
>
> Client:
>
> ```
> package main
>
> import (
> "flag"
> "fmt"
> "net"
> "os"
> "time"
> )
>
> var RemoteAddr *string
> var ConcurNum *int
> var LocalAddr *string
>
> func init() {
> RemoteAddr = flag.String("remote-ip", "127.0.0.1", "ip addr of remote 
> server")
> ConcurNum = flag.Int("concurrent-num", 100, "concurrent number of 
> client")
> LocalAddr = flag.String("local-ip", "0.0.0.0", "ip addr of remote 
> server")
> }
>
> func consume() {
>
> laddr := {IP: net.ParseIP(*LocalAddr)}
>
> var dialer net.Dialer
> dialer.LocalAddr = laddr
>
> conn, err := dialer.Dial("tcp", *RemoteAddr+":")
> if err != nil {
> fmt.Println("dial failed:", err)
> os.Exit(1)
> }
> defer conn.Close()
>
> buffer := make([]byte, 512)
>
> for {
> _, err2 := conn.Read(buffer)
> if err2 != nil {
> fmt.Println("Read failed:", err2)
> return
> }
>
> //  fmt.Println("count:", n, "msg:", string(buffer))
>
> }
>
> }
>
> func main() {
> flag.Parse()
> for i := 0; i < *ConcurNum; i++ {
> go consume()
> }
> time.Sleep(3600 * time.Second)
> }
> ```
>

-- 
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/e139c771-4b11-49c6-9045-ed65c861ded2n%40googlegroups.com.


Re: [go-nuts] Handle 1 million concurrent connections with 50 lines Go code

2022-04-06 Thread Ian Lance Taylor
On Wed, Apr 6, 2022 at 6:43 AM 'Jack Li' via golang-nuts
 wrote:
>
> I am going through this page: https://studygolang.com/articles/22820 , It 
> claims that the 50 lines of Go code handles 1 million concurrent connections 
> from network clients, on 1 single server machine with a 4-Core CPU and 16G 
> memory.
>
> Does the package net already utilize IO Multiplexing internally, like epoll 
> (epoll_create, epoll_ctl, epoll_wait)? So I can just use package net and gain 
> the epoll ability automatically without calling epoll apis manually in Go?

I didn't read your program, but, yes, the net package uses epoll
internally.  There is no need to call epoll yourself.

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWpReVnWqxCkoHBcw%3DvYQsiTuSQZZPV9p-Tz7KQCG5adg%40mail.gmail.com.


[go-nuts] How go.work knows which module refers to which folder

2022-04-06 Thread 'Jack Li' via golang-nuts
Hi group,


In the go.mod replace way, there’s a one-to-one mapping relationship, for 
example, the module example.com/hello is mapped to folder …/hello


```
$ go mod edit -replace example.com/hello=../hello
$ view go.mod
replace example.com/hello = ../hello
$
```


Now with the go.work way. If I've got three repos or modules like this:


```
module main
go 1.18
require example1.com/hello v1.0.0
require example2.com/hello v1.0.0
require example3.com/hello v1.0.0
```


How can go.work know which module above, refers to ./hello ?


```
go.work:
use ./hello
```


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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/tencent_FFE3265FF272623D8732F23F839930C48D09%40qq.com.


[go-nuts] Execution of goroutines

2022-04-06 Thread Guido Millenaar
Hi,

As a fun way of getting into Go I decided to create a "random" number 
generator by timing a number of requests to a specific URL, and reducing 
the results to one number. For practice pusposes I made a  "naive" version 
with just a for loop and a version that uses goroutines.
As I am interested in the timings for each individual request, there was an 
interesting result. Implemented in the for loop, each request was timed as 
expected. For the goroutines however the timings incremented for each 
individual timing, where the last timing was equal or a microsecond or so 
below the total timing for all requests.
Upon further inspection, it seems that the time.Now() for the startTime is 
called almost immediately for all, but the time.Now() for the stopSub is 
called much later.
How is it possible that all goroutines start execution at the same time, 
but finish not at the same time? Is there maybe something blocking involved 
in http.Get()?
I posted all code for this on Stackoverflow a couple of days ago but no 
answers there yet (go - Unexpected behaviour of time.Now() in goroutine - 
Stack Overflow 
).
 
See below for the goroutine and how it is called.

Execution of goroutines:
*start := time.Now()*
*ch := make(chan int64, 100)*
*url := "https://www.nu.nl"*
*for i := 0; i < len(timings_parallel); i++ {*
*wg.Add(1)*
*go func() {*
*defer wg.Done()*
*doGet(url, ch)*
*}()*
*}*
*wg.Wait()*
*close(ch)*
*// feed the results from the channel into the result array*
*count := 0*
*for ret := range ch {*
*timings_parallel[count] = ret*
*count++*
*}*
*// get total running time for this part*
*time_parallel := time.Since(start).Milliseconds()*
Goroutine:
*func doGet(address string, channel chan int64) {*
*startTime := time.Now()*
*startSub := startTime.UnixMilli()*

*_, err := http.Get(address)*
*if err != nil {*
*log.Fatalln(err)*
*}*
*stopSub := time.Now().UnixMilli()*
*delta := stopSub - startSub*

*channel <- delta*
*}*


-- 
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/9a4896fd-5e92-4462-9e6a-7363aa19a483n%40googlegroups.com.


[go-nuts] Handle 1 million concurrent connections with 50 lines Go code

2022-04-06 Thread 'Jack Li' via golang-nuts
Hi group,


I am going through this page: https://studygolang.com/articles/22820 , It 
claims that the 50 lines of Go code handles 1 million concurrent connections 
from network clients, on 1 single server machine with a 4-Core CPU and 16G 
memory.


Does the package net already utilize IO Multiplexing internally, like epoll 
(epoll_create, epoll_ctl, epoll_wait)? So I can just use package net and gain 
the epoll ability automatically without calling epoll apis manually in Go?


Thanks


Server:
```
package main


import (
  "fmt"
  "net"
  "os"
  "time"
)


var array []byte = make([]byte, 10)


func checkError(err error, info string) (res bool) {


  if err != nil {
fmt.Println(info + " " + err.Error())
return false
  }
  return true
}


func Handler(conn net.Conn) {
  for {
_, err := conn.Write(array)
if err != nil {
  return
}
time.Sleep(10 * time.Second)
  }
}


func main() {


  for i := 0; i < 10; i += 1 {
array[i] = 'a'
  }


  service := ":"
  tcpAddr, _ := net.ResolveTCPAddr("tcp4", service)
  l, _ := net.ListenTCP("tcp", tcpAddr)


  for {
conn, err := l.Accept()
if err != nil {
  fmt.Printf("accept error, err=%s\n", 
err.Error())
  os.Exit(1)
}
go Handler(conn)
  }


}
```


Client:


```
package main


import (
  "flag"
  "fmt"
  "net"
  "os"
  "time"
)


var RemoteAddr *string
var ConcurNum *int
var LocalAddr *string


func init() {
  RemoteAddr = flag.String("remote-ip", "127.0.0.1", "ip addr of 
remote server")
  ConcurNum = flag.Int("concurrent-num", 100, "concurrent number of 
client")
  LocalAddr = flag.String("local-ip", "0.0.0.0", "ip addr of remote 
server")
}


func consume() {


  laddr := net.TCPAddr{IP: net.ParseIP(*LocalAddr)}


  var dialer net.Dialer
  dialer.LocalAddr = laddr


  conn, err := dialer.Dial("tcp", *RemoteAddr+":")
  if err != nil {
fmt.Println("dial failed:", err)
os.Exit(1)
  }
  defer conn.Close()


  buffer := make([]byte, 512)


  for {
_, err2 := conn.Read(buffer)
if err2 != nil {
  fmt.Println("Read failed:", err2)
  return
}


// fmt.Println("count:", n, "msg:", 
string(buffer))


  }


}


func main() {
  flag.Parse()
  for i := 0; i < *ConcurNum; i++ {
go consume()
  }
  time.Sleep(3600 * time.Second)
}
```

-- 
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/tencent_BEE3D2499F3C9358D7A1CD7C88E0228C6D07%40qq.com.


Re: [go-nuts] Why is it forbidden to add methods to an existing type?

2022-04-06 Thread Brian Candler
I agree, and there's a clear benefit that it's harder to dereference a nil 
interface than a nil pointer, when that interface has no methods.  The 
problem is that statically it doesn't tell you anything about the possible 
contained type.

In comparison, a pointer tells you exactly the type contained, but it must 
be exactly one type, and there's always a risk of accidentally deferencing 
a nil pointer. 

If one day, generics type-constraint interfaces could be used as regular 
interface types, that would be powerful: you could have a variable of type 
"interface { float64 | Status }" and know for sure that the value *must* be 
either nil, float64 or Status. Furthermore, you wouldn't be able to use the 
contained value without an explicit type assertion.

On Wednesday, 6 April 2022 at 01:10:23 UTC+1 sam.a@gmail.com wrote:

> I get what you're saying, and for what it's worth, you're absolutely 
> correct. Something like above is a set of tradeoffs, and I guess all I can 
> assert is that it works for me. I do think it's a good design, given Go's 
> lack of a None type to enforce well-defined behavior on a nil pointer 
> dereference, but it's an example of a well-designed API from the days 
> before generics, which safely respects nil/null values in the appropriate 
> context.
>
> For most of my use of the model, the types offered by the pgtype pacakge 
> are A. total overkill, and B. just an intermediate type to hold a value 
> between two boundaries that do understand null values, such as bridging an 
> RPC frontend and a SQL backend.
>
> If anything, it proves that Generics do simplify codebases, and that 
> well-defined, graceful null/nil handling is worth the effort.
> On Tuesday, April 5, 2022 at 5:13:04 AM UTC-5 Brian Candler wrote:
>
>> I did look at the code briefly.  The main thing I noticed was that the 
>> return type of float8.Get() was an interface{} - so it's up to the caller 
>> to check at runtime whether the value is nil, a float64, or a Status.
>>
>> So you're right, it's not that they are compile-time unsafe, but rather 
>> that you have to write type matching code at each use site. Within a given 
>> switch branch, it's safe.
>>
>> On Tuesday, 5 April 2022 at 07:29:09 UTC+1 sam.a@gmail.com wrote:
>>
>>> Uh, you should check the code: 
>>> github.com/jackc/pgtype/blob/master/float8.go If you know what you have 
>>> and what you're dealing with, and if you actually check the error result, 
>>> you do get safety. If you don't know what you've got, or if you're 
>>> iterating through the values, then you end up hitting the sad, sad, 
>>> reflective path...for now.
>>> On Saturday, April 2, 2022 at 4:37:36 AM UTC-5 Brian Candler wrote:
>>>
 Correct repository path is: https://github.com/jackc/pgtype

 Interesting.  These structs generally contain a Status value as well:

 type Int8 struct {
Int int64
Status Status
 }

 where pgtype.go has:

 type Status byte

 const (
Undefined Status = iota
Null
Present
 )

 They also have Set() and Get() methods, although these are not 
 compiled-time type safe as they accept and return interface{}

 On Friday, 1 April 2022 at 17:40:42 UTC+1 sam.a@gmail.com wrote:

>
> Thanks for clarifying that, @Brian. Yeah. It took a bit to warm up to 
> that approach, but the github.com/jackc/pgtypes convinced me that the 
> results were worth it. The benefits:  A, package interpretation methods 
> with a piece of data, B, lazily valuate data when needed, and C, gain 
> introspective capability specific to the type and not using reflect
> On Friday, April 1, 2022 at 4:47:32 AM UTC-5 Brian Candler wrote:
>
>> That wasn't literal code with anglebrackets - you're supposed to fill 
>> that in yourself.  I think he meant something like:
>>
>> type fooString struct{ string }
>>
>> https://go.dev/play/p/4Q94xMZDciV
>>
>> What this is doing is *embedding* a string value into a struct; if 
>> you have not come across type embedding before then Google for the 
>> details.
>>
>> You still cannot use one of these types transparently as a string, 
>> but you can use
>> x.string
>> instead of
>> string(x)
>> to extract the value.
>>
>> On Friday, 1 April 2022 at 06:48:04 UTC+1 yan.z...@gmail.com wrote:
>>
>>> Hi Sam! Your solution does not seem to work:
>>>
>>> package main
>>>
>>> import(
>>> "fmt"
>>> "strconv"
>>> )
>>>
>>> type  String struct{string}
>>>
>>> func (s String) print(){
>>> fmt.Println(s)
>>> }
>>>
>>> func main() {
>>>var a String ="hello, world\n"
>>>
>>>a.print()
>>>
>>>fmt.Println(strconv.ParseInt("78",10, 64))
>>>
>>>var x String ="452"
>>>
>>>n, _ := strconv.ParseInt(x, 10,