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

2020-11-01 Thread Miki Tebeka
I *do* use "go test", 
see https://github.com/tebeka/recheck/blob/master/regression_test.go

On Sunday, November 1, 2020 at 8:43:33 AM UTC+2 amits...@gmail.com wrote:

>
>
> On Sun, 1 Nov 2020, 4:07 pm Miki Tebeka,  wrote:
>
>> Hi,
>>
>> I wrote a regexp linter (https://github.com/tebeka/recheck) that's using 
>> golang.org/x/tools/go/analysis.
>>
>> To test the tool, I run  "go run ./cmd/recheck testdata/ok.go" (using 
>> os/exec). The problem is that after the test, go.mod & go.sum are modified 
>> since there are some external imports in the go files under testdata.
>>
>> I've tried using -mod=readonly, building & then running, moving the test 
>> file to /tmp - all of them didn't work, the mod files are still changed 
>> after the test.
>>
>> Any idea how can I prevent the test from modifing the mod files?
>>
>
> Your example above suggests you are not using go test to execute your 
> tests? 
>
>
>> Thanks,
>> Miki
>>
>> -- 
>> 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/701453b4-eaa7-4a92-a8a1-520ae6d66fcfn%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/bc16d6c7-131d-4666-9b01-2a41ba04c42bn%40googlegroups.com.


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

2020-11-01 Thread 'Dan Kortschak' via golang-nuts
You're using go test, with -mod=readonly, but it's running your code
with go run, without -mod=readonly.

Either you'll need to unconditionally pass -mod=readonly to go run in
the regression_test.go file, or find wether it's been passed to go test
and then conditionally pass it to go run.


On Sun, 2020-11-01 at 01:09 -0700, Miki Tebeka wrote:
> I *do* use "go test", see 
> https://github.com/tebeka/recheck/blob/master/regression_test.go
> 
> On Sunday, November 1, 2020 at 8:43:33 AM UTC+2 amits...@gmail.com
> wrote:
> > 
> > On Sun, 1 Nov 2020, 4:07 pm Miki Tebeka, 
> > wrote:
> > > Hi,
> > > 
> > > I wrote a regexp linter (https://github.com/tebeka/recheck)
> > > that's using golang.org/x/tools/go/analysis.
> > > 
> > > To test the tool, I run  "go run ./cmd/recheck testdata/ok.go"
> > > (using os/exec). The problem is that after the test, go.mod &
> > > go.sum are modified since there are some external imports in the
> > > go files under testdata.
> > > 
> > > I've tried using -mod=readonly, building & then running, moving
> > > the test file to /tmp - all of them didn't work, the mod files
> > > are still changed after the test.
> > > 
> > > Any idea how can I prevent the test from modifing the mod files?
> > 
> > Your example above suggests you are not using go test to execute
> > your tests? 
> > 
> > > Thanks,
> > > Miki


-- 
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/80699bdc8a81f300b2b769ae7c8a40dbdead6d7d.camel%40kortschak.io.


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

2020-11-01 Thread Amit Saha


> On 1 Nov 2020, at 7:22 pm, 'Dan Kortschak' via golang-nuts 
>  wrote:
> 
> You're using go test, with -mod=readonly, but it's running your code
> with go run, without -mod=readonly.
> 
> Either you'll need to unconditionally pass -mod=readonly to go run in
> the regression_test.go file, or find wether it's been passed to go test
> and then conditionally pass it to go run.
> 
> 
> On Sun, 2020-11-01 at 01:09 -0700, Miki Tebeka wrote:
>> I *do* use "go test", see 
>> https://github.com/tebeka/recheck/blob/master/regression_test.go

I am not sure I don’t see go test in there. But I think Dan already gave you a 
hint.


>> 
>> On Sunday, November 1, 2020 at 8:43:33 AM UTC+2 amits...@gmail.com
>> wrote:
>>> 
>>> On Sun, 1 Nov 2020, 4:07 pm Miki Tebeka, 
>>> wrote:
 Hi,
 
 I wrote a regexp linter (https://github.com/tebeka/recheck)
 that's using golang.org/x/tools/go/analysis.
 
 To test the tool, I run  "go run ./cmd/recheck testdata/ok.go"
 (using os/exec). The problem is that after the test, go.mod &
 go.sum are modified since there are some external imports in the
 go files under testdata.
 
 I've tried using -mod=readonly, building & then running, moving
 the test file to /tmp - all of them didn't work, the mod files
 are still changed after the test.
 
 Any idea how can I prevent the test from modifing the mod files?
>>> 
>>> Your example above suggests you are not using go test to execute
>>> your tests? 
>>> 
 Thanks,
 Miki
> 
> 
> -- 
> 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/80699bdc8a81f300b2b769ae7c8a40dbdead6d7d.camel%40kortschak.io
>  
> .

-- 
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/643937D0-4B19-4008-8999-7D7E63E0F5F3%40gmail.com.


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

2020-11-01 Thread Miki Tebeka
I try to change the "go run" command to use "-mod=readonly", didn't help.

On Sunday, November 1, 2020 at 10:23:07 AM UTC+2 kortschak wrote:

> You're using go test, with -mod=readonly, but it's running your code
> with go run, without -mod=readonly.
>
> Either you'll need to unconditionally pass -mod=readonly to go run in
> the regression_test.go file, or find wether it's been passed to go test
> and then conditionally pass it to go run.
>
>
> On Sun, 2020-11-01 at 01:09 -0700, Miki Tebeka wrote:
> > I *do* use "go test", see 
> > https://github.com/tebeka/recheck/blob/master/regression_test.go
> > 
> > On Sunday, November 1, 2020 at 8:43:33 AM UTC+2 amits...@gmail.com
> > wrote:
> > > 
> > > On Sun, 1 Nov 2020, 4:07 pm Miki Tebeka, 
> > > wrote:
> > > > Hi,
> > > > 
> > > > I wrote a regexp linter (https://github.com/tebeka/recheck)
> > > > that's using golang.org/x/tools/go/analysis.
> > > > 
> > > > To test the tool, I run "go run ./cmd/recheck testdata/ok.go"
> > > > (using os/exec). The problem is that after the test, go.mod &
> > > > go.sum are modified since there are some external imports in the
> > > > go files under testdata.
> > > > 
> > > > I've tried using -mod=readonly, building & then running, moving
> > > > the test file to /tmp - all of them didn't work, the mod files
> > > > are still changed after the test.
> > > > 
> > > > Any idea how can I prevent the test from modifing the mod files?
> > > 
> > > Your example above suggests you are not using go test to execute
> > > your tests? 
> > > 
> > > > Thanks,
> > > > Miki
>
>
>

-- 
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/354542dc-0648-4383-98af-63ff4f7dabcfn%40googlegroups.com.


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

2020-11-01 Thread ma...@eliasnaur.com
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/9454a1ab-49e8-498e-a627-2fa628108fc6n%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.


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

2020-11-01 Thread 'Dan Kortschak' via golang-nuts
Ah, it just clicked.

You're indirectly using go/packages, which will (unless configured not
to), cause changes to the go.mod and go.sum file. This configuration
happens for this by adding "-mod=readonly" to
packages.Config.BuildFlags (I think). But this isn't exposed via the
go/analysis API (the config is populated here[1] where the user can't
access it).

This can be confirmed by seeing that building your checker, resetting
the changes to go.mod and go.sum and then manually running the binary
on your test cases.

I'm not sure what to do about this.

[1]
https://github.com/golang/tools/blob/582c62ec74d06936c88d4b760c63cbc2925e69c7/go/analysis/internal/checker/checker.go#L152-L155

On Sun, 2020-11-01 at 04:52 -0800, Miki Tebeka wrote:
> I try to change the "go run" command to use "-mod=readonly", didn't
> help.
> 
> On Sunday, November 1, 2020 at 10:23:07 AM UTC+2 kortschak wrote:
> > You're using go test, with -mod=readonly, but it's running your
> > code 
> > with go run, without -mod=readonly. 
> > 
> > Either you'll need to unconditionally pass -mod=readonly to go run
> > in 
> > the regression_test.go file, or find wether it's been passed to go
> > test 
> > and then conditionally pass it to go run. 
> > 
> > 
> > On Sun, 2020-11-01 at 01:09 -0700, Miki Tebeka wrote: 
> > > I *do* use "go test", see 
> > > https://github.com/tebeka/recheck/blob/master/regression_test.go 
> > > 
> > > On Sunday, November 1, 2020 at 8:43:33 AM UTC+2 
> > amits...@gmail.com 
> > > wrote: 
> > > > 
> > > > On Sun, 1 Nov 2020, 4:07 pm Miki Tebeka,  
> > > > wrote: 
> > > > > Hi, 
> > > > > 
> > > > > I wrote a regexp linter (https://github.com/tebeka/recheck) 
> > > > > that's using golang.org/x/tools/go/analysis. 
> > > > > 
> > > > > To test the tool, I run "go run ./cmd/recheck
> > testdata/ok.go" 
> > > > > (using os/exec). The problem is that after the test, go.mod
> > & 
> > > > > go.sum are modified since there are some external imports in
> > the 
> > > > > go files under testdata. 
> > > > > 
> > > > > I've tried using -mod=readonly, building & then running,
> > moving 
> > > > > the test file to /tmp - all of them didn't work, the mod
> > files 
> > > > > are still changed after the test. 
> > > > > 
> > > > > Any idea how can I prevent the test from modifing the mod
> > files? 
> > > > 
> > > > Your example above suggests you are not using go test to
> > execute 
> > > > your tests? 
> > > > 
> > > > > Thanks, 
> > > > > Miki 
> > 
> > 
> 
> -- 
> 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/354542dc-0648-4383-98af-63ff4f7dabcfn%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/8311ca8d52158493a088d88bef33ee93f82c6e7a.camel%40kortschak.io.


[go-nuts] json.number in struct

2020-11-01 Thread irvan hendrik
Hi, I have 
type Product struct {
Weight json.Number 
}

func (p Product) GetWeight() float64 {
tmp, _ := p.Weight.Float64()
return tmp
}

I would like to be able to call and assign the variable directly. I got the 
GetWeight() to help me convert from json.Number to float64.
How to assign the variable? 
I would like to be able to use
p Product
&p.Weight
 
Can some one help me or simplify the GetWeight also maybe?
because right now I can only do it by:
var tempWeight float32
assign using &tempWeight
then 
p.Product = json.Number(fmt.Sprintf("%f", tempWeight))

Thank you.


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e10dcacf-7445-48c6-88f0-90d9b72bfbafn%40googlegroups.com.


[go-nuts] Creating your OWN GitHub Action in Go

2020-11-01 Thread Michael Levan
https://www.youtube.com/watch?v=8IgNY8QT3vk

-- 
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/c50f5106-8709-4389-a08e-8049cba3f1b8n%40googlegroups.com.


[go-nuts] Hash Tables Inner Implementation in Go - A story (for normal people)

2020-11-01 Thread Marwan abdel moneim
Hi Guys,

I spent a lot of days diving into the implementation of the maps in Go, and 
wrote this article 
 
that makes it easy for other people to understand the implementation better.

Thanks very much for *Keith Randall* for helping me understanding some 
details in the code.

Please comment if you found any mistake in the article.

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/fa3f7013-d0e3-4700-9d01-d92f3c86f24fn%40googlegroups.com.


[go-nuts] Does GOMAXPROCS(1) means run a program deterministically

2020-11-01 Thread Ting Yuan

I find it is tricky to debug a concurrency Go program in multi-core 
systems, so I wonder if there is a way to make the program run in 
deterministically. Can I assume a program with GOMAXPROCS(1) can be 
deterministically 
executed ?

Here a deterministic execution means once the input is given, the execution 
of the prorgam is serialized. Every instruction in the execution follows a 
certain order unless the input is changed.

-- 
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/f6587369-f5d3-489c-98d7-7bbf79c05b65n%40googlegroups.com.


Re: [go-nuts] Does GOMAXPROCS(1) means run a program deterministically

2020-11-01 Thread Harald Weidner
Hello,

> I find it is tricky to debug a concurrency Go program in multi-core
> systems, so I wonder if there is a way to make the program run in
> deterministically. Can I assume a program with GOMAXPROCS(1) can be 
> deterministically
> executed ?

Even with GOMAXPROCS=1, a Go program is not 100% deterministic. See this
funny blog post on how to gain randomness even without using the standard
library.
https://blog.merovius.de/2018/01/15/generating_entropy_without_imports_in_go.html

Using libs, there are even more sources of indeterminism, e.g. time.Now()
or both of the "rand" packages.

Best regards,
Harald

-- 
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/20201102073052.GA12615%40hweidner.de.


Re: [go-nuts] Trying to call powershell script from Go

2020-11-01 Thread Uzair Ally
Hi Kurtis,

The issue on my end was the same, I had to bypass execution policy for 
powershell and change script.ps1 to \\script.ps1. Thanks for your help with 
this, much appreciated! 

On Thursday, October 29, 2020 at 5:56:32 AM UTC+3 Kurtis Rader wrote:

> I ran, in an interactive administrative PowerShell session, this command:
>
> Set-ExecutionPolicy -Scope CurrentUser Unrestricted
>
> After doing that I was able to successfully run your program after 
> changing "script.ps1" to ".\\script.ps1". That is, I saw "hello" and "err" 
> was nil.
>
> On Wed, Oct 28, 2020 at 9:48 AM Uzair Ally  wrote:
>
>> Hi Marvin,
>>
>> That was the issue. I removed the quotes from cmdName and the compiler 
>> identified it as a variable instead of a string. 
>> So I updated the code, removing the quotes from cmdName and it compiled, 
>> but I'm seeing the err output now and exit status 1 instead of actual 
>> output from the commands in the powershell script. Any ideas why the 
>> program is giving me the error out instead of running the powershell 
>> script? 
>>
>> CODE:
>> package main
>> import (
>> "fmt"
>> "os"
>> "os/exec"
>> )
>> func main() {
>> cmdName := 
>> "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
>> out, err := exec.Command(cmdName, "script.ps1").Output()
>> if err != nil {
>> fmt.Fprintln(os.Stderr, "Error creating StdoutPipe for Cmd", err)
>> }
>> fmt.Println(string(out))
>> }
>>
>> ERROR:
>> Error creating StdoutPipe for Cmd exit status 1
>>
>>
>> On Wednesday, October 28, 2020 at 7:46:08 PM UTC+3 Uzair Ally wrote:
>>
>>> Hi Jake.. sorry for the confusion.. appreciate your input!
>>>
>>>
>>> On Wednesday, October 28, 2020 at 3:00:24 PM UTC+3 jake...@gmail.com 
>>> wrote:
>>>
 Technically your code is not runnable, since it does not compile. I 
 misunderstood, and thought you were having a problem with running a 
 powershell script from Go, but actually you are having a problem compiling 
 the code. Very different problems. So never-mind ;-)
 On Tuesday, October 27, 2020 at 2:18:25 PM UTC-4 mua...@gmail.com 
 wrote:

> Hi Jake,
>
> The code I posted is the runnable go program just missing the 
> powershell script which is a separate file. Maybe I'm miss understanding? 
> Is there something else I can provide to help you understand further?
>
> On Tuesday, October 27, 2020 at 8:48:54 PM UTC+3 jake...@gmail.com 
> wrote:
>
>> It might help if you posted an actual runnable program, that you have 
>> personally run, and the full output. 
>>
>> On Tuesday, October 27, 2020 at 1:26:53 PM UTC-4 mua...@gmail.com 
>> wrote:
>>
>>> Hi Marvin,
>>>
>>> If I add script.ps1 in double quotes and try to run, it tells me 
>>> cmdName declared but no used.
>>> Yes, the script is named script.ps1. The script is not a variable.
>>>
>>> On Tuesday, October 27, 2020 at 8:22:14 PM UTC+3 Marvin Renich wrote:
>>>
 * Uzair Ally  [201027 12:25]: 
 > Hi, 
 > 
 > I am getting the following error when I try to call a powershell 
 script 
 > from go. 
 > 
 > undefined: script 
 > 
 > Here is the code: 
 > 
 > cmdName := 
 "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" 
 > out, err := exec.Command("cmdName", script.ps1).Output() 

 Perhaps you what you intended was: 
 out, err := exec.Command("cmdName", "script.ps1").Output() 

 Is your script named script.ps1 or is script a variable with a 
 field 
 named ps1 containing the name of the script? 

 > if err != nil { 
 > fmt.Fprintln(os.Stderr, "Error creating StdoutPipe for Cmd", err) 
 > 
 > 
 > It looks like go doesn't recognize the powershell script. How do 
 I resolve 
 > this error? Any help or guidance will be appreciated. 

 ...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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/1a532275-eaee-4bbf-872e-11caf38ee1e2n%40googlegroups.com
>>  
>> 
>> .
>>
>
>
> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>

-- 
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/bca934c3

[go-nuts] Re: json.number in struct

2020-11-01 Thread Brian Candler
Is there a particular reason why you don't just do this?

type Product struct {
Weight float64
}

That should serialize to/from JSON just fine.  You can also include 
metadata about how you want it serialized:

type Product struct {
Weight float64 `json:"weight,omitempty"`
}


-- 
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/07b5217b-2b7e-47e0-8316-fba13d869cado%40googlegroups.com.