[go-nuts] Re: accessibility of module version information in executable

2020-06-26 Thread seank...@gmail.com
go version -m $binary

runtime/debug.BuildInfo

On Friday, June 26, 2020 at 6:13:56 PM UTC+2 Marvin Renich wrote:

> When building a command with go build that imports modules, does the
> resulting executable contain information about which modules are
> included as well as their versions?
>
> If so, is there a tool available to extract that information from the
> executable? Can the information be retrieved from within the program
> (e.g. through the runtime package)?
>
> If not, would a request for this be received favorably?
>
> ...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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/a2816324-6b9d-4e98-b2da-7c31c8de2d05n%40googlegroups.com.


[go-nuts] Re: Building multiple executables from one module

2020-06-30 Thread seank...@gmail.com
go build -o output_directory ./...

On Tuesday, June 30, 2020 at 12:58:05 PM UTC+2 b.ca...@pobox.com wrote:

> Suppose I have a tree of files like this, to build two executables:
>
> ==> ./go.mod <==
> module example.com/test
>
> go 1.14
>
> ==> ./shared.go <==
> package example
>
> const Answer = 42
>
> ==> ./bin/test1/main1.go <==
> package main
>
> import (
> . "example.com/test"
> "fmt"
> )
>
> func main() {
> fmt.Printf("%s, answer is %d\n", Message, Answer)
> }
>
> ==> ./bin/test1/dep1.go <==
> package main
>
> const Message = "hello"
>
> ==> ./bin/test2/main2.go <==
> package main
>
> import (
> . "example.com/test"
> "fmt"
> )
>
> func main() {
> fmt.Printf("%s, answer was %d\n", Message, Answer)
> }
>
> ==> ./bin/test2/dep2.go <==
> package main
>
> const Message = "goodbye"
>
> Ideally I'd like a way to build the executables in a single command.  
> Currently I enter each directory and build explicitly, i.e.
>
> for d in bin/*; do (cd $d && go build); done
>
> If at the top level I do "go build ./...", the executables don't get 
> built.  Something happens, because it takes a fraction of a second to 
> return, but nothing is written out as far as I can see.
>
> The documentation  says:
>
> -buildmode=default
>   Listed main packages are built into executables and listed
>   non-main packages are built into .a files (the default
>   behavior).
>
>
> This implies multiple "main packages" can be built into multiple 
> "executables" in one command.
>
> But how is a main package "listed"?  I tried:
>
> $ go build bin/test1
> can't load package: package bin/test1 is not in GOROOT 
> (/usr/local/go/src/bin/test1)
> $ go build bin/test1/main
> can't load package: package bin/test1/main is not in GOROOT 
> (/usr/local/go/src/bin/test1/main)
> $ go build bin/test1/...
> go: warning: "bin/test1/..." matched no packages
> go: warning: "bin/test1/..." matched no packages
> $ go build bin/test1/main1.go
> # command-line-arguments
> bin/test1/main1.go:9:35: undefined: Message
>
> The following is accepted, but as far as I can see does not create any 
> files:
>
> $ go build example.com/test/bin/test1 example.com/test/bin/test2
> $ 
>
> Just like "go build ./...", it takes a noticeable fraction of a second, 
> but nothing is written out.  I've look in the top level, inside the 
> bin/test[12] directories, and  "find ~/go -mtime -1"
>
> If I build one at a time, it works, yay!
>
> $ go build example.com/test/bin/test1
> $ go build example.com/test/bin/test2
> $ ls
> bin  go.mod  shared.go test1  test2
>
> ... but the documentation says I ought to be able to list multiple main 
> packages, so I'm clearly missing something.
>
> It seems when I build a single package, it gets moved to the final 
> location:
>
> $ go build -x example.com/test/bin/test1
> ...
> /usr/local/go/pkg/tool/linux_amd64/buildid -w $WORK/b001/exe/a.out # 
> internal
> mv $WORK/b001/exe/a.out test1
> rm -r $WORK/b001/
> $ 
>
> but not when I build two:
>
> $ go build -x example.com/test/bin/test1 example.com/test/bin/test2
> ...
> /usr/local/go/pkg/tool/linux_amd64/buildid -w $WORK/b033/exe/a.out # 
> internal
> /usr/local/go/pkg/tool/linux_amd64/buildid -w $WORK/b001/exe/a.out # 
> internal
> $ 
>
> That's as far as I've got.  (Incidentally, I see the same with "go build 
> -x ./...")
>
> Any clues?
>
> Thanks,
>
> Brian.
>
> P.S.
> $ go version
> go version go1.14.4 linux/amd64
>
>

-- 
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/e0ca3474-2f02-4e8d-bc36-b5af043b7139n%40googlegroups.com.


[go-nuts] Re: clean unused packages in $GOPATH/pkg/mod

2020-07-07 Thread seank...@gmail.com
go clean -modcache

On Tuesday, July 7, 2020 at 9:23:50 AM UTC+2 HailangGe wrote:

>
> Thanks. I'm just trying to look for if there are any way to clean them in 
> a programmer's way.
> 在2020年7月7日星期二 UTC+8 下午1:26:16 写道:
>
>> Just delete them all.
>> Your next build will repopulate the ones that are needed.
>>
>

-- 
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/a5760d15-84b3-48bc-88d3-910be435687en%40googlegroups.com.


Re: [go-nuts] var fn myHandler = func(){ fn }

2020-07-12 Thread seank...@gmail.com
https://github.com/golang/go/issues/33167

On Sunday, July 12, 2020 at 10:44:02 PM UTC+2 axel.wa...@googlemail.com 
wrote:

> On Sun, Jul 12, 2020 at 9:33 PM Bakul Shah  wrote:
>
>> On Jul 12, 2020, at 11:11 AM, Gert  wrote:
>> > 
>> > https://play.golang.org/p/6xMgjr1IyFD
>> > 
>> > var fn myHandler
>> > fn = func(w http.ResponseWriter, r *http.Request) {
>> >   fn.GET(w, r)
>> > }
>> > 
>> > Just wondering if it's possible somehow to write this in one line like 
>> so
>> > 
>> > var fn myHandler = func(w http.ResponseWriter, r *http.Request) {
>> >   fn.GET(w, r)
>> > }
>>
>> The issue is that fn's type can't be completely determined until
>> the RHS func is fully analyzed but for that to work fn must be
>> known!
>
>
> Why? ISTM the type is mentioned twice - once as "myHandler" on the LHS and 
> once in the signature on the RHS. And there isn't even a way to write down 
> a function literal without mentioning the full type. On the surface, this 
> seems like a relatively straightforward scoping issue, introduced by the 
> fact that the scope of a variable declaration starts at the end of it's 
> VarSpec, not the "=". Interestingly though, the initialization rules 
> prevent this from working at the package-level, where this scoping problem 
> doesn't exist: https://play.golang.org/p/IPMxtYETGsg
>
> Also note that the first definition won't do what you may be thinking
>> it does. The`fn.GET` call will be to the existing value of fn, not
>> the result of the assignment.
>>
>
> No, it won't. The function-literal closes over `fn`, so it will use 
> whatever is assigned at call-time.
> https://play.golang.org/p/VCvCt8J8Zcw
> I use this pattern all the time to define a recursive function without 
> polluting the package-scope.
>
>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/716C7D59-9F2B-4AAD-8560-79011359A96C%40iitbombay.org
>> .
>>
>

-- 
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/acbc2cad-163d-461a-a546-5a8248d0c392n%40googlegroups.com.


[go-nuts] Re: best way to know executable version without running it

2020-08-13 Thread seank...@gmail.com
go version -m 

On Thursday, August 13, 2020 at 10:30:56 AM UTC+2 santhoshth...@gmail.com 
wrote:

> Hi All,
>
> What is best way to know a executable version without executing it through 
> golang?
>
> I tried with reading the executable file through a scanner and matching 
> every line with regex (like ngnix regx) but this is not working for all 
> executables.
>
> Do you have any idea?
>

-- 
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/a0d50b2d-beb7-42b0-9506-acc7f4b22a42n%40googlegroups.com.


[go-nuts] Re: The latest version of package in pkg.go.dev

2020-08-15 Thread seank...@gmail.com
that's an invalid semver, no leading 0s  allowed

https://semver.org/#spec-item-2 :
A normal version number MUST take the form X.Y.Z where X, Y, and Z are 
non-negative integers, and MUST NOT contain leading zeroes. X is the major 
version, Y is the minor version, and Z is the patch version. Each element 
MUST increase numerically. For instance: 1.9.0 -> 1.10.0 -> 1.11.0.

On Saturday, August 15, 2020 at 4:08:06 AM UTC+2 sunto...@gmail.com wrote:

> How to force update the latest version of package in pkg.go.dev?
>
> My https://github.com/go-easygen/easygen/releases/tag/v5.1.01 has been 
> release for over 10 days, but the 
> https://pkg.go.dev/github.com/go-easygen/easygen?tab=versions is still 
> showing an old version. 
>
> From https://proxy.golang.org/ I saw
>
> explicitly request that version via go get module@version. After one 
>> minute for caches to expire, the go command will see that tagged version. 
>> If this doesn't work for you, please file an issue 
>> .
>
>
>
> So I did:
>
>
> go get github.com/go-easygen/eas...@v5.1.01 
> 
>
> go: downloading github.com/go-easygen/easygen 
> v4.0.1-0.20200804033944-7bacacfacf6a+incompatible
> go: github.com/go-easygen/easygen v5.1.01 => 
> v4.0.1-0.20200804033944-7bacacfacf6a+incompatible
> go: finding module for package gopkg.in/yaml.v2
> . . . 
>
> $ date
> Fri Aug 14 21:56:06 EDT 2020
>
> $ lynx -dump -width=78 "
> https://pkg.go.dev/github.com/go-easygen/easygen?tab=versions";; date
> . . . 
> v1 - github.com/go-easygen/easygen
>
>  * [32]v4.1.0+incompatible - Jun 19, 2019
>  * [33]v4.0.0+incompatible - Mar 24, 2019
>  * [34]v3.0.0+incompatible - May 4, 2018
> . . . 
> Fri Aug 14 22:06:18 EDT 2020
>
>
> So do I need to file an issue 
> , or I've missed 
> something? 
>
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/074b1e7d-7b1c-43c0-abc6-d20eb2625c7dn%40googlegroups.com.


[go-nuts] Re: Generating code into module cache?

2020-10-20 Thread seank...@gmail.com
That doesn't really make sense? 
The module cache is for immutable versions of modules,
ie. publish your (generated) code as a package/module, import that
it will then get cached

On Tuesday, October 20, 2020 at 8:50:25 PM UTC+2 mattm...@gmail.com wrote:

> Hey folks, 
>
> I'm working on a project with a lot of code generation. I'd love to:
>
> - get the code generation out of the way when you don't care about it
> - be able to vendor the generated code when you do care about it
>
> That led me to an idea about generating code into the go module cache. Do 
> you see any downside in doing this? 
>
> 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/69e3f7d7-fede-4d78-b6b1-e745a4466e79n%40googlegroups.com.


Re: [go-nuts] Table driven tests and error/output testing

2020-10-20 Thread seank...@gmail.com
you should be able to unconditionally compare the output without doing the 
length check

On Tuesday, October 20, 2020 at 8:51:56 AM UTC+2 amits...@gmail.com wrote:

>
> On 20 Oct 2020, at 4:13 pm, Tamás Gulácsi  wrote:
>
> Use bytes.Buffer or strings.Builder directly - no need for the 
> bufio.Writer.
> bufio.Writer only speeds up writing by calling the underlying Writer less, 
> with bigger slices.
> Here you Write into a memory, just as bufio.Writer.
>
> Also, you can save some allocations by creating the buffer once outside of 
> the loop,
> and Reset() it in each cycle before calling handleCommand.
>
>
> Thank you, appreciate the suggestions.
>
>
>
> amits...@gmail.com a következőt írta (2020. október 20., kedd, 6:03:31 
> UTC+2):
>
>> Hi all, Consider the following test configuration: 
>>
>>
>> func TestHandleCommand(t *testing.T) { 
>>
>> type expectedResult struct { 
>> output string 
>> err error 
>> } 
>> type testConfig struct { 
>> args []string 
>> result expectedResult 
>> } 
>>
>> testConfigs := []testConfig{ 
>> testConfig{ 
>> args: []string{"-h"}, 
>> result: expectedResult{ 
>> err: nil, 
>> output: `Expected output`, 
>> }, 
>> }, 
>> } 
>>
>> Then, I do this: 
>>
>>
>> for _, tc := range testConfigs { 
>> byteBuf := new(bytes.Buffer) 
>> w := bufio.NewWriter(byteBuf) 
>>
>> err := handleCommand(w, tc.args) 
>> if tc.result.err == nil && err != nil { 
>> t.Errorf("Expected nil error, got %v", err) 
>> } 
>>
>> if tc.result.err != nil && err.Error() != tc.result.err.Error() { 
>> t.Errorf("Expected error %v, got %v", tc.result.err, err) 
>> } 
>>
>> if len(tc.result.output) != 0 { 
>> w.Flush() 
>> gotOutput := byteBuf.String() 
>> if tc.result.output != gotOutput { 
>> t.Errorf("Expected output to be: %v, Got: %v", 
>> tc.result.output, gotOutput) 
>> } 
>> } 
>> } 
>> } 
>>
>> The above pattern works for me since the function may return an error 
>> and/or it may have something it writes to the provided writer, w. 
>>
>> Is there a more concise way to write this? 
>>
>>
>>
>> Thanks, 
>> Amit. 
>>
>
> -- 
> 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.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/2759fea4-a3d6-42ee-b3e4-2c0ac208f2b9n%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/a7383aa7-8d16-4697-89bf-7f9d57752f08n%40googlegroups.com.


Re: [go-nuts] Running "go test" modifies go.mod & go.sum

2020-11-01 Thread seank...@gmail.com
you're using the analysis packages which have dependencies on calling the 
go cmd internally
you could try passing readonly via GOFLAGS

the fact that your go.mod/go.sum changed means you should reevaluate what 
you're doing,
specifically you have an unversioned/untracked dependency on gorilla/mux 
via your testdata

as an aside, go1.16 readonly by default works (tested with tip)

On Sunday, November 1, 2020 at 6:26:17 PM UTC+1 ma...@eliasnaur.com wrote:

> On Sunday, 1 November 2020 at 13:52:34 UTC+1 miki@gmail.com wrote:
>
>> I try to change the "go run" command to use "-mod=readonly", didn't help.
>>
>  
> Drive-by comment in case you weren't aware: Go 1.16 is switching to 
> -mod=readonly
> by default. The proposal and links to the implementation are in
> https://github.com/golang/go/issues/40728.
>
> Hope it helps,
> Elias
>  
>

-- 
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/0eee972d-0ab7-4495-89eb-f4524da352bcn%40googlegroups.com.


[go-nuts] Re: Go modules replace statements referencing legacy codebases

2020-11-06 Thread seank...@gmail.com
I think you should be able to do `go get ./... dep1@branchA dep2@branchB 
...`
On Friday, November 6, 2020 at 3:20:16 PM UTC+1 Jim Minter wrote:

> Hi,
>
> Using Go 1.14, I'm working on a parent codebase which, in its go.mod 
> file, has a number of replace statements referencing legacy child 
> codebases which have not yet converted to Go modules.
>
> At this stage the legacy child codebases handle versioning by branch, 
> rather than using semantic versioning, so my go.mod file has a number of 
> statements like these:
>
> > replace github.com/foo/bar => github.com/foo/bar 
> v0.0.0-2020xx- // should track branch baz
> > replace github.com/foo/bar1 => github.com/foo/bar1 
> v0.0.0-2020yy- // should track branch baz
>
> My goal is to be confident that if I update dependencies in the parent 
> codebase (go get -u ./...), I'll be pulling in HEAD on the relevant 
> branch of all the legacy child dependencies.
>
> My expectation is that this is a transitional use case because 
> eventually the child codebases will migrate to Go modules, but until 
> then, it's important to me to know I will pull in critical fixes from 
> the child dependencies if they happen.
>
> The difficulty I've got is ensuring that the replace stanzas are valid 
> and up-to-date. I'm not finding a great way to do this with the Go 
> module tooling and I wonder if I'm missing anything. Here are the 
> feasible ugly alternatives I've found so far:
>
> 1. Child by child, abuse the fact that `go mod tidy` rightly or wrongly 
> seems to tolerate a single legacy branch reference in the file at a time 
> and rewrites it to the v0.0.0-2020xx- format:
>
> > go mod edit -replace github.com/foo/bar=github.com/foo/bar@baz
> > go mod tidy
> > go mod edit -replace github.com/foo/bar1=github.com/foo/bar1@baz
> > go mod tidy
> > ...etc...
> > go get -u ./...
>
> 2. A script to be run manually (or via go generate? yikes!) before 
> running go get -u ./..., containing abominations like this:
>
> > go mod edit -replace github.com/foo/bar=$(go list -mod=mod -m 
> github.com/foo/bar@baz | sed -e 's/ /@/')
> > go mod edit -replace github.com/foo/bar1=$(go list -mod=mod -m 
> github.com/foo/bar1@baz | sed -e 's/ /@/')
> > ...etc...
> > go get -u ./...
>
> 3. Alternative abominations like this:
>
> > go mod edit -replace github.com/foo/bar=github.com/foo/bar $(curl -s 
> https://proxy.golang.org/github.com/foo/bar/@v/baz.info | jq -r .Version)
> > go mod edit -replace github.com/foo/bar1=github.com/foo/bar1 $(curl -s 
> https://proxy.golang.org/github.com/foo/bar1/@v/baz.info | jq -r .Version)
> > ...etc...
> > go get -u ./...
>
> I'm wondering: is there a better way? Should there be?
>
> Many thanks!
>
> Jim Minter
>

-- 
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/147a99cd-4c81-45e6-903a-a9813e891037n%40googlegroups.com.


[go-nuts] Re: go get not downloading a module under a repository from BitBucket

2020-11-08 Thread seank...@gmail.com
https://golang.org/ref/mod#vcs-version 3rd paragraph

> If a module is defined in a subdirectory within the repository, that is, 
the module subdirectory 
 portion of the module 
path is not empty, then each tag name must be prefixed with the module 
subdirectory, followed by a slash. For example, the 
module golang.org/x/tools/gopls is defined in the gopls subdirectory of the 
repository with root path golang.org/x/tools. The version v0.4.0 of that 
module must have the tag named gopls/v0.4.0 in that repository.

On Sunday, November 8, 2020 at 2:34:15 AM UTC+1 dean.w@gmail.com wrote:

> In my git repo (bitbucket.org) I have
>
> reponame/
> .git/
> integration1/
> integration2/
> integration-common/
> └── util
> ├── go.mod
> └── readascii.go
>
> The module directory is a subdirectory of the git repository.  The 
> repository is tagged with v0.0.1.
>
> Heres the go.mod
>
> module bitbucket.org/orgname/reponame/integration-common/util
> go 1.14
>
> When I do a go get for this module I get the following error:
>
> go get bitbucket.org/orgname/reponame/integration-common/ut...@v0.0.1 
> 
> go: downloading bitbucket.org/orgname/reponame v0.0.1
> go get bitbucket.org/orgname/reponame/integration-common/ut...@v0.0.1 
> : 
> module bitbucket.org/orgname/repo...@v0.0.1 
>  found, but does not 
> contain package bitbucket.org/orgname/reponame/integration-common/util
>
> I can see the integration-common/util/ directory in bitbucket under the 
> tag v0.0.1 if I look with the web browser.  The go.mod has the contents 
> shown above.
>
> What is even more odd is that go get does manage to download the other 
> directories in the repository (integration1 and integration2).  For some 
> reason it thinks v0.0.1 doesn't contain the integration-common/ directory, 
> even though bitbucket shows it there for that tag.
>
> I have to use ssh instead of https because our private repos on 
> bitbucket.org require 2fa.  I have this in my ~/.gitconfig:
>
> url "g...@bitbucket.org:"]insteadOf = https://bitbucket.org/
>
>
> I know bitbucket is weird when it comes to using go get.  Is there 
> something I missed, or is the a bug with go get and bitbucket?
>
>

-- 
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/93bbadb4-eb9f-4acb-aefe-41a4aa2badccn%40googlegroups.com.


[go-nuts] Re: My app hangs up at some point in net/http/h2_bundle.go. What is the better way to debug?

2020-11-09 Thread seank...@gmail.com
maybe setting GODEBUG=http2debug=2 to spit out some logs?

On Monday, November 9, 2020 at 5:49:57 PM UTC+1 telyuk...@gmail.com wrote:

> Hello!
>
> I use third-party software with my own code to build reverse-proxy, which 
> supports http/2. Sometimes requests hang up with infinite waiting. With 
> Delve I found, that it happens in 
> https://golang.org/src/net/http/h2_bundle.go in writeHeaders or in 
> writeDataFromHandler. But I have no any idea why it happens. Which tools 
> should I use to find the reason of such behaviour?
>
> Denis

-- 
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/94e4b5cd-6005-4a52-916f-9e1a88137399n%40googlegroups.com.


[go-nuts] Re: use same for/range code on a hash map but it has different result

2020-11-10 Thread seank...@gmail.com
spec: https://golang.org/ref/spec#RangeClause

point 3: ... If a map entry is created during iteration, that entry may be 
produced during the iteration or may be skipped. The choice may vary for 
each entry created and from one iteration to the next. ...

On Tuesday, November 10, 2020 at 3:12:54 PM UTC+1 Kilos wrote:

> when I run the same code like this 
> https://play.golang.org/p/fSPpo4_-k57,most of the time it print A,B,C and 
> D,but sometimes it just print A,B and C,why ???
>

-- 
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/f54f305d-2d81-4b13-8bcd-b64947d6b31en%40googlegroups.com.


[go-nuts] Re: Not getting 1.15.5 as the latest Go version - getgo

2020-11-17 Thread seank...@gmail.com
VERSION reports the version the site is under, 
use https://golang.org/dl/?mode=json instead

On Tuesday, November 17, 2020 at 5:21:43 PM UTC+1 fmpw...@gmail.com wrote:

> Hi,
>
> Today I tried the getgo [1] binary but instead of providing Go 1.15.5, it 
> installed 1.15.4. I looked around the code and ended up in
>
> https://golang.org/VERSION?m=text
>
> which reports 1.15.4 as the latest. Is this the right place to report this 
> to get it fixed?
>
>
> [1] https://github.com/golang/tools/tree/master/cmd/getgo
>
>
> 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/edd0092c-0ae5-408e-9ec9-fbf5a6b86cb3n%40googlegroups.com.


[go-nuts] Re: Any recommendation for structured logging library in Golang?

2020-11-18 Thread seank...@gmail.com
Since you've been using glog, k8s.io/klog/v2 (fork by kubernetes) should 
feel familiar and v2 supports the structured variants

On Wednesday, November 18, 2020 at 5:21:48 AM UTC+1 ChrisLu wrote:

> I am considering moving from glog to structured logging. I tried logrus, 
> go-kit, uber/zap, but could not find one good fit. In short, this is the 
> desired format:
>
> [info][timestamp] [filename:line_number] message k1=v1 k2=v2 ...
>
> It shows the correct file name(need to pop out a few call stacks) and line 
> number in a customizable format, not as key-value pair for each line which 
> is just too verbose to have the extra "time=" "file=".
>
> Please let me know the one you actually use.
>
>
> Thanks!
> Chris
> -
> https://github.com/chrislusf/seaweedfs
>

-- 
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/5afb6156-34d5-4bf0-beb0-d24a79ce9b5cn%40googlegroups.com.


Re: [go-nuts] How to plug git version when using "go get" to fetch a cli?

2020-11-25 Thread seank...@gmail.com
using `runtime/debug` this will return a tagged or pseudo version when 
retrieved through `go get` in module mode, in other cases it will return 
`(devel)`

i, _ := debug.ReadBuildInfo()
fmt.Println(i.Main.Version)

On Wednesday, November 25, 2020 at 7:14:45 PM UTC+1 changkun wrote:

> That is really unfortunate. Is there any alternative solution so that I 
> can burn at least the version information to the binary when a user uses 
> `go get`?
>
> On Wednesday, November 25, 2020 at 6:36:17 PM UTC+1 Jan Mercl wrote:
>
>> On Wed, Nov 25, 2020 at 6:25 PM changkun  wrote:
>>
>> > As far as I know, there are two approaches to add extra information at 
>> build time:
>> > 1. using -ldflags="-X path/pkg.Var=${ENV_VAR}", in a Makefile
>> > 2. using `go generate ./...`, before `go build`
>> >
>> > These approaches are good as it is if I build my binary and distribute 
>> it to other users.
>> > However, none of these are possible if a user uses `go get 
>> github.com/user/pkg/cmd/x-cli` , 
>> because:
>> > 1. `go get` does not understand Makefile
>> > 2. `go generate` does not execute with `go build` automatically.
>> >
>> > What should I do in order to plug the extra information (in my case, 
>> the git version) if my user uses "go get"?
>>
>> I don't think that can be done. Also IINM, in module mode `go get` no
>> longer uses git. It just downloads the zipped version of the
>> appropriate tag via http from the hosting service.
>>
>

-- 
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/d1dbd29f-4c46-4939-8d6a-3d3e1f2244a6n%40googlegroups.com.


[go-nuts] error handling proposals summary

2020-11-25 Thread seank...@gmail.com
For some reason I thought going through most of the error handling 
proposals would be a nice way to spend the evening (note I now mostly 
regret this). If anyone wants to see how similar they 
are: https://seankhliao.com/blog/12020-11-23-go-error-handling-proposals/

-- 
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/d4f03a29-3ab2-4342-8123-0f3d1c1ba3cdn%40googlegroups.com.


[go-nuts] Re: [error handling] RFC 'else'

2020-12-02 Thread seank...@gmail.com
see also

https://github.com/golang/go/issues/41908
https://github.com/golang/go/issues/37243
https://github.com/gooid/gonotes/blob/master/inline_style_error_handle.md

On Wednesday, December 2, 2020 at 8:57:13 PM UTC+1 Oliver Smith wrote:

> Do I understand correctly that "last return value is error" is purely 
> convention and there is no formal error handling in current go?
>
> My instinct is to leverage the 'else' keyword along with the notion of a 
> "stock error whose return list's last element is type error with value != 
> nil.
>
>   func not_stock() (int, interface{})
>   func stock() error
>   func stock() (int, error, string, float, error, error, error)
>   func not_stock() (error, error, error, int)
>   func stock() (error, error)
>
> Any other type of error handling can still be handled as the user wishes, 
> stock errors simply provide syntax to lean into, and that syntax would be: 
>  
> [  ]  ast.ELSE 
>
> e.g.
>
> file, err := io.Open(file) else {
>   return nil, err
> }
> fh.Close() else {
>   panic("close call failed")
> }
>
> Equivalent to:
>
> file, err := io.Open(file)
> if err != nil {
>   return nil, err
> }
> if err := fh.Close(); err != nil {
>   panic("close call failed")
> }
>
> One of the current nuisances of error handling is that it can break the 
> clean flow of variable assignments, forcing you to add separate 
> declarations or scopes. Given a function
>
>func NewStruct() (s *Struct, sz int, err error)
>
> you typically have two very different lifespans for the return values
>
>s, sz, err := NewStruct()
>if err != nil {  // last reference to err in function
>
> vs
>
> if s, sz, err := NewStruct(); err != nil {
>   panic(err)
> } else {
>   // to access s and sz
> }
>
> or
>
> var (
>   s *Struct
>   sz int
>   err error   // but literally only for one line
> )
> if s, sz, err = NewStruct(); err != nil {
>   panic(err)
> }
>
> Using the else construct always allows the shorter form, which is at least 
> consistent:
>
> // not a sub-clause so s, sz and err introduced in current scope level.
> s, sz, err := NewStruct() else {
>   panic(err)
> }
>
> The fly in the ointment here is ... where does the error go if you don't 
> mention it?
>
> fh.Close() else {
>   panic(?what?)
> }
>
> the lazy option would be `_`
>
> fh.Close() else {
>   fmt.Errorf("unexpected close failure: %s", _)
>   err := _
>   panic(err)
> }
>
> But I think we can avoid the path of perl, and simply require capture if 
> you want the value surfaced.
>
> err := fh.Close() else {
>   panic(err)
> }
>
>

-- 
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/db52e100-83e0-4fed-9d19-c6278d4a211fn%40googlegroups.com.