[go-nuts] Deploying Translated Golang Tour on AppEngine: Questions

2024-06-13 Thread Daniel Castillo


Hello everyone,

I am currently working on translating the Golang Tour (Introduction Guide 
to Golang) into Spanish. As part of this project, I have a couple of 
questions regarding the deployment pipeline of the Golang Tour on AppEngine:

   1. Is anyone familiar with the deployment pipeline for the Golang Tour 
   on AppEngine?
   2. When the tour is deployed, does it remain within some kind of free 
   tier?

I appreciate any insights or advice you can offer.

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/07349e45-f3cd-44c4-89fb-a8dd94c78bd6n%40googlegroups.com.


[go-nuts] Re: `go fix ./...` in go1.22.4 is reporting invalid go version

2024-06-13 Thread David Ševčík
Ok, I was searching in wrong branch, I found the cause, it's caused by the 
custom 
version parsing 

 
in the 1.22 branch, in the main it's fixed

On Wednesday, June 12, 2024 at 3:54:10 PM UTC+2 David Ševčík wrote:

> Hello guys,
> when I run locally or in CircleCI  command `go fix 
> ./...` it reports this error multiple times:
> go fix ./...
> invalid -go=go1.22.0
> exit status 2
> invalid -go=go1.22.0
> exit status 2
> invalid -go=go1.22.0
> exit status 2
> invalid -go=go1.22.0
> exit status 2
> invalid -go=go1.22.0
> exit status 2
> invalid -go=go1.22.0
> exit status 2
> invalid -go=go1.22.0
> exit status 2
> invalid -go=go1.22.0
> exit status 2
> invalid -go=go1.22.0
> exit status 2
> invalid -go=go1.22.0
> exit status 2
> invalid -go=go1.22.0
> exit status 2
> invalid -go=go1.22.0
> exit status 2
> invalid -go=go1.22.0
> exit status 2
>
> When digging deeper, it shows that the underlying tool is reporting this 
> error:
> go tool fix -go=go1.22.0 .
> invalid -go=go1.22.0
>
> When I omit the path, it works:
> go tool fix -go=go1.22 .
> (no error, no output)
>
> In source code, it looks like it uses standard go validation for the 
> version:
>
> https://github.com/golang/go/blob/b788e91badd523e5bb0fc8d50cd76b8ae04ffb20/src/cmd/fix/main.go#L75
>
> I tried to run this validation in a test and it works:
> func Test(t *testing.T) {
> require.True(t, version.IsValid("go1.22.0"))
> }
> // Output
> === RUN   Test
> --- PASS: Test (0.00s)
> PASS
> So I'm confused, why it fails.
>
> Local machine:
> Apple M3 Pro
> macOS Sonoma (Version 14.5 (23F79))
>
> Installed go is:
> go version go1.22.4 darwin/arm64
> In go.mod is:
> go 1.22.0
>
> toolchain go1.22.4
>
> This tool fails also in the CircleCI, used image is:
> cimg/go:1.22 
> 
>  
> where is probably also go1.22.4
>
> Do anybody know why it's happening and how to fix it?
> Looks like a bug to me 樂
>

-- 
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/7db14153-0201-4c0b-ac69-eb9c6baa0739n%40googlegroups.com.


[go-nuts] `go fix ./...` in go1.22.4 is reporting invalid go version

2024-06-12 Thread David Ševčík
Hello guys,
when I run locally or in CircleCI  command `go fix 
./...` it reports this error multiple times:
go fix ./...
invalid -go=go1.22.0
exit status 2
invalid -go=go1.22.0
exit status 2
invalid -go=go1.22.0
exit status 2
invalid -go=go1.22.0
exit status 2
invalid -go=go1.22.0
exit status 2
invalid -go=go1.22.0
exit status 2
invalid -go=go1.22.0
exit status 2
invalid -go=go1.22.0
exit status 2
invalid -go=go1.22.0
exit status 2
invalid -go=go1.22.0
exit status 2
invalid -go=go1.22.0
exit status 2
invalid -go=go1.22.0
exit status 2
invalid -go=go1.22.0
exit status 2

When digging deeper, it shows that the underlying tool is reporting this 
error:
go tool fix -go=go1.22.0 .
invalid -go=go1.22.0

When I omit the path, it works:
go tool fix -go=go1.22 .
(no error, no output)

In source code, it looks like it uses standard go validation for the 
version:
https://github.com/golang/go/blob/b788e91badd523e5bb0fc8d50cd76b8ae04ffb20/src/cmd/fix/main.go#L75

I tried to run this validation in a test and it works:
func Test(t *testing.T) {
require.True(t, version.IsValid("go1.22.0"))
}
// Output
=== RUN   Test
--- PASS: Test (0.00s)
PASS
So I'm confused, why it fails.

Local machine:
Apple M3 Pro
macOS Sonoma (Version 14.5 (23F79))

Installed go is:
go version go1.22.4 darwin/arm64
In go.mod is:
go 1.22.0

toolchain go1.22.4

This tool fails also in the CircleCI, used image is:
cimg/go:1.22 

 
where is probably also go1.22.4

Do anybody know why it's happening and how to fix it?
Looks like a bug to me 樂

-- 
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/daa7f469-de6d-4e3f-9d3d-d0a9f64c45d0n%40googlegroups.com.


[go-nuts] Re: Failed to compile apptainer on Ubuntu 22.04.4 LTS.

2024-06-11 Thread Hongyi Zhao


On Tuesday, June 11, 2024 at 9:23:19 PM UTC+8 Hongyi Zhao wrote:

On Ubuntu 22.04.4 LTS, I tried to compile the latest GitHub version of 
apptainer using the guidance [here](
https://github.com/apptainer/apptainer/blob/main/INSTALL.md), but failed at 
the `make` step:

```shell
$ go version
go version devel go1.23-62711d61e5 Thu May 23 03:44:19 2024 + 
linux/amd64
$ sudo apt-get install -y build-essential libseccomp-dev 
pkg-config uidmap squashfs-tools fakeroot cryptsetup 
tzdata curl wget git

$ cd "/home/werner/Public/repo/github.com/apptainer/apptainer.git" 
$ proxychains-ng-country-control go mod download
$ ./mconfig
$ cd builddir
$ make
 GEN GO DEP /home/werner/Public/repo/
github.com/apptainer/apptainer.git/builddir/starter.deps
 GEN GO DEP /home/werner/Public/repo/
github.com/apptainer/apptainer.git/builddir/apptainer.deps
 GEN GO DEP /home/werner/Public/repo/
github.com/apptainer/apptainer.git/builddir/starter.deps
 GO apptainer
[+] GO_TAGS "containers_image_openpgp sylog oci_engine apptainer_engine 
fakeroot_engine apparmor selinux seccomp"
package github.com/apptainer/apptainer/cmd/apptainer
imports github.com/apptainer/apptainer/cmd/internal/cli
imports github.com/apptainer/apptainer/internal/app/apptainer
imports github.com/apptainer/apptainer/internal/pkg/runtime/engine/oci
imports 
github.com/apptainer/apptainer/internal/pkg/runtime/engine/config/starter: 
build constraints exclude all Go files in /home/werner/Public/repo/
github.com/apptainer/apptainer.git/internal/pkg/runtime/engine/config/starter
make: *** [Makefile:181: apptainer] Error 1
```

Any tips for fixing this problem? See here [1] for the related discussion.


I found that the issue was due to using the self-compiled latest git commit 
version of Go. Switching to the latest stable version of Go solved the 
problem.


[1] https://github.com/apptainer/apptainer/issues/2265

Regards,
Zhao

-- 
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/2f1f787b-0150-4add-8206-b5d2b149aeffn%40googlegroups.com.


[go-nuts] Failed to compile apptainer on Ubuntu 22.04.4 LTS.

2024-06-11 Thread Hongyi Zhao
On Ubuntu 22.04.4 LTS, I tried to compile the latest GitHub version of 
apptainer using the guidance 
[here](https://github.com/apptainer/apptainer/blob/main/INSTALL.md), but 
failed at the `make` step:

```shell
$ go version
go version devel go1.23-62711d61e5 Thu May 23 03:44:19 2024 + 
linux/amd64
$ sudo apt-get install -y build-essential libseccomp-dev 
pkg-config uidmap squashfs-tools fakeroot cryptsetup 
tzdata curl wget git

$ cd "/home/werner/Public/repo/github.com/apptainer/apptainer.git" 
$ proxychains-ng-country-control go mod download
$ ./mconfig
$ cd builddir
$ make
 GEN GO DEP 
/home/werner/Public/repo/github.com/apptainer/apptainer.git/builddir/starter.deps
 GEN GO DEP 
/home/werner/Public/repo/github.com/apptainer/apptainer.git/builddir/apptainer.deps
 GEN GO DEP 
/home/werner/Public/repo/github.com/apptainer/apptainer.git/builddir/starter.deps
 GO apptainer
[+] GO_TAGS "containers_image_openpgp sylog oci_engine apptainer_engine 
fakeroot_engine apparmor selinux seccomp"
package github.com/apptainer/apptainer/cmd/apptainer
imports github.com/apptainer/apptainer/cmd/internal/cli
imports github.com/apptainer/apptainer/internal/app/apptainer
imports github.com/apptainer/apptainer/internal/pkg/runtime/engine/oci
imports 
github.com/apptainer/apptainer/internal/pkg/runtime/engine/config/starter: 
build constraints exclude all Go files in 
/home/werner/Public/repo/github.com/apptainer/apptainer.git/internal/pkg/runtime/engine/config/starter
make: *** [Makefile:181: apptainer] Error 1
```

Any tips for fixing this problem? See here [1] for the related discussion.

[1] https://github.com/apptainer/apptainer/issues/2265

Regards,
Zhao

-- 
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/1dc36f6c-7de2-485e-8a7f-6989e1d3de91n%40googlegroups.com.


Re: [go-nuts] Nillable basic types?

2024-06-10 Thread Daniel Lepage
>
>  But I think this is not really worth arguing. If you change fundamental
> things like this in the language, then you'll suggesting turning Go into
> something that looks like Rust. In which case, you may as well just use
> Rust.

I don't think I'm proposing a fundamental change, or to turn Go into Rust -
there are good reasons why Go (and the majority of other languages) don't
force us to null-check every single pointer access, because there are lots
of use cases for pointers besides "this can be null" (e.g. for mutability
or performance reasons). I'm proposing a fairly specific syntax to solve a
fairly specific (but, at least in projects I've worked on, incredibly
common) problem. That said, I do agree that #57644
 subsumes this problem (as do a
number of other proposals for union or variant types), and if this feature
were to be implemented it would definitely be preferable to do so en route
to a fuller variant type solution.

-- 
Dan

On Thu, Mar 21, 2024 at 11:04 PM Mike Schinkel  wrote:

> Hi Axel,
>
> Thank you for that link. I had not seen it before, but it is rather
> insightful.
>
> -Mike
>
> On Wednesday, March 20, 2024 at 10:29:20 AM UTC-4 Axel Wagner wrote:
>
> FWIW I believe (as Brian sort of points out) this proposal is fully
> subsumed under #57644 . Under
> that proposal, the proposed type `int | nil` would be spelled `interface{
> int }`. The other syntactical constructs are, as far as I can tell,
> identical - you'd have to use a type-assertion to use an `interface{ int }`
> as an integer (e.g. to do arithmetic), you can use it with type-switches,
> and any `int` as well as `nil` would be assignable to it.
>
> I think the one difference would be that `x == 42` would work on
> `interface{ int }`, but would (presumably) not work on `int | nil`. I
> personally doubt that this difference would justify an extra construction,
> but I'm mentioning it for completeness sake.
>
> The "nice to have" of type guards is, I think, an easy idea to mention,
> but not an easy idea to add to Go. Note that the other languages mentioned,
> that do that, use a function-scoped type-inference (as far as I know) -
> that is, they look at an identifiers use over the entire function and then
> infer the most general type it would have.
> Go has so far tried to avoid doing anything like that, limiting any
> inference to the statement (or expression) a value appears in. And this
> idea effectively means an identifier would change its type over its
> lifetime (from `interface{ int }` - does not allow arithmetic - to `int` -
> does allow arithmetic), which would create numerous problems for existing
> tooling, as it violates assumptions made by the `go/*` packages.
>
> On Wed, Mar 20, 2024 at 11:26 AM Mike Schinkel wrote:
>
> On Wednesday, March 20, 2024 at 5:47:00 AM UTC-4 Brian Candler wrote:
>
> If you change fundamental things like this in the language, then you'll
> suggesting turning Go into something that looks like Rust. In which case,
> you may as well just use Rust.
>
>
> Agreed.  Which is why I was asking if using interfaces as type constraints
> would address the concern.
>
> And as discussed, probably not.
>
> But it is an interesting thought exercise. If an interface-based solution
> could be found, it would address the concern without turning us effectively
> into Rust programmers. ¯\_(ツ)_/¯
>
> -Mike
>
> --
>
> 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/b3cf8686-b0fb-4cdd-938e-deee4a6af273n%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/b13c0f3c-2f87-4270-bc57-a22c577473d9n%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/CANtoCQ_ATPoPxbDvCbj30yN0RvS_W8c4qKfQYRpBbTcuEdObiw%40mail.gmail.com.


[go-nuts] Re: Guidance on techniques that can help me write a comprehensive test for my go library.

2024-06-08 Thread Amnon
https://research.swtch.com/testing

On Friday 7 June 2024 at 14:26:35 UTC+1 Guilherme Henrique wrote:

> You want to make a mock of the Google API calls, the same ones you use in 
> your project, and that's it?
>
> Em quarta-feira, 5 de junho de 2024 às 10:41:03 UTC-3, Ai Readone escreveu:
>
>> Hello Everyone,
>>
>> I am currently writing a go library that Integrates various Google cloud 
>> services.
>>
>> The aim of the library is to eliminate duplicate implementations across 
>> various services of the same software.
>>
>>
>> I am having challenges on how to write a comprehensive test for my 
>> library, the main challenges are coming from testing function and methods 
>> that performs remote call to Google cloud APIs
>>
>> I want to be able to mock every function in my library.
>>
>> I am familiar with majorly table-testing technique but I am open 
>> to suggestions that requires me to learn new technologies too.
>>
>> Thanks in advance for your time and help.
>>
>

-- 
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/319e668f-20a7-46d4-8172-91ef87c62e02n%40googlegroups.com.


[go-nuts] Re: Guidance on techniques that can help me write a comprehensive test for my go library.

2024-06-07 Thread Guilherme Henrique
You want to make a mock of the Google API calls, the same ones you use in 
your project, and that's it?

Em quarta-feira, 5 de junho de 2024 às 10:41:03 UTC-3, Ai Readone escreveu:

> Hello Everyone,
>
> I am currently writing a go library that Integrates various Google cloud 
> services.
>
> The aim of the library is to eliminate duplicate implementations across 
> various services of the same software.
>
>
> I am having challenges on how to write a comprehensive test for my 
> library, the main challenges are coming from testing function and methods 
> that performs remote call to Google cloud APIs
>
> I want to be able to mock every function in my library.
>
> I am familiar with majorly table-testing technique but I am open 
> to suggestions that requires me to learn new technologies too.
>
> Thanks in advance for your time and help.
>

-- 
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/4c713822-0faf-499d-8aa9-243597a1f00cn%40googlegroups.com.


[go-nuts] [x/term] Adding history save/restore/clear/etc and some small issues

2024-06-06 Thread Dragos Vingarzan
Hey folks,

I recently embedded the golang.go/x/term into my application and I love the 
simplicity and effectiveness of having such a terminal.

The history part of it is also great to have, but even better if one could 
save/restore the history over application restarts. I did some changes and 
a proof-of-concept and I'm wondering if this would be worth merging. So any 
developers/maintainers/users here which I could maybe ping ideas with, 
before submitting a patch for review?

I also found a couple of slightly annoying issues which I'd also like to 
fix:
1. Terminal.ReadPassword() allows the auto-complete callback; I don't see 
why that would be helpful, other than making TABs harder to use in 
passwords :-p. Of course, once could simply unset/set the callback around 
the calls to Terminal.ReadPassword(), but feels like I shouldn't need that 
(e.g. some users might leak partial password unintentionally).
2. I redirected all my stdout logs through Terminal.Write(), but still, I'm 
getting some funky wrapped lines when (I guess) my go-routines write things 
in parallel or maybe when the prompt is "refreshed"... not sure.

Cheers,
-Dragos 

-- 
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/bb138fc1-9cd4-4d0e-8590-1f17a861a89en%40googlegroups.com.


[go-nuts] Re: Guidance on techniques that can help me write a comprehensive test for my go library.

2024-06-06 Thread Jeremy French
This:
> "I want to be able to mock every function in my library."
is a bit confusing. Normally, you want to mock the functions that your 
library calls, not your own library functions.

Other than that, this seems pretty doable.. Can you give some more 
clarification as to what aspect is giving you trouble?
On Thursday, June 6, 2024 at 2:27:53 AM UTC-4 Marcello H wrote:

> Normally, the way to use the functions/methods of the external library is 
> by having an interface with all the function definitions.
>
> Then you can generate a mock that offers the same functionality.
> With such a mock, you can give all kinds of results back to the caller.
>
> Do you have your project in a public GIT?
>
> Op woensdag 5 juni 2024 om 15:41:03 UTC+2 schreef Ai Readone:
>
>> Hello Everyone,
>>
>> I am currently writing a go library that Integrates various Google cloud 
>> services.
>>
>> The aim of the library is to eliminate duplicate implementations across 
>> various services of the same software.
>>
>>
>> I am having challenges on how to write a comprehensive test for my 
>> library, the main challenges are coming from testing function and methods 
>> that performs remote call to Google cloud APIs
>>
>> I want to be able to mock every function in my library.
>>
>> I am familiar with majorly table-testing technique but I am open 
>> to suggestions that requires me to learn new technologies too.
>>
>> Thanks in advance for your time and help.
>>
>

-- 
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/f2216db5-5382-412d-bb33-2041e939ecc6n%40googlegroups.com.


[go-nuts] Re: Guidance on techniques that can help me write a comprehensive test for my go library.

2024-06-06 Thread Marcello H
Normally, the way to use the functions/methods of the external library is 
by having an interface with all the function definitions.

Then you can generate a mock that offers the same functionality.
With such a mock, you can give all kinds of results back to the caller.

Do you have your project in a public GIT?

Op woensdag 5 juni 2024 om 15:41:03 UTC+2 schreef Ai Readone:

> Hello Everyone,
>
> I am currently writing a go library that Integrates various Google cloud 
> services.
>
> The aim of the library is to eliminate duplicate implementations across 
> various services of the same software.
>
>
> I am having challenges on how to write a comprehensive test for my 
> library, the main challenges are coming from testing function and methods 
> that performs remote call to Google cloud APIs
>
> I want to be able to mock every function in my library.
>
> I am familiar with majorly table-testing technique but I am open 
> to suggestions that requires me to learn new technologies too.
>
> Thanks in advance for your time and help.
>

-- 
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/a79ed2ea-5d89-4cb1-9c3f-1e4eb09d78aen%40googlegroups.com.


[go-nuts] Guidance on techniques that can help me write a comprehensive test for my go library.

2024-06-05 Thread Ai Readone
Hello Everyone,

I am currently writing a go library that Integrates various Google cloud
services.

The aim of the library is to eliminate duplicate implementations across
various services of the same software.


I am having challenges on how to write a comprehensive test for my library,
the main challenges are coming from testing function and methods that
performs remote call to Google cloud APIs

I want to be able to mock every function in my library.

I am familiar with majorly table-testing technique but I am open
to suggestions that requires me to learn new technologies too.

Thanks in advance for your time and help.

-- 
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/CAC3%3DO7w%3DdFY4r%3DKixhvP5V4-HT3rZw3UFEVXb%2B2F%3D6yQiu0Pnw%40mail.gmail.com.


[go-nuts] [security] Go 1.22.4 and Go 1.21.11 are released

2024-06-04 Thread announce
Hello gophers,

We have just released Go versions 1.22.4 and 1.21.11, minor point releases.

These minor releases include 2 security fixes following the security policy 
:

-   archive/zip: mishandling of corrupt central directory record

The archive/zip package's handling of certain types of invalid zip 
files differed from the behavior of most zip implementations. This misalignment 
could be exploited to create an zip file with contents that vary depending on 
the implementation reading the file. The archive/zip package now rejects files 
containing these errors.

Thanks to Yufan You (@ouuan) for reporting this issue.

This is CVE-2024-24789 and Go issue https://go.dev/issue/66869.

-   net/netip: unexpected behavior from Is methods for IPv4-mapped IPv6 
addresses

The various Is methods (IsPrivate, IsLoopback, etc) did not work as 
expected for
IPv4-mapped IPv6 addresses, returning false for addresses which would 
return
true in their traditional IPv4 forms.

Thanks to Enze Wang of Alioth (@zer0yu) and Jianjun Chen of 
Zhongguancun Lab
(@chenjj) for reporting this issue.

This is CVE-2024-24790 and Go issue https://go.dev/issue/67680.

View the release notes for more information:
https://go.dev/doc/devel/release#go1.22.4

You can download binary and source distributions from the Go website:
https://go.dev/dl/

To compile from source using a Git clone, update to the release with
git checkout go1.22.4 and build as usual.

Thanks to everyone who contributed to the releases.

Cheers,
Michael and Matthew for the Go team

-- 
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/Gr_I2bQNTludBurV4zYDXQ%40geopod-ismtpd-3.


Re: [go-nuts] Does I/O in Goroutine blocks the underlying thread?

2024-06-03 Thread Ian Lance Taylor
On Mon, Jun 3, 2024 at 1:09 AM Haoyang Fan  wrote:
>
> Let's say if I'm writing a program in Golang that is similar to the "top" 
> command, which rapidly reads the files under /proc directory (e.g. every 1 
> second) and I'm launching goroutines to read different parts of that 
> directory. Since /proc is a virtual filesystem not actually stored on the 
> disk, can I assume in this case there won't be any thread blocked?

Technically the threads will block briefly as they read from the /proc
file system.  However, I would expect that the time they spend blocked
would be very short, imperceptible to a 1 second loop.

Ian


> On Friday, May 31, 2024 at 12:34:38 PM UTC-7 Ian Lance Taylor wrote:
>>
>> On Fri, May 31, 2024 at 12:09 PM Haoyang Fan  wrote:
>> >
>> > I was always under the impression that Go solely uses async I/O under the 
>> > hood so that when invoking a seemingly blocking call like os.File.Read the 
>> > underlying thread won't be blocked. Go scheduler will save the context of 
>> > current goroutine and schedule other goroutines to run on that thread. 
>> > This understanding seems to be aligned with most material I can find on 
>> > the internet.
>>
>> That is how it works for most operations. That said, since you
>> specifically mentioned os.File.Read, if the os.File is a disk file,
>> then on most Unix systems the goroutine and the underlying thread will
>> indeed block for the duration of the I/O. That is because most Unix
>> systems have no mechanism for non-blocking I/O for disk files, so the
>> I/O does block the underlying thread. The underlying thread will not
>> block for I/O on a network connection or a pipe. As a practical
>> matter this is only relevant when using a networked file system, as
>> local file systems are fast.
>>
>> > However, recently when I was reading the slides 
>> > (https://go.dev/talks/2012/waza.slide#32), on slide 32 I notice it says 
>> > "When a goroutine blocks, that thread blocks but no other goroutine 
>> > blocks". This is contradictory and make me wonder does Go really perform 
>> > I/O in an asynchronous manner (e.g. like select/poll/epoll in Linux) under 
>> > the hood?
>> >
>> > Can somebody please clarify?
>>
>> That talk is from 2012. The network poller and scheduler have been
>> rewritten since then.
>>
>> 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/4e467662-c516-4956-aa76-06f3b244c656n%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/CAOyqgcWcv0ZTaOD7aDA31WD10bvPpvxDvEkE%2BSHtb30mCLc%3DYQ%40mail.gmail.com.


Re: [go-nuts] Changing Epoll mode for Golang runtime

2024-06-03 Thread Ian Lance Taylor
On Mon, Jun 3, 2024 at 12:42 PM armin afsharian  wrote:
>
> For my research project, I'm trying to change the Go runtime to use 
> "Epolloneshot" instead of the default "Edge-Triggered" mode. Based on what 
> I've gathered from the code, I've changed two functions in 
> src/runtime/netpoll_epoll.go.
>
> First, I updated the netpollopen function to use the Epolloneshot flag 
> instead of the Epollet flag. Second, I modified the netpollarm function, 
> which isn't used in Linux, to rearm notifications for Epolloneshot. I also 
> tweaked poll_runtime_pollWait() in src/runtime/netpoll.go to call netpollarm 
> for Linux.
>
> Now, I'm running into an issue where HTTP tests for compiling Go are failing. 
> Here's the error I'm seeing:
>
> "httptest.Server blocked in Close after 5 seconds, waiting for connections:
>
> *net.TCPConn 0xc000221520 127.0.0.1:51836 in state active
>
> panic: test timed out after 9m0s"
>
> I suspect that the rearming might be incorrect, causing the server to stall 
> indefinitely.
>
> Just so you know, I'm using Ubuntu 22.04 and Go 1.18.10.

I don't know what the problem is.

That said, look at how netpoll_solaris.go calls netpollupdate from netpoll.

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


[go-nuts] Re: HTTP method before the endpoint

2024-06-03 Thread rogerjd
If it helps someone else, :
The problem was it was using go version 1.20
Needed to change go.mod to use
go 1.22.3


On Monday, June 3, 2024 at 1:20:20 PM UTC-4 rogerjd wrote:

> Your code works both in the playground and on my local machine.
> I need to figure what I did wrong originally.
> Thank you for helping,
> Roger
>
> On Monday, June 3, 2024 at 3:26:22 AM UTC-4 p...@morth.org wrote:
>
>> Hi,
>>
>> It works on the playground at least, https://go.dev/play/p/YZbgmezjSIV
>> Are you sure your server is listening on port 80? That's fairly uncommon 
>> for service code and usually requires extra permissions.
>> If it's listening on another port, you'll have to specify that in the 
>> browser as well (see line 27 in the link above).
>>
>> Regards,
>> Per Johansson
>>
>> On Sunday, June 2, 2024 at 11:26:36 PM UTC+2 rogerjd wrote:
>>
>>> Routing Enhancements for Go 1.22
>>>
>>> I have this in the init func for main 
>>> http.HandleFunc("GET /posts", handlePost2)
>>>
>>> Yet, in the browser, when http://127.0.0.1/posts is entered, it returns
>>> 404 page not found.
>>>
>>> Am I doing something wrong? Maybe the problem lies elsewhere?
>>> Thank you,
>>> Roger
>>>
>>> func handlePost2(w http.ResponseWriter, r *http.Request) {
>>> fmt.Fprint(w, "GET test handlePost2")
>>> }
>>>
>>

-- 
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/afed0533-0e52-4138-a848-ef4deb8af422n%40googlegroups.com.


[go-nuts] Changing Epoll mode for Golang runtime

2024-06-03 Thread armin afsharian


Hi there,

For my research project, I'm trying to change the Go runtime to use 
"Epolloneshot" instead of the default "Edge-Triggered" mode. Based on what 
I've gathered from the code, I've changed two functions in 
src/runtime/netpoll_epoll.go.

First, I updated the netpollopen function to use the Epolloneshot flag 
instead of the Epollet flag. Second, I modified the netpollarm function, 
which isn't used in Linux, to rearm notifications for Epolloneshot. I also 
tweaked poll_runtime_pollWait() in src/runtime/netpoll.go to call 
netpollarm for Linux.

Now, I'm running into an issue where HTTP tests for compiling Go are 
failing. Here's the error I'm seeing:

"httptest.Server blocked in Close after 5 seconds, waiting for connections:

*net.TCPConn 0xc000221520 127.0.0.1:51836 in state active

panic: test timed out after 9m0s"

I suspect that the rearming might be incorrect, causing the server to stall 
indefinitely.

Just so you know, I'm using Ubuntu 22.04 and Go 1.18.10.

-- 
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/7a69745d-60c4-4c45-ae4b-9ae6a35ee7ebn%40googlegroups.com.


[go-nuts] Re: HTTP method before the endpoint

2024-06-03 Thread rogerjd
Your code works both in the playground and on my local machine.
I need to figure what I did wrong originally.
Thank you for helping,
Roger

On Monday, June 3, 2024 at 3:26:22 AM UTC-4 p...@morth.org wrote:

> Hi,
>
> It works on the playground at least, https://go.dev/play/p/YZbgmezjSIV
> Are you sure your server is listening on port 80? That's fairly uncommon 
> for service code and usually requires extra permissions.
> If it's listening on another port, you'll have to specify that in the 
> browser as well (see line 27 in the link above).
>
> Regards,
> Per Johansson
>
> On Sunday, June 2, 2024 at 11:26:36 PM UTC+2 rogerjd wrote:
>
>> Routing Enhancements for Go 1.22
>>
>> I have this in the init func for main 
>> http.HandleFunc("GET /posts", handlePost2)
>>
>> Yet, in the browser, when http://127.0.0.1/posts is entered, it returns
>> 404 page not found.
>>
>> Am I doing something wrong? Maybe the problem lies elsewhere?
>> Thank you,
>> Roger
>>
>> func handlePost2(w http.ResponseWriter, r *http.Request) {
>> fmt.Fprint(w, "GET test handlePost2")
>> }
>>
>

-- 
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/41cf9938-a069-4378-ab23-b30c26dcd93cn%40googlegroups.com.


Re: [go-nuts] Does I/O in Goroutine blocks the underlying thread?

2024-06-03 Thread Haoyang Fan
Let's say if I'm writing a program in Golang that is similar to the "top" 
command, which rapidly reads the files under /proc directory (e.g. every 1 
second) and I'm launching goroutines to read different parts of that 
directory. Since /proc is a virtual filesystem not actually stored on the 
disk, can I assume in this case there won't be any thread blocked?
On Friday, May 31, 2024 at 12:34:38 PM UTC-7 Ian Lance Taylor wrote:

> On Fri, May 31, 2024 at 12:09 PM Haoyang Fan  wrote:
> >
> > I was always under the impression that Go solely uses async I/O under 
> the hood so that when invoking a seemingly blocking call like os.File.Read 
> the underlying thread won't be blocked. Go scheduler will save the context 
> of current goroutine and schedule other goroutines to run on that thread. 
> This understanding seems to be aligned with most material I can find on the 
> internet.
>
> That is how it works for most operations. That said, since you
> specifically mentioned os.File.Read, if the os.File is a disk file,
> then on most Unix systems the goroutine and the underlying thread will
> indeed block for the duration of the I/O. That is because most Unix
> systems have no mechanism for non-blocking I/O for disk files, so the
> I/O does block the underlying thread. The underlying thread will not
> block for I/O on a network connection or a pipe. As a practical
> matter this is only relevant when using a networked file system, as
> local file systems are fast.
>
> > However, recently when I was reading the slides (
> https://go.dev/talks/2012/waza.slide#32), on slide 32 I notice it says 
> "When a goroutine blocks, that thread blocks but no other goroutine 
> blocks". This is contradictory and make me wonder does Go really perform 
> I/O in an asynchronous manner (e.g. like select/poll/epoll in Linux) under 
> the hood?
> >
> > Can somebody please clarify?
>
> That talk is from 2012. The network poller and scheduler have been
> rewritten since then.
>
> 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/4e467662-c516-4956-aa76-06f3b244c656n%40googlegroups.com.


[go-nuts] Re: HTTP method before the endpoint

2024-06-03 Thread p...@morth.org
Hi,

It works on the playground at least, https://go.dev/play/p/YZbgmezjSIV
Are you sure your server is listening on port 80? That's fairly uncommon 
for service code and usually requires extra permissions.
If it's listening on another port, you'll have to specify that in the 
browser as well (see line 27 in the link above).

Regards,
Per Johansson

On Sunday, June 2, 2024 at 11:26:36 PM UTC+2 rogerjd wrote:

> Routing Enhancements for Go 1.22
>
> I have this in the init func for main 
> http.HandleFunc("GET /posts", handlePost2)
>
> Yet, in the browser, when http://127.0.0.1/posts is entered, it returns
> 404 page not found.
>
> Am I doing something wrong? Maybe the problem lies elsewhere?
> Thank you,
> Roger
>
> func handlePost2(w http.ResponseWriter, r *http.Request) {
> fmt.Fprint(w, "GET test handlePost2")
> }
>

-- 
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/79390cb0-bfac-482e-a844-91b7c6326602n%40googlegroups.com.


[go-nuts] HTTP method before the endpoint

2024-06-02 Thread rogerjd
Routing Enhancements for Go 1.22

I have this in the init func for main 
http.HandleFunc("GET /posts", handlePost2)

Yet, in the browser, when http://127.0.0.1/posts is entered, it returns
404 page not found.

Am I doing something wrong? Maybe the problem lies elsewhere?
Thank you,
Roger

func handlePost2(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "GET test handlePost2")
}

-- 
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/3b61f51e-b302-46f8-80f3-45af882f4e37n%40googlegroups.com.


Re: [go-nuts] Does I/O in Goroutine blocks the underlying thread?

2024-05-31 Thread Ian Lance Taylor
On Fri, May 31, 2024 at 12:09 PM Haoyang Fan  wrote:
>
> I was always under the impression that Go solely uses async I/O under the 
> hood so that when invoking a seemingly blocking call like os.File.Read the 
> underlying thread won't be blocked. Go scheduler will save the context of 
> current goroutine and schedule other goroutines to run on that thread. This 
> understanding seems to be aligned with most material I can find on the 
> internet.

That is how it works for most operations.  That said, since you
specifically mentioned os.File.Read, if the os.File is a disk file,
then on most Unix systems the goroutine and the underlying thread will
indeed block for the duration of the I/O.  That is because most Unix
systems have no mechanism for non-blocking I/O for disk files, so the
I/O does block the underlying thread.  The underlying thread will not
block for I/O on a network connection or a pipe.  As a practical
matter this is only relevant when using a networked file system, as
local file systems are fast.

> However, recently when I was reading the slides 
> (https://go.dev/talks/2012/waza.slide#32), on slide 32 I notice it says "When 
> a goroutine blocks, that thread blocks but no other goroutine blocks". This 
> is contradictory and make me wonder does Go really perform I/O in an 
> asynchronous manner (e.g. like select/poll/epoll in Linux) under the hood?
>
> Can somebody please clarify?

That talk is from 2012.  The network poller and scheduler have been
rewritten since then.

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/CAOyqgcVXYzWZZ881Si%2B6YcxVbsdme%3DcomqoiutGyx4o0g5SCBQ%40mail.gmail.com.


Re: [go-nuts] Does I/O in Goroutine blocks the underlying thread?

2024-05-31 Thread robert engels
It does. I think the wording is wrong - the Go routine blocks - but the carrier 
thread (that was running the Go routine) runs another Go routine (if needed and 
ready to run).

> On May 31, 2024, at 2:54 AM, Haoyang Fan  wrote:
> 
> Hi everyone,
> 
> I was always under the impression that Go solely uses async I/O under the 
> hood so that when invoking a seemingly blocking call like os.File.Read the 
> underlying thread won't be blocked. Go scheduler will save the context of 
> current goroutine and schedule other goroutines to run on that thread. This 
> understanding seems to be aligned with most material I can find on the 
> internet.
> 
> However, recently when I was reading the slides 
> (https://go.dev/talks/2012/waza.slide#32), on slide 32 I notice it says "When 
> a goroutine blocks, that thread blocks but no other goroutine blocks". This 
> is contradictory and make me wonder does Go really perform I/O in an 
> asynchronous manner (e.g. like select/poll/epoll in Linux) under the hood?
> 
> Can somebody please clarify?
> 
> 
> -- 
> 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/e1c49031-821c-42af-9449-2c7586c3676fn%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/29CDB318-EC02-4E03-A3D6-3F2498CE3E40%40ix.netcom.com.


[go-nuts] Does I/O in Goroutine blocks the underlying thread?

2024-05-31 Thread Haoyang Fan
Hi everyone,

I was always under the impression that Go solely uses async I/O under the 
hood so that when invoking a seemingly blocking call like os.File.Read the 
underlying thread won't be blocked. Go scheduler will save the context of 
current goroutine and schedule other goroutines to run on that thread. This 
understanding seems to be aligned with most material I can find on the 
internet.

However, recently when I was reading the slides 
(https://go.dev/talks/2012/waza.slide#32), on slide 32 I notice it says "*When 
a goroutine blocks, that thread blocks but no other goroutine blocks*". 
This is contradictory and make me wonder does Go really perform I/O in an 
asynchronous manner (e.g. like select/poll/epoll in Linux) under the hood?

Can somebody please clarify?

-- 
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/e1c49031-821c-42af-9449-2c7586c3676fn%40googlegroups.com.


Re: [go-nuts] multiple rangefunc iterators: restart?

2024-05-31 Thread Rory Campbell-Lange
On 31/05/24, Rory Campbell-Lange (r...@campbell-lange.net) wrote:
> On 23/05/24, Rory Campbell-Lange (r...@campbell-lange.net) wrote:
> > I've been playing with with rangefunc experiment...
> 
> ...reference to python nested yield example...
> 
> > for p in people:
> > for c in p.cars:
> > for t in c.tickets:
> > print("person {} in car {} got ticket {}", p, c, t)
> > 
> 
> > [My attempt to recreate in go at]  
> > https://go.dev/play/p/gFUcKNSrbMV?v=gotip ... only has an iterator on the 
> > left hand side and series of nested structs through slices...
> 
> For info, in my attempt to use nested iter.Seq structures I (obviously) 
> didn't need a restart, but simply yielded the left-most struct and used the 
> iterators in each nested struct as required.

Apologies -- the code I meant to share for an example of nested iter.Seq 
structs is here: https://go.dev/play/p/8QZmybr_nOB?v=gotip

-- 
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/Zlnkv87IZO3q-pYk%40campbell-lange.net.


Re: [go-nuts] multiple rangefunc iterators: restart?

2024-05-31 Thread Rory Campbell-Lange
On 23/05/24, Rory Campbell-Lange (r...@campbell-lange.net) wrote:
> I've been playing with with rangefunc experiment...

...reference to python nested yield example...

> for p in people:
> for c in p.cars:
> for t in c.tickets:
> print("person {} in car {} got ticket {}", p, c, t)
> 

> [My attempt to recreate in go at]  https://go.dev/play/p/gFUcKNSrbMV?v=gotip 
> ... only has an iterator on the left hand side and series of nested structs 
> through slices...

For info, in my attempt to use nested iter.Seq structures I (obviously) didn't 
need a restart, but simply yielded the left-most struct and used the iterators 
in each nested struct as required. I've got this sort of working as shown below 
-- sorry if my plain text email formatting gets lost in translation.

type obj[T comparable, U any] struct {
this  T
those []U
}

func (o *obj[T, U]) Add(u U) {
o.those = append(o.those, u)
}

func (o *obj[T, U]) Eq(n T) bool {
return o.this == n
}

// Iter could take args for customization
func (o *obj[T, U]) Iter() iter.Seq[U] {
if debug {
fmt.Printf("calling Iter() on %T\n", o.those)
}
return func(yield func(U) bool) {
for _, v := range o.those {
if !yield(v) {
return
}
}
}
}

It's painful to work with so probably not worth the effort. See:
https://go.dev/play/p/PpKpAIz7u6J?v=gotip

Example output from

a1 a1a a1b 1.1 1.2 1.3 n1 n1a n1b
a1 a1a a1b 1.1 1.2 1.3 n2 n2a n2b
a1 a1a a1b 1.1 1.2 1.3 n3 n3a n3b
a1 a1a a1b 2.1 2.2 2.3 n4 n4a n4b
a2 a2a a2b 3.1 3.2 3.3 n5 n5a n6b
a2 a2a a2b 3.1 3.2 3.3 n6 n5a n6b

is as follows:

{a1 a1a a1b}
calling Iter() on []main.obj[main.b,main.c]
>  {1.1 1.2 1.3}
calling Iter() on []main.c
> >  {n1 n1a n1b}
>  {1.1 1.2 1.3}
calling Iter() on []main.c
> >  {n1 n1a n1b}
> >  {n2 n2a n2b}
>  {1.1 1.2 1.3}
calling Iter() on []main.c
> >  {n1 n1a n1b}
> >  {n2 n2a n2b}
> >  {n3 n3a n3b}
>  {2.1 2.2 2.3}
calling Iter() on []main.c
> >  {n4 n4a n4b}
{a2 a2a a2b}
calling Iter() on []main.obj[main.b,main.c]
>  {3.1 3.2 3.3}
calling Iter() on []main.c
> >  {n5 n5a n6b}
>  {3.1 3.2 3.3}
calling Iter() on []main.c
> >  {n5 n5a n6b}
> >  {n6 n5a n6b}

-- 
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/ZlnaPio5zk6qEUD_%40campbell-lange.net.


Re: [go-nuts] Symbol of const string are not exported by compiler

2024-05-31 Thread Benoît Marguerie
Just for information, I've written an issue on go compiler to follow this 
evolution: https://github.com/golang/go/issues/67744 

Le vendredi 31 mai 2024 à 10:15:02 UTC+2, Benoît Marguerie a écrit :

> Good question !
>
> But delve mainly extracts its symbols from Dwarf info. And when I try to 
> get them with your code, I obtain this:
>
> *~/tmp$ objdump -W main | grep -i constV<2547>   DW_AT_name: 
> main.constValueInt*
>
> We can see that the compiler puts some debug tags for const int values but 
> not for the others.
>
> From here, I've searched into Go SDK for dwarf information and I found in 
> the compiler sources this (file src/cmd/compile/internal/gc/obj.go:163-189 
> func dumpGlobalConst):
> // only export integer constants for now
> if !t.IsInteger() {
> return
> }
>
> *So, for the moment, it seems to be a deliberate limitation of Go 
> compiler.*
>
> Many thanks for your help @Jan and @Kurtis !
> Benoît
>
> NB: just for information, I'm working with Go 1.22.3, dlv 1.22.1 , objdump 
> 2.38)
>
> Le vendredi 31 mai 2024 à 07:30:52 UTC+2, Kurtis Rader a écrit :
>
>> Your question should have included more information such as the Go 
>> version. Nonetheless, I don't see how Delve is able to resolve "myValueInt" 
>> in your example. I modified your code to include non-const versions of the 
>> symbols:
>>
>> package main
>>
>>
>> import "fmt"
>>
>>
>> const constValueStr = "abc"
>> const constValueInt = 12
>> const constValueFloat = 1.2
>>
>>
>> var varValueStr = "def"
>> var varValueInt = 13
>>
>>
>> func main() {
>> fmt.Println(constValueStr, constValueInt, constValueFloat, 
>> varValueStr, varValueInt)
>> }
>>
>>
>> I put that code in a file named "x.go" and compiled it with "go build 
>> x.go". The "strings" command shows both "varValue" symbols but neither 
>> "constValue" symbols:
>>
>> elvish> strings - x | grep varValue
>> _main.varValueInt
>> _main.varValueStr
>> elvish> strings - x | grep constValue
>> Exception: grep exited with 1
>>   [tty 156]:1:15-29: strings - x | grep constValue
>>
>>
>> Delve is able to resolve three of the five symbols:
>>
>> elvish> dlv exec x
>> Type 'help' for list of commands.
>> (dlv) print main.varValueInt
>> 13
>> (dlv) print main.constValueInt
>> 12
>> (dlv) print main.constValueFloat
>> Command failed: could not find symbol value for main
>> (dlv) print main.varValueStr
>> (unreadable could not read string at 0x100086f47 due to protocol error 
>> E08 during memory read for packet $m100086f47,3)
>> (dlv) print main.constValueStr
>> Command failed: could not find symbol value for main
>>
>>
>> It is not obvious how Delve is able to resolve "main.constValueInt" since 
>> that string does not appear in the binary according to the "strings - x" 
>> command. So I think the more interesting question is how Delve is able to 
>> resolve the "main.constValueInt" symbol but not the two other const symbols.
>>
>>
>> On Thu, May 30, 2024 at 1:58 AM Benoît Marguerie  
>> wrote:
>>
>>> or, in a easier way, a full "copy/paste" example of code:
>>>
>>> package main
>>>
>>> import "fmt"
>>>
>>> const myValueStr = "try"
>>> const myValueInt = 12
>>>
>>> func main() {
>>> fmt.Println("Instruction only to put a breakpoint")
>>> }
>>>
>>>
>>> Le jeudi 30 mai 2024 à 10:53:50 UTC+2, Benoît Marguerie a écrit :
>>>
 Of course!
 The code can be really simple like this:


 *const myValueStr = "try"const myValueInt = 12*



 *func DoSomething() {   fmt.Println("Instruction only to put a 
 breakpoint")}*


 and the result with delve:





 *(dlv) print %v myValueInt12(dlv) print %v myValueStrCommand failed: 
 could not find symbol value for myValueStr*

 Benoit

>>> -- 
>>> 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/c938f107-9bca-4b8e-a10c-f8deef396c87n%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/e240b3c6-84f1-4160-90e6-8a3698e83dc4n%40googlegroups.com.


Re: [go-nuts] Symbol of const string are not exported by compiler

2024-05-31 Thread Benoît Marguerie
Good question !

But delve mainly extracts its symbols from Dwarf info. And when I try to 
get them with your code, I obtain this:

*~/tmp$ objdump -W main | grep -i constV<2547>   DW_AT_name: 
main.constValueInt*

We can see that the compiler puts some debug tags for const int values but 
not for the others.

>From here, I've searched into Go SDK for dwarf information and I found in 
the compiler sources this (file src/cmd/compile/internal/gc/obj.go:163-189 
func dumpGlobalConst):
// only export integer constants for now
if !t.IsInteger() {
return
}

*So, for the moment, it seems to be a deliberate limitation of Go compiler.*

Many thanks for your help @Jan and @Kurtis !
Benoît

NB: just for information, I'm working with Go 1.22.3, dlv 1.22.1 , objdump 
2.38)

Le vendredi 31 mai 2024 à 07:30:52 UTC+2, Kurtis Rader a écrit :

> Your question should have included more information such as the Go 
> version. Nonetheless, I don't see how Delve is able to resolve "myValueInt" 
> in your example. I modified your code to include non-const versions of the 
> symbols:
>
> package main
>
>
> import "fmt"
>
>
> const constValueStr = "abc"
> const constValueInt = 12
> const constValueFloat = 1.2
>
>
> var varValueStr = "def"
> var varValueInt = 13
>
>
> func main() {
> fmt.Println(constValueStr, constValueInt, constValueFloat, 
> varValueStr, varValueInt)
> }
>
>
> I put that code in a file named "x.go" and compiled it with "go build 
> x.go". The "strings" command shows both "varValue" symbols but neither 
> "constValue" symbols:
>
> elvish> strings - x | grep varValue
> _main.varValueInt
> _main.varValueStr
> elvish> strings - x | grep constValue
> Exception: grep exited with 1
>   [tty 156]:1:15-29: strings - x | grep constValue
>
>
> Delve is able to resolve three of the five symbols:
>
> elvish> dlv exec x
> Type 'help' for list of commands.
> (dlv) print main.varValueInt
> 13
> (dlv) print main.constValueInt
> 12
> (dlv) print main.constValueFloat
> Command failed: could not find symbol value for main
> (dlv) print main.varValueStr
> (unreadable could not read string at 0x100086f47 due to protocol error E08 
> during memory read for packet $m100086f47,3)
> (dlv) print main.constValueStr
> Command failed: could not find symbol value for main
>
>
> It is not obvious how Delve is able to resolve "main.constValueInt" since 
> that string does not appear in the binary according to the "strings - x" 
> command. So I think the more interesting question is how Delve is able to 
> resolve the "main.constValueInt" symbol but not the two other const symbols.
>
>
> On Thu, May 30, 2024 at 1:58 AM Benoît Marguerie  
> wrote:
>
>> or, in a easier way, a full "copy/paste" example of code:
>>
>> package main
>>
>> import "fmt"
>>
>> const myValueStr = "try"
>> const myValueInt = 12
>>
>> func main() {
>> fmt.Println("Instruction only to put a breakpoint")
>> }
>>
>>
>> Le jeudi 30 mai 2024 à 10:53:50 UTC+2, Benoît Marguerie a écrit :
>>
>>> Of course!
>>> The code can be really simple like this:
>>>
>>>
>>> *const myValueStr = "try"const myValueInt = 12*
>>>
>>>
>>>
>>> *func DoSomething() {   fmt.Println("Instruction only to put a 
>>> breakpoint")}*
>>>
>>>
>>> and the result with delve:
>>>
>>>
>>>
>>>
>>>
>>> *(dlv) print %v myValueInt12(dlv) print %v myValueStrCommand failed: 
>>> could not find symbol value for myValueStr*
>>>
>>> Benoit
>>>
>> -- 
>> 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/c938f107-9bca-4b8e-a10c-f8deef396c87n%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/7df5f762-815f-4e16-aa2b-80a09b9b948an%40googlegroups.com.


Re: [go-nuts] Symbol of const string are not exported by compiler

2024-05-30 Thread Kurtis Rader
Your question should have included more information such as the Go version.
Nonetheless, I don't see how Delve is able to resolve "myValueInt" in your
example. I modified your code to include non-const versions of the symbols:

package main


import "fmt"


const constValueStr = "abc"
const constValueInt = 12
const constValueFloat = 1.2


var varValueStr = "def"
var varValueInt = 13


func main() {
fmt.Println(constValueStr, constValueInt, constValueFloat,
varValueStr, varValueInt)
}


I put that code in a file named "x.go" and compiled it with "go build
x.go". The "strings" command shows both "varValue" symbols but neither
"constValue" symbols:

elvish> strings - x | grep varValue
_main.varValueInt
_main.varValueStr
elvish> strings - x | grep constValue
Exception: grep exited with 1
  [tty 156]:1:15-29: strings - x | grep constValue


Delve is able to resolve three of the five symbols:

elvish> dlv exec x
Type 'help' for list of commands.
(dlv) print main.varValueInt
13
(dlv) print main.constValueInt
12
(dlv) print main.constValueFloat
Command failed: could not find symbol value for main
(dlv) print main.varValueStr
(unreadable could not read string at 0x100086f47 due to protocol error E08
during memory read for packet $m100086f47,3)
(dlv) print main.constValueStr
Command failed: could not find symbol value for main


It is not obvious how Delve is able to resolve "main.constValueInt" since
that string does not appear in the binary according to the "strings - x"
command. So I think the more interesting question is how Delve is able to
resolve the "main.constValueInt" symbol but not the two other const symbols.


On Thu, May 30, 2024 at 1:58 AM Benoît Marguerie  wrote:

> or, in a easier way, a full "copy/paste" example of code:
>
> package main
>
> import "fmt"
>
> const myValueStr = "try"
> const myValueInt = 12
>
> func main() {
> fmt.Println("Instruction only to put a breakpoint")
> }
>
>
> Le jeudi 30 mai 2024 à 10:53:50 UTC+2, Benoît Marguerie a écrit :
>
>> Of course!
>> The code can be really simple like this:
>>
>>
>> *const myValueStr = "try"const myValueInt = 12*
>>
>>
>>
>> *func DoSomething() {   fmt.Println("Instruction only to put a
>> breakpoint")}*
>>
>>
>> and the result with delve:
>>
>>
>>
>>
>>
>> *(dlv) print %v myValueInt12(dlv) print %v myValueStrCommand failed:
>> could not find symbol value for myValueStr*
>>
>> Benoit
>>
> --
> 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/c938f107-9bca-4b8e-a10c-f8deef396c87n%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/CABx2%3DD--TKEdowrJdOFT%3Dgz5gTPZPWyyf42pHwkb8Jv0GxNDXg%40mail.gmail.com.


[go-nuts] [security] Go 1.22.4 and Go 1.21.11 pre-announcement

2024-05-30 Thread announce
Hello gophers,

We plan to issue Go 1.22.4 and Go 1.21.11 during US business hours on Tuesday, 
June 4.

These minor releases include PRIVATE security fixes to the standard library, 
covering the following CVE:

-   CVE-2024-24790

Following our security policy, this is the pre-announcement of those releases.

Thanks,
Matthew and Carlos for the Go team

-- 
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/hro34FA2QbSJZ-wwA7vkTQ%40geopod-ismtpd-25.


Re: [go-nuts] Memory operations hung in semacquire state, GC routine parked while holding semaphore?

2024-05-30 Thread 'Alex Kristiansen' via golang-nuts
Thanks for the response Michael.

> It looks like a Windows minidump (unsurprisingly) can't follow the 
relation. A regular goroutine stack trace dump that gets emitted on a 
forced exit or crash is able to show both sides of the system stack switch 
with a little bit of configuration.

Yeah, that was my understanding too. Again, not a windows expert, but my 
understanding is that there's no equivalent to the "send SIGABRT to get a 
stack dump" trick on windows? 

I didn't file a bug initially, as this version appears to be more than two 
minor releases behind, and I also wasn't completely sure if it was a bug or 
some weird AV/VM behavior. 

The entire stack trace is pretty huge, so I put it here: 
https://gist.github.com/fearful-symmetry/1e6546640f667731b3fe2a90f96b5680
On Wednesday, May 29, 2024 at 9:26:50 PM UTC-7 Michael Knyszek wrote:

> The example goroutine in the original post is parked waiting for some 
> other goroutine to finish up the GC cycle. Somewhere, a goroutine is 
> getting stuck trying to finish it up, which could possibly be a deadlock. 
> (I am especially suspicious of a deadlock bug because most threads are 
> stopped there.) It would be good to confirm whether application CPU time 
> drops to zero or plateaus to some very consistent number, which would 
> support the deadlock theory.
>
> On Wednesday, May 29, 2024 at 11:09:30 AM UTC-4 robert engels wrote:
>
> I am pretty sure runtime is supposed to crash the process if it slows the 
> allocators “too much” (I believe there are some config settings to control 
> this).
>
> The runtime never intentionally crashes a process due to rate or volume of 
> allocation. There is an optional memory limit, but it's soft in that the 
> runtime gives up trying to maintain the limit at some point; see below and 
> see https://go.dev/doc/gc-guide.
>
>
> If you have enough Go routines it may look like they are hung - you need 
> to track specific routines by their ID. The stack certainly looks like it 
> is trying to allocate memory for a slice - and it is being paused - because 
> it is waiting on the GC lock.
>
> Are you doing any native code? You could have heap corruption and that is 
> also why the GC thread is getting hung.
>
> If the GC thread makes progress albeit slowly - I would settle on my first 
> guess - memory leak...
>
> I suspect a memory leak is not at play here. In the case of a memory leak, 
> by default, your live heap may steadily increase, and the time between GC 
> cycles increases proportionally. The GC is designed such that the overall 
> impact should stay roughly constant as your heap grows by default. In this 
> case, memory leak should appear exactly as expected: a rise in memory use 
> over time.
>
> If GOMEMLIMIT is in use (which is non-default; you have to ask for it), 
> then a memory leak may result in progressively more frequent GC cycles. 
> However, the worst-case failure to make progress ("GC death spiral") should 
> be prevented in practice by the runtime already. It puts a hard limit on 
> the amount of CPU time that can be taken by the GC every CPU-second, 
> instead letting memory use increase. Don't get me wrong, it can still slow 
> down the application a good bit, and maybe under some circumstances it'll 
> still look like a hang. It is also possible there's a bug in the GC CPU 
> limiter or something.
>
> But, from what I've seen so far in this bug, I'm more convinced of a 
> deadlock bug than the application failing to make progress. Lots of 
> goroutines lining up on gcMarkDone just sounds too specific to me.
>
>
> On May 29, 2024, at 10:00 AM, 'Alex Kristiansen' via golang-nuts <
> golan...@googlegroups.com> wrote:
>
> That's an interesting idea, I probably wouldn't have thought of that on my 
> own. Is that expected behavior for memory pressure on Windows+golang? I 
> don't have much windows experience, so my assumption would be that the 
> Windows equivalent of the OOMKiller would kick in and just kill the 
> application. 
>
> On Tuesday, May 28, 2024 at 4:04:15 PM UTC-7 robert engels wrote:
>
> Feels like a memory leak to me. I would look for growing heap size in the 
> gc logs. I am guessing that the system is not completely hung - but rather 
> the runtime is having a hard time obtaining more memory, so it is slowing 
> the allocators to a rate that makes them appear hung.
>
> It may be that the process has consumed nearly all of the OS memory too - 
> so the OS is having a hard-time responding to malloc requests.
>
> i.e. The system is not making progress.
>
> On May 28, 2024, at 3:54 PM, 'Alex Kristiansen' via golang-nuts <
> golan...@googlegroups.com> wrote:
>
> This is an odd one. For reference, this is a customer machine, Windows 
> server 2016, compiled with go1.20.11. The application just hangs after a 
> number of days; windows minidump reveals that most threads are doing this:
>
>   Goroutine 462 - User: unicode/utf16/utf16.go:106 unicode/utf16.Decode 
> (0xe6e391) [semacquire]
>  

Re: [go-nuts] Symbol of const string are not exported by compiler

2024-05-30 Thread Benoît Marguerie
or, in a easier way, a full "copy/paste" example of code:

package main

import "fmt"

const myValueStr = "try"
const myValueInt = 12

func main() {
fmt.Println("Instruction only to put a breakpoint")
}


Le jeudi 30 mai 2024 à 10:53:50 UTC+2, Benoît Marguerie a écrit :

> Of course!
> The code can be really simple like this:
>
>
> *const myValueStr = "try"const myValueInt = 12*
>
>
>
> *func DoSomething() {   fmt.Println("Instruction only to put a 
> breakpoint")}*
>
>
> and the result with delve:
>
>
>
>
>
> *(dlv) print %v myValueInt12(dlv) print %v myValueStrCommand failed: could 
> not find symbol value for myValueStr*
>
> Benoit
>

-- 
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/c938f107-9bca-4b8e-a10c-f8deef396c87n%40googlegroups.com.


Re: [go-nuts] Symbol of const string are not exported by compiler

2024-05-30 Thread Benoît Marguerie


Of course!
The code can be really simple like this:


*const myValueStr = "try"const myValueInt = 12*



*func DoSomething() {   fmt.Println("Instruction only to put a 
breakpoint")}*


and the result with delve:





*(dlv) print %v myValueInt12(dlv) print %v myValueStrCommand failed: could 
not find symbol value for myValueStr*

Benoit

-- 
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/89042acf-1a57-467e-8df4-f33fbd71415en%40googlegroups.com.


Re: [go-nuts] Symbol of const string are not exported by compiler

2024-05-30 Thread Jan Mercl
On Thu, May 30, 2024 at 10:34 AM Benoît Marguerie  wrote:

> I discovered a "strange" behavior doing a simple operation.
> I defined 2 const : one integer and one string. With delve (or other 
> debugger), I'm able to consult the const integer value but not the const 
> string value. Delve team explained me that the go compiler doesn't export 
> symbol of const string.
>
> Sorry for the newbee's question but is there anybody knowing why the symbol 
> can be exported for an integer but not for a string ?

Please include a code example that you're investigating using delve.
I, for one, cannot infer enough information from your post to be sure
what exactly is the problem and hence if the observed is - or is not -
an expected outcome.

-- 
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/CAA40n-V0CAVBGHo-E1DgyA2cJaX8QjKRYNCgcGNu%2BkNL0Cg%3D0w%40mail.gmail.com.


[go-nuts] Symbol of const string are not exported by compiler

2024-05-30 Thread Benoît Marguerie
Hello All,

I discovered a "strange" behavior doing a simple operation. 
I defined 2 const : one integer and one string. With delve (or other 
debugger), I'm able to consult the const integer value but not the const 
string value. Delve team explained me that the go compiler doesn't export 
symbol of const string.

Sorry for the newbee's question but is there anybody knowing why the symbol 
can be exported for an integer but not for a string ?

BR,
Benoît

-- 
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/31d16661-566b-445f-a592-01c09dee0c05n%40googlegroups.com.


Re: [go-nuts] Memory operations hung in semacquire state, GC routine parked while holding semaphore?

2024-05-29 Thread 'Michael Knyszek' via golang-nuts
The example goroutine in the original post is parked waiting for some other 
goroutine to finish up the GC cycle. Somewhere, a goroutine is getting 
stuck trying to finish it up, which could possibly be a deadlock. (I am 
especially suspicious of a deadlock bug because most threads are stopped 
there.) It would be good to confirm whether application CPU time drops to 
zero or plateaus to some very consistent number, which would support the 
deadlock theory.

On Wednesday, May 29, 2024 at 11:09:30 AM UTC-4 robert engels wrote:

I am pretty sure runtime is supposed to crash the process if it slows the 
allocators “too much” (I believe there are some config settings to control 
this).

The runtime never intentionally crashes a process due to rate or volume of 
allocation. There is an optional memory limit, but it's soft in that the 
runtime gives up trying to maintain the limit at some point; see below and 
see https://go.dev/doc/gc-guide.


If you have enough Go routines it may look like they are hung - you need to 
track specific routines by their ID. The stack certainly looks like it is 
trying to allocate memory for a slice - and it is being paused - because it 
is waiting on the GC lock.

Are you doing any native code? You could have heap corruption and that is 
also why the GC thread is getting hung.

If the GC thread makes progress albeit slowly - I would settle on my first 
guess - memory leak...

I suspect a memory leak is not at play here. In the case of a memory leak, 
by default, your live heap may steadily increase, and the time between GC 
cycles increases proportionally. The GC is designed such that the overall 
impact should stay roughly constant as your heap grows by default. In this 
case, memory leak should appear exactly as expected: a rise in memory use 
over time.

If GOMEMLIMIT is in use (which is non-default; you have to ask for it), 
then a memory leak may result in progressively more frequent GC cycles. 
However, the worst-case failure to make progress ("GC death spiral") should 
be prevented in practice by the runtime already. It puts a hard limit on 
the amount of CPU time that can be taken by the GC every CPU-second, 
instead letting memory use increase. Don't get me wrong, it can still slow 
down the application a good bit, and maybe under some circumstances it'll 
still look like a hang. It is also possible there's a bug in the GC CPU 
limiter or something.

But, from what I've seen so far in this bug, I'm more convinced of a 
deadlock bug than the application failing to make progress. Lots of 
goroutines lining up on gcMarkDone just sounds too specific to me.


On May 29, 2024, at 10:00 AM, 'Alex Kristiansen' via golang-nuts <
golan...@googlegroups.com> wrote:

That's an interesting idea, I probably wouldn't have thought of that on my 
own. Is that expected behavior for memory pressure on Windows+golang? I 
don't have much windows experience, so my assumption would be that the 
Windows equivalent of the OOMKiller would kick in and just kill the 
application. 

On Tuesday, May 28, 2024 at 4:04:15 PM UTC-7 robert engels wrote:

Feels like a memory leak to me. I would look for growing heap size in the 
gc logs. I am guessing that the system is not completely hung - but rather 
the runtime is having a hard time obtaining more memory, so it is slowing 
the allocators to a rate that makes them appear hung.

It may be that the process has consumed nearly all of the OS memory too - 
so the OS is having a hard-time responding to malloc requests.

i.e. The system is not making progress.

On May 28, 2024, at 3:54 PM, 'Alex Kristiansen' via golang-nuts <
golan...@googlegroups.com> wrote:

This is an odd one. For reference, this is a customer machine, Windows 
server 2016, compiled with go1.20.11. The application just hangs after a 
number of days; windows minidump reveals that most threads are doing this:

  Goroutine 462 - User: unicode/utf16/utf16.go:106 unicode/utf16.Decode 
(0xe6e391) [semacquire]
 0  0x00e2d116 in runtime.gopark
 at runtime/proc.go:382
 1  0x00e3df5c in runtime.goparkunlock
 at runtime/proc.go:387
 2  0x00e3df5c in runtime.semacquire1
 at runtime/sema.go:160
 3  0x00e0ac2f in runtime.semacquire
 at runtime/sema.go:111
 4  0x00e0ac2f in runtime.gcMarkDone
 at runtime/mgc.go:787
 5  0x00128c10 in ???
 at ?:-1
 6  0x00dfe7da in runtime.deductAssistCredit
 at runtime/malloc.go:1217
 7  0x00dfdff0 in runtime.mallocgc
 at runtime/malloc.go:932
 8  0x00e3f972 in runtime.makeslice
 at runtime/slice.go:103
 9  0x00e6e391 in unicode/utf16.Decode
 at unicode/utf16/utf16.go:106
10  0x00e72a7b in syscall.UTF16ToString
 at syscall/syscall_windows.go:63
11  

Re: [go-nuts] Memory operations hung in semacquire state, GC routine parked while holding semaphore?

2024-05-29 Thread robert engels
I am pretty sure runtime is supposed to crash the process if it slows the 
allocators “too much” (I believe there are some config settings to control 
this).

If you have enough Go routines it may look like they are hung - you need to 
track specific routines by their ID. The stack certainly looks like it is 
trying to allocate memory for a slice - and it is being paused - because it is 
waiting on the GC lock.

Are you doing any native code? You could have heap corruption and that is also 
why the GC thread is getting hung.

If the GC thread makes progress albeit slowly - I would settle on my first 
guess - memory leak...

> On May 29, 2024, at 10:00 AM, 'Alex Kristiansen' via golang-nuts 
>  wrote:
> 
> That's an interesting idea, I probably wouldn't have thought of that on my 
> own. Is that expected behavior for memory pressure on Windows+golang? I don't 
> have much windows experience, so my assumption would be that the Windows 
> equivalent of the OOMKiller would kick in and just kill the application. 
> 
> On Tuesday, May 28, 2024 at 4:04:15 PM UTC-7 robert engels wrote:
> Feels like a memory leak to me. I would look for growing heap size in the gc 
> logs. I am guessing that the system is not completely hung - but rather the 
> runtime is having a hard time obtaining more memory, so it is slowing the 
> allocators to a rate that makes them appear hung.
> 
> It may be that the process has consumed nearly all of the OS memory too - so 
> the OS is having a hard-time responding to malloc requests.
> 
> i.e. The system is not making progress.
> 
> 
>> On May 28, 2024, at 3:54 PM, 'Alex Kristiansen' via golang-nuts 
>> > > wrote:
>> 
> 
>> This is an odd one. For reference, this is a customer machine, Windows 
>> server 2016, compiled with go1.20.11. The application just hangs after a 
>> number of days; windows minidump reveals that most threads are doing this:
>> 
>>   Goroutine 462 - User: unicode/utf16/utf16.go:106 unicode/utf16.Decode 
>> (0xe6e391) [semacquire]
>>  0  0x00e2d116 in runtime.gopark
>>  at runtime/proc.go:382
>>  1  0x00e3df5c in runtime.goparkunlock
>>  at runtime/proc.go:387
>>  2  0x00e3df5c in runtime.semacquire1
>>  at runtime/sema.go:160
>>  3  0x00e0ac2f in runtime.semacquire
>>  at runtime/sema.go:111
>>  4  0x00e0ac2f in runtime.gcMarkDone
>>  at runtime/mgc.go:787
>>  5  0x00128c10 in ???
>>  at ?:-1
>>  6  0x00dfe7da in runtime.deductAssistCredit
>>  at runtime/malloc.go:1217
>>  7  0x00dfdff0 in runtime.mallocgc
>>  at runtime/malloc.go:932
>>  8  0x00e3f972 in runtime.makeslice
>>  at runtime/slice.go:103
>>  9  0x00e6e391 in unicode/utf16.Decode
>>  at unicode/utf16/utf16.go:106
>> 10  0x00e72a7b in syscall.UTF16ToString
>>  at syscall/syscall_windows.go:63
>> 11  0x00eb7a67 in os.(*File).readdir
>>  at os/dir_windows.go:43
>> 12  0x00eb72c5 in os.(*File).Readdirnames
>>  at os/dir.go:70
>> 13  0x00fb623a in path/filepath.glob
>>  at path/filepath/match.go:346
>> 14  0x00fb5ea5 in path/filepath.globWithLimit
>>  at path/filepath/match.go:273
>> 15  0x031de255 in path/filepath.Glob
>>  at path/filepath/match.go:243
>> 
>> Multiple threads, all waiting on a semaphore inside mallocgc. The actual 
>> reason we're waiting for memory changes, obviously (sometimes a string 
>> method, or hashmap allocation, or logging call...). This behavior has 
>> remained consistent across multiple hangs across a number of weeks. After a 
>> bit of digging into the minidump, this (I think) is the thread that's 
>> holding the semaphore(s), at least based on the line numbers:
>> 
>>   Goroutine 37 - User: :0 ??? (0x7ffb0e056974) (thread 5628)
>> 0  0x7ffb0e056974 in ???
>> at ?:-1
>> 1  0x00e5c5a0 in runtime.systemstack_switch
>> at runtime/asm_amd64.s:463
>> 2  0x00e0ade5 in runtime.gcMarkDone
>> at runtime/mgc.go:855
>> 3  0x00128c10 in ???
>> at ?:-1
>> 4  0x00e5e881 in runtime.goexit
>> at runtime/asm_amd64.s:1598
>> 
>> Note that the precise point in gcMarkDone can change. I have another 
>> minidump showing a hang at a different point in the same method:
>> 
>> Goroutine 19 - Go: :0 ??? (0x208351516f8) (thread 7164) [unknown wait reason 
>> 30] 
>> 0 0x7ffe66e66974 in ??? 
>> at ?:-1 
>> 1 0x00e9c5a0 in runtime.systemstack_switch 
>> at runtime/asm_amd64.s:463 
>> 2 0x00e4acff in runtime.gcMarkDone 
>> at runtime/mgc.go:807 
>> 3 0x00128c10 in ??? 
>> at ?:-1 
>> 4 

Re: [go-nuts] Memory operations hung in semacquire state, GC routine parked while holding semaphore?

2024-05-29 Thread 'Alex Kristiansen' via golang-nuts
That's an interesting idea, I probably wouldn't have thought of that on my 
own. Is that expected behavior for memory pressure on Windows+golang? I 
don't have much windows experience, so my assumption would be that the 
Windows equivalent of the OOMKiller would kick in and just kill the 
application. 

On Tuesday, May 28, 2024 at 4:04:15 PM UTC-7 robert engels wrote:

> Feels like a memory leak to me. I would look for growing heap size in the 
> gc logs. I am guessing that the system is not completely hung - but rather 
> the runtime is having a hard time obtaining more memory, so it is slowing 
> the allocators to a rate that makes them appear hung.
>
> It may be that the process has consumed nearly all of the OS memory too - 
> so the OS is having a hard-time responding to malloc requests.
>
> i.e. The system is not making progress.
>
> On May 28, 2024, at 3:54 PM, 'Alex Kristiansen' via golang-nuts <
> golan...@googlegroups.com> wrote:
>
> This is an odd one. For reference, this is a customer machine, Windows 
> server 2016, compiled with go1.20.11. The application just hangs after a 
> number of days; windows minidump reveals that most threads are doing this:
>
>   Goroutine 462 - User: unicode/utf16/utf16.go:106 unicode/utf16.Decode 
> (0xe6e391) [semacquire]
>  0  0x00e2d116 in runtime.gopark
>  at runtime/proc.go:382
>  1  0x00e3df5c in runtime.goparkunlock
>  at runtime/proc.go:387
>  2  0x00e3df5c in runtime.semacquire1
>  at runtime/sema.go:160
>  3  0x00e0ac2f in runtime.semacquire
>  at runtime/sema.go:111
>  4  0x00e0ac2f in runtime.gcMarkDone
>  at runtime/mgc.go:787
>  5  0x00128c10 in ???
>  at ?:-1
>  6  0x00dfe7da in runtime.deductAssistCredit
>  at runtime/malloc.go:1217
>  7  0x00dfdff0 in runtime.mallocgc
>  at runtime/malloc.go:932
>  8  0x00e3f972 in runtime.makeslice
>  at runtime/slice.go:103
>  9  0x00e6e391 in unicode/utf16.Decode
>  at unicode/utf16/utf16.go:106
> 10  0x00e72a7b in syscall.UTF16ToString
>  at syscall/syscall_windows.go:63
> 11  0x00eb7a67 in os.(*File).readdir
>  at os/dir_windows.go:43
> 12  0x00eb72c5 in os.(*File).Readdirnames
>  at os/dir.go:70
> 13  0x00fb623a in path/filepath.glob
>  at path/filepath/match.go:346
> 14  0x00fb5ea5 in path/filepath.globWithLimit
>  at path/filepath/match.go:273
> 15  0x031de255 in path/filepath.Glob
>  at path/filepath/match.go:243
>
> Multiple threads, all waiting on a semaphore inside mallocgc. The actual 
> reason we're waiting for memory changes, obviously (sometimes a string 
> method, or hashmap allocation, or logging call...). This behavior has 
> remained consistent across multiple hangs across a number of weeks. After a 
> bit of digging into the minidump, this (I think) is the thread that's 
> holding the semaphore(s), at least based on the line numbers:
>
>   Goroutine 37 - User: :0 ??? (0x7ffb0e056974) (thread 5628)
> 0  0x7ffb0e056974 in ???
> at ?:-1
> 1  0x00e5c5a0 in runtime.systemstack_switch
> at runtime/asm_amd64.s:463
> 2  0x00e0ade5 in runtime.gcMarkDone
> at runtime/mgc.go:855
> 3  0x00128c10 in ???
> at ?:-1
> 4  0x00e5e881 in runtime.goexit
> at runtime/asm_amd64.s:1598
>
> Note that the precise point in gcMarkDone can change. I have another 
> minidump showing a hang at a different point in the same method:
>
> Goroutine 19 - Go: :0 ??? (0x208351516f8) (thread 7164) [unknown wait 
> reason 30] 
> 0 0x7ffe66e66974 in ??? 
> at ?:-1 
> 1 0x00e9c5a0 in runtime.systemstack_switch 
> at runtime/asm_amd64.s:463 
> 2 0x00e4acff in runtime.gcMarkDone 
> at runtime/mgc.go:807 
> 3 0x00128c10 in ??? 
> at ?:-1 
> 4 0x00e9e881 in runtime.goexit 
> at runtime/asm_amd64.s:1598 
>
> The commonality between these treads appears to be the `stacktrace()` 
> method. 
>
> Does anyone have any ideas for how to further debug this? Has anyone seen 
> anything like this? I've never seen anything like this before, and I can't 
> really reproduce it, as the only behavior is "let the application sit and 
> run for a few days." The only vaguely similar issue I've found is this, 
> which mentions interference from AV software: 
> https://github.com/golang/go/issues/52178. 
>
> Right now I'm waiting for the results of a gctrace log, as well as setting 
> GODEBUG=asyncpreemptoff=1, but other than that, I'm a bit out of ideas.  
>
> -- 
> You received this message because you are subscribed to the 

Re: [go-nuts] Memory operations hung in semacquire state, GC routine parked while holding semaphore?

2024-05-28 Thread robert engels
Feels like a memory leak to me. I would look for growing heap size in the gc 
logs. I am guessing that the system is not completely hung - but rather the 
runtime is having a hard time obtaining more memory, so it is slowing the 
allocators to a rate that makes them appear hung.

It may be that the process has consumed nearly all of the OS memory too - so 
the OS is having a hard-time responding to malloc requests.

i.e. The system is not making progress.

> On May 28, 2024, at 3:54 PM, 'Alex Kristiansen' via golang-nuts 
>  wrote:
> 
> This is an odd one. For reference, this is a customer machine, Windows server 
> 2016, compiled with go1.20.11. The application just hangs after a number of 
> days; windows minidump reveals that most threads are doing this:
> 
>   Goroutine 462 - User: unicode/utf16/utf16.go:106 unicode/utf16.Decode 
> (0xe6e391) [semacquire]
>  0  0x00e2d116 in runtime.gopark
>  at runtime/proc.go:382
>  1  0x00e3df5c in runtime.goparkunlock
>  at runtime/proc.go:387
>  2  0x00e3df5c in runtime.semacquire1
>  at runtime/sema.go:160
>  3  0x00e0ac2f in runtime.semacquire
>  at runtime/sema.go:111
>  4  0x00e0ac2f in runtime.gcMarkDone
>  at runtime/mgc.go:787
>  5  0x00128c10 in ???
>  at ?:-1
>  6  0x00dfe7da in runtime.deductAssistCredit
>  at runtime/malloc.go:1217
>  7  0x00dfdff0 in runtime.mallocgc
>  at runtime/malloc.go:932
>  8  0x00e3f972 in runtime.makeslice
>  at runtime/slice.go:103
>  9  0x00e6e391 in unicode/utf16.Decode
>  at unicode/utf16/utf16.go:106
> 10  0x00e72a7b in syscall.UTF16ToString
>  at syscall/syscall_windows.go:63
> 11  0x00eb7a67 in os.(*File).readdir
>  at os/dir_windows.go:43
> 12  0x00eb72c5 in os.(*File).Readdirnames
>  at os/dir.go:70
> 13  0x00fb623a in path/filepath.glob
>  at path/filepath/match.go:346
> 14  0x00fb5ea5 in path/filepath.globWithLimit
>  at path/filepath/match.go:273
> 15  0x031de255 in path/filepath.Glob
>  at path/filepath/match.go:243
> 
> Multiple threads, all waiting on a semaphore inside mallocgc. The actual 
> reason we're waiting for memory changes, obviously (sometimes a string 
> method, or hashmap allocation, or logging call...). This behavior has 
> remained consistent across multiple hangs across a number of weeks. After a 
> bit of digging into the minidump, this (I think) is the thread that's holding 
> the semaphore(s), at least based on the line numbers:
> 
>   Goroutine 37 - User: :0 ??? (0x7ffb0e056974) (thread 5628)
> 0  0x7ffb0e056974 in ???
> at ?:-1
> 1  0x00e5c5a0 in runtime.systemstack_switch
> at runtime/asm_amd64.s:463
> 2  0x00e0ade5 in runtime.gcMarkDone
> at runtime/mgc.go:855
> 3  0x00128c10 in ???
> at ?:-1
> 4  0x00e5e881 in runtime.goexit
> at runtime/asm_amd64.s:1598
> 
> Note that the precise point in gcMarkDone can change. I have another minidump 
> showing a hang at a different point in the same method:
> 
> Goroutine 19 - Go: :0 ??? (0x208351516f8) (thread 7164) [unknown wait reason 
> 30] 
> 0 0x7ffe66e66974 in ??? 
> at ?:-1 
> 1 0x00e9c5a0 in runtime.systemstack_switch 
> at runtime/asm_amd64.s:463 
> 2 0x00e4acff in runtime.gcMarkDone 
> at runtime/mgc.go:807 
> 3 0x00128c10 in ??? 
> at ?:-1 
> 4 0x00e9e881 in runtime.goexit 
> at runtime/asm_amd64.s:1598 
> 
> The commonality between these treads appears to be the `stacktrace()` method. 
> 
> Does anyone have any ideas for how to further debug this? Has anyone seen 
> anything like this? I've never seen anything like this before, and I can't 
> really reproduce it, as the only behavior is "let the application sit and run 
> for a few days." The only vaguely similar issue I've found is this, which 
> mentions interference from AV software: 
> https://github.com/golang/go/issues/52178. 
> 
> Right now I'm waiting for the results of a gctrace log, as well as setting 
> GODEBUG=asyncpreemptoff=1, but other than that, I'm a bit out of ideas. 
> 
> -- 
> 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/9c78ef6f-0190-4981-ab1f-ed18ad2f1080n%40googlegroups.com
>  
> 

[go-nuts] Memory operations hung in semacquire state, GC routine parked while holding semaphore?

2024-05-28 Thread 'Alex Kristiansen' via golang-nuts
This is an odd one. For reference, this is a customer machine, Windows 
server 2016, compiled with go1.20.11. The application just hangs after a 
number of days; windows minidump reveals that most threads are doing this:

  Goroutine 462 - User: unicode/utf16/utf16.go:106 unicode/utf16.Decode 
(0xe6e391) [semacquire]
 0  0x00e2d116 in runtime.gopark
 at runtime/proc.go:382
 1  0x00e3df5c in runtime.goparkunlock
 at runtime/proc.go:387
 2  0x00e3df5c in runtime.semacquire1
 at runtime/sema.go:160
 3  0x00e0ac2f in runtime.semacquire
 at runtime/sema.go:111
 4  0x00e0ac2f in runtime.gcMarkDone
 at runtime/mgc.go:787
 5  0x00128c10 in ???
 at ?:-1
 6  0x00dfe7da in runtime.deductAssistCredit
 at runtime/malloc.go:1217
 7  0x00dfdff0 in runtime.mallocgc
 at runtime/malloc.go:932
 8  0x00e3f972 in runtime.makeslice
 at runtime/slice.go:103
 9  0x00e6e391 in unicode/utf16.Decode
 at unicode/utf16/utf16.go:106
10  0x00e72a7b in syscall.UTF16ToString
 at syscall/syscall_windows.go:63
11  0x00eb7a67 in os.(*File).readdir
 at os/dir_windows.go:43
12  0x00eb72c5 in os.(*File).Readdirnames
 at os/dir.go:70
13  0x00fb623a in path/filepath.glob
 at path/filepath/match.go:346
14  0x00fb5ea5 in path/filepath.globWithLimit
 at path/filepath/match.go:273
15  0x031de255 in path/filepath.Glob
 at path/filepath/match.go:243

Multiple threads, all waiting on a semaphore inside mallocgc. The actual 
reason we're waiting for memory changes, obviously (sometimes a string 
method, or hashmap allocation, or logging call...). This behavior has 
remained consistent across multiple hangs across a number of weeks. After a 
bit of digging into the minidump, this (I think) is the thread that's 
holding the semaphore(s), at least based on the line numbers:

  Goroutine 37 - User: :0 ??? (0x7ffb0e056974) (thread 5628)
0  0x7ffb0e056974 in ???
at ?:-1
1  0x00e5c5a0 in runtime.systemstack_switch
at runtime/asm_amd64.s:463
2  0x00e0ade5 in runtime.gcMarkDone
at runtime/mgc.go:855
3  0x00128c10 in ???
at ?:-1
4  0x00e5e881 in runtime.goexit
at runtime/asm_amd64.s:1598

Note that the precise point in gcMarkDone can change. I have another 
minidump showing a hang at a different point in the same method:

Goroutine 19 - Go: :0 ??? (0x208351516f8) (thread 7164) [unknown wait 
reason 30] 
0 0x7ffe66e66974 in ??? 
at ?:-1 
1 0x00e9c5a0 in runtime.systemstack_switch 
at runtime/asm_amd64.s:463 
2 0x00e4acff in runtime.gcMarkDone 
at runtime/mgc.go:807 
3 0x00128c10 in ??? 
at ?:-1 
4 0x00e9e881 in runtime.goexit 
at runtime/asm_amd64.s:1598 

The commonality between these treads appears to be the `stacktrace()` 
method. 

Does anyone have any ideas for how to further debug this? Has anyone seen 
anything like this? I've never seen anything like this before, and I can't 
really reproduce it, as the only behavior is "let the application sit and 
run for a few days." The only vaguely similar issue I've found is this, 
which mentions interference from AV software: 
https://github.com/golang/go/issues/52178. 


Right now I'm waiting for the results of a gctrace log, as well as setting 
GODEBUG=asyncpreemptoff=1, but other than that, I'm a bit out of ideas.  

-- 
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/9c78ef6f-0190-4981-ab1f-ed18ad2f1080n%40googlegroups.com.


[go-nuts] Re: Protobuf build error with gogo - has inconsistent names structpb

2024-05-28 Thread Ian Vernon (ianvernon92)
Did you ever figure this out? I am hitting the same issue, and it's quite 
frustrating :(

On Monday, July 25, 2022 at 2:08:18 AM UTC-7 santhoshth...@gmail.com wrote:

> Hi Everyone
>
> I am importing the proto of other project into my proto file and run 
> protoc command. 
> I got this below error :
>
> *Go package "github.com/gogo/protobuf/types 
> " has inconsistent names structpb 
> (google/protobuf/struct.proto) and timestamppb 
> (google/protobuf/timestamp.proto)*
>
> *protoc command:*
> User/project/web/tools/protoc-3.17.3/bin/protoc 
> --proto_path=User/project:. 
> -I=User/project/web/rpc/protomgr 
> -I=User/project/web/protobuf-import 
> --plugin=protoc-gen-twirp=User/project/bin/protoc-gen-twirp 
> --plugin=protoc-gen-go=User/project/bin/protoc-gen-go 
> --plugin=protoc-gen-go-grpc=User/project/bin/protoc-gen-go-grpc 
> --twirp_out=. 
> go_out=Mgoogle/protobuf/any.proto=
> github.com/gogo/protobuf/types,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types:.
>  
> proto_file.proto
>
>
> The both proto files has the import of 
>
> *import "google/protobuf/timestamp.proto";import 
> "google/protobuf/struct.proto";*
>
>
> I can't figure out what is happening here. Can somebody provide some 
> suggestions? 
>

-- 
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/042d8e88-d0e8-48ef-b894-22bf8cc5f058n%40googlegroups.com.


Re: [go-nuts] Significance of using a buffered channel of capacity 1.

2024-05-27 Thread Deepak Pathak
IMHO, this is so that the sender of ths signal to your channel doesn't gets 
blocked. 

A helpful blog to understand 
it: https://www.rudderstack.com/blog/implementing-graceful-shutdown-in-go/

Hope it helps!

On Thursday 30 July 2015 at 02:42:50 UTC+5:30 Bakul Shah wrote:

> On Wed, 29 Jul 2015 01:39:50 PDT Yesudeep Mangalapilly  
> wrote:
> > --- code ---
> > package main
> > 
> > import "fmt"
> > import "time"
> > 
> > func worker(done chan bool) {
> > time.Sleep(time.Second)
> > done <- true
> > }
> > 
> > func main() {
> > done := make(chan bool, 1) // What is the significance of using 1 as 
> > capacity here?
> > go worker(done)
> > <-done
> > }
> > --- end code ---
> > 
> > Why use 1 to create a buffered channel? Can we not signal "done" using a 
> > regular non-buffered channel?
>
> In general, synchronize only when you have to. Here the main
> thread wants to know when the worker thread terminates but the
> worker thread doesn't care when the main thread gets around to
> reading from "done". Using a 1 deep buffer channel exactly
> captures this usage pattern. An unbuffered channel would make
> the worker thread "rendezvous" with the main thread, which is
> unnecessary.
>

-- 
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/6ef0468a-fd7d-4bf8-833b-a7696512aa4dn%40googlegroups.com.


[go-nuts] Re: Upgrading to last version of dependency without upgrading toolchain?

2024-05-25 Thread 'TheDiveO' via golang-nuts
For the archeologists, underlying issue has been acknowledged 
https://github.com/golang/go/issues/67574; sadly, this forum kept schtumm.

On Monday, May 6, 2024 at 1:46:17 PM UTC+2 TheDiveO wrote:

> As I cannot edit the title anymore: it's about upgrading to the last 
> version that can be used without toolchain change, which is not necessarily 
> the "latest" version of a dependency.
>
> On Monday, May 6, 2024 at 10:42:17 AM UTC+2 TheDiveO wrote:
>
>> FYI, go-mod-upgrade runs the following command under its hood:
>>
>> go list -u -mod=readonly -f '{{if (and (not (or .Main .Indirect)) 
>> .Update)}}{{.Path}}: {{.Version}} -> {{.Update.Version}}{{end}}' -m all
>>
>> On Monday, May 6, 2024 at 10:36:08 AM UTC+2 TheDiveO wrote:
>>
>>> Up front, I have to admit that I'm struggling with the newly introduced 
>>> download-your-go-toolchain-on-the-fly when it comes to:
>>>
>>>1. having reproducible builds in a CI/CD pipeline without getting 
>>>downloaded a different toolchain as installed at the stage start,
>>>2. being a module maintained as opposed to being a "leaf" app 
>>>maintainer without downstream users, while maintaining the N,N-1 go 
>>> (minor) 
>>>version guarantee.
>>>
>>> Over the years, I've found https://github.com/oligot/go-mod-upgrade to 
>>> be very useful to me in maintaining my (intermediate) module dependencies. 
>>> Unfortunately, this tool now breaks down and the author of go-mod-upgrade 
>>> at this time considers the situation to be a go toolchain upstream problem (
>>> https://github.com/oligot/go-mod-upgrade/issues/52#issuecomment-2093537300
>>> ).
>>>
>>> What happens is when I'm on a go 1.21.x toolchain in order to ensure the 
>>> N,N-1 guarantee, a go-mod-upgrade on a module with a k8s.io/api  
>>> "crashes" with the following error, caused by the go command used from 
>>> go-mod-upgrade under its hood:
>>>
>>>
>>> *Error running go command to discover modules: exit status 1 stderr=go: 
>>> loading module retractions for k8s.io/a...@v0.26.2 
>>> : module k8s.io/a...@v0.30.0 
>>>  requires go >= 1.22.0 (running go 1.21.7; 
>>> GOTOOLCHAIN=local)*
>>>
>>> Is there a way in the go command to upgrade to the "latest" dependency 
>>> that doesn't trigger this error? Manually 
>>> , I can see that there is a 
>>> 0.29.4 available. Unfortunately, even a single dependency like this causes 
>>> go-mod-upgrade to fail completely, so it's back for me to maintaining each 
>>> and ever of my many deps individually ... which absolutely sucks from the 
>>> UX perspective as I'm sure you can follow along with. Remember, I simply 
>>> cannot switch toolchains on a whim, not least due to CI/CD policies.
>>>
>>> How to deal with this situation? Is there a way to use the go tool so 
>>> that it would return only upgrades without toolchain changes? How might the 
>>> go-mod-upgrade tool work around this situation?
>>>
>>>

-- 
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/5032c3c3-74cc-4272-bd97-3d99c55bd4a7n%40googlegroups.com.


Re: [go-nuts] mutex in slog/handler.go?

2024-05-24 Thread Harris, Andrew
The mutex field of the common handler struct became a pointer-to-mutex at some 
point IIRC - it is currently, so copying should be fine.

Get Outlook for iOS

From: golang-nuts@googlegroups.com  on behalf of 
Eli Lindsey 
Sent: Friday, May 24, 2024 7:18:51 AM
To: Jochen Voss 
Cc: golang-nuts 
Subject: Re: [go-nuts] mutex in slog/handler.go?

Git blame may be helpful, and specifically commit 847d40d6998. It looks like 
code drifted from the comment.

-eli

On May 24, 2024, at 9:25 AM, Jochen Voss  wrote:

Hello,

In the Go standard library, in the file log/slog/handler.go, I found the 
following code:

func (h *commonHandler) clone() *commonHandler {
// We can't use assignment because we can't copy the mutex.
return {
json:  h.json,
opts:  h.opts,
preformattedAttrs: slices.Clip(h.preformattedAttrs),
groupPrefix:   h.groupPrefix,
groups:slices.Clip(h.groups),
nOpenGroups:   h.nOpenGroups,
w: h.w,
mu:h.mu, // mutex shared among all clones of this handler
}
}

The first comment states that "we can't copy the mutex", but then the last line 
seems to copy the mutex anyway.  What is going on here?

Maybe this just an oversight from a time when every hander had its own mutex?  
Or is there something subtle going on here?

Many thanks,
Jochen


--
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/153e9898-f17e-44cc-ab2a-8570f916c0c3n%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/D370602F-6226-4AAC-B3EC-6BA164FEA4F9%40siliconsprawl.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/SJ0PR07MB97958715C77D9CCFC2C2C1CFA0F52%40SJ0PR07MB9795.namprd07.prod.outlook.com.


Re: [go-nuts] mutex in slog/handler.go?

2024-05-24 Thread Eli Lindsey
Git blame may be helpful, and specifically commit 847d40d6998. It looks like code drifted from the comment.-eli On May 24, 2024, at 9:25 AM, Jochen Voss  wrote:Hello,In the Go standard library, in the file log/slog/handler.go, I found the following code:func (h *commonHandler) clone() *commonHandler {	// We can't use assignment because we can't copy the mutex.	return {		json:              h.json,		opts:              h.opts,		preformattedAttrs: slices.Clip(h.preformattedAttrs),		groupPrefix:       h.groupPrefix,		groups:            slices.Clip(h.groups),		nOpenGroups:       h.nOpenGroups,		w:                 h.w,		mu:                h.mu, // mutex shared among all clones of this handler	}}The first comment states that "we can't copy the mutex", but then the last line seems to copy the mutex anyway.  What is going on here?Maybe this just an oversight from a time when every hander had its own mutex?  Or is there something subtle going on here?Many thanks,Jochen



-- 
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/153e9898-f17e-44cc-ab2a-8570f916c0c3n%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/D370602F-6226-4AAC-B3EC-6BA164FEA4F9%40siliconsprawl.com.


[go-nuts] mutex in slog/handler.go?

2024-05-24 Thread Jochen Voss
Hello,

In the Go standard library, in the file log/slog/handler.go, I found the 
following code:

func (h *commonHandler) clone() *commonHandler {
// We can't use assignment because we can't copy the mutex.
return {
json:  h.json,
opts:  h.opts,
preformattedAttrs: slices.Clip(h.preformattedAttrs),
groupPrefix:   h.groupPrefix,
groups:slices.Clip(h.groups),
nOpenGroups:   h.nOpenGroups,
w: h.w,
mu:h.mu, // mutex shared among all clones of this handler
}
}

The first comment states that "we can't copy the mutex", but then the last 
line seems to copy the mutex anyway.  What is going on here?

Maybe this just an oversight from a time when every hander had its own 
mutex?  Or is there something subtle going on here?

Many thanks,
Jochen

-- 
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/153e9898-f17e-44cc-ab2a-8570f916c0c3n%40googlegroups.com.


[go-nuts] multiple rangefunc iterators: restart?

2024-05-23 Thread Rory Campbell-Lange
I've been playing with with rangefunc experiment, with help from 
https://go.dev/wiki/RangefuncExperiment and the possible idioms that might come 
out of it (https://blog.perfects.engineering/go_range_over_funcs is a good 
read).

One somewhat eccentric use of nested iterators I built in the past in python 
was turning an SQL widerows or domain aggregate result into a set of nested 
objects, so one could use the results in something like the following way:

for p in people:
for c in p.cars:
for t in c.tickets:
print("person {} in car {} got ticket {}", p, c, t)

While I was able to get a very janky version of this type of behaviour with 
https://go.dev/play/p/gFUcKNSrbMV?v=gotip this only has an iterator on the left 
hand side and series of nested structs through slices. My attempts to use more 
iterators (for cars and tickets) fails as these of course stop after the first 
set of cars and tickets respectively have been yielded.

I realise this is a contrived example, but I wonder if there might be more 
general cases where iterators could be stopped and restarted. (The docs to 
iter.Pull suggest next() and stop() are non-resettable also.) Perhaps there 
could be hidden new iter.Seq constructors in the container for when the cars 
and tickets iterators are exhausted...hmm...

I'd be grateful for any thoughts about this casual and hypothetical case, 
although I guess it could be helpful for something like retrieving nested data 
from an sql cursor efficiently.

Cheers
Rory


That code above turns:

a a1 a2 b1 b2 b3 c1 c2 c3
a a1 a2 b1 b2 b3 c4 c5 c6
a a1 a2 b1 b2 b3 c7 c8 c9
a a1 a2 b4 b5 b6 c10 c11 c12
d d1 d2 e1 e2 e3 f1 f2 f3
d d1 d2 e1 e2 e3 f4 f5 f6
g g1 g2 h1 h2 h3 i1 i2 i3

into:

[a a1 a2]
>  [b1 b2 b3]
> >  [c1 c2 c3]
> >  [c4 c5 c6]
> >  [c7 c8 c9]
>  [b4 b5 b6]
> >  [c10 c11 c12]
[d d1 d2]
>  [e1 e2 e3]
> >  [f1 f2 f3]
> >  [f4 f5 f6]
[g g1 g2]
>  [h1 h2 h3]
> >  [i1 i2 i3]

called like this:

for a := range collection.Iter() { // iter.Seq
fmt.Println(a.r)
for _, b := range a.s {// slice -- could be iter.Seq?
fmt.Println("> ", b.r)
for _, c := range b.s {// slice -- could be 
iter.Seq?
fmt.Println("> > ", c.r)
}
}
}

-- 
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/Zk94CqLUJ6fJjmuA%40campbell-lange.net.


Re: [go-nuts] Re: Call the .net dlls into the golang

2024-05-23 Thread 'Brian Candler' via golang-nuts
"try building at the command line"

That's your clue. You'll most likely get a meaningful error message on 
stderr, which your IDE is hiding.

On Thursday 23 May 2024 at 13:47:10 UTC+1 Pavan Kumar A R wrote:

> Hello , 
>
> I am try to call the c program in the golang , but i am getting the issue 
> .  please see the error message :
> package main
>
> go list failed to return CompiledGoFiles. This may indicate failure to 
> perform cgo processing; try building at the command line. See 
> https://golang.org/issue/38990.go list
> View Problem (Alt+F8)
>
>
> //#cgo LDFLAGS: -L. -llibCWrapper-win64 -Wl,-rpath,.
> //#include "ealApiLib.h"
>
> import "C"
> import "fmt"
>
> func main() {
>
> result := C.Connect("192.168.1.1")
>
> fmt.Println("connection success" + result)
>
> }
>
>
>
> On Thursday 23 May 2024 at 02:53:12 UTC+5:30 peterGo wrote:
>
>> cgo command
>> https://pkg.go.dev/cmd/cgo
>> Cgo enables the creation of Go packages that call C code.
>>
>> On Wednesday, May 22, 2024 at 4:41:13 PM UTC-4 Carla Pfaff wrote:
>>
>>> Yes, you can call C functions from Go, it's called Cgo: 
>>> https://go.dev/blog/cgo
>>>
>>> On Wednesday 22 May 2024 at 18:04:19 UTC+2 Pavan Kumar A R wrote:
>>>

> Okay,  it's possible to call the C program to Golang. Because I also 
> have the C platform dlls and the C platform dlls  we using in the cross 
> platform mono and in the mono internally call the.net dlls function , 
> can I use the C program dlls in Golang?  
>


-- 
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/21db8561-176e-4857-a904-8bda3c226ab3n%40googlegroups.com.


Re: [go-nuts] Re: Call the .net dlls into the golang

2024-05-23 Thread Pavan Kumar A R
Hello , 

I am try to call the c program in the golang , but i am getting the issue 
.  please see the error message :
package main

go list failed to return CompiledGoFiles. This may indicate failure to 
perform cgo processing; try building at the command line. See 
https://golang.org/issue/38990.go list
View Problem (Alt+F8)


//#cgo LDFLAGS: -L. -llibCWrapper-win64 -Wl,-rpath,.
//#include "ealApiLib.h"

import "C"
import "fmt"

func main() {

result := C.Connect("192.168.1.1")

fmt.Println("connection success" + result)

}



On Thursday 23 May 2024 at 02:53:12 UTC+5:30 peterGo wrote:

> cgo command
> https://pkg.go.dev/cmd/cgo
> Cgo enables the creation of Go packages that call C code.
>
> On Wednesday, May 22, 2024 at 4:41:13 PM UTC-4 Carla Pfaff wrote:
>
>> Yes, you can call C functions from Go, it's called Cgo: 
>> https://go.dev/blog/cgo
>>
>> On Wednesday 22 May 2024 at 18:04:19 UTC+2 Pavan Kumar A R wrote:
>>
>>>
 Okay,  it's possible to call the C program to Golang. Because I also 
 have the C platform dlls and the C platform dlls  we using in the cross 
 platform mono and in the mono internally call the.net dlls function , 
 can I use the C program dlls in Golang?  

>>>

-- 
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/d8665110-07f3-4f0d-8e14-49900cd4b6abn%40googlegroups.com.


Re: [go-nuts] vet: Respect PATH

2024-05-22 Thread 'wagner riiffel' via golang-nuts

On 5/21/2024 12:48 PM, andrew.p...@gmail.com wrote:

Please simplify both of these, so that the user can simply run:

go vet -vettool=shadow

Or:

shadow ./...

> In other words, the user should be able to invoke gofmt on a large Go
> project with:
>
> gofmt ./...
>
> Same request for goimports.
>

The "./..." syntax matches packages, not files and that's why tools 
which work on files doesn't accept this syntax. The "go" program already 
has "fmt" sub-command that do exactly this, run gofmt recursively on all 
matched packages sources, so try "go fmt ./...". Analyzers already 
accept packages and not files, so "shadow ./..." should work.


I think taking files instead of packages is somewhat legacy, but I found 
it's useful, since we moved from GOPATH to go modules resolving packages 
is somehow slow, I definitely feel a delay when using programs that 
takes packages as an argument, that's very noticeable when you're in a 
slow filesystem or storage device, so gofmt not taking 5 seconds (unlike 
go fmt) to run is a good feature.


-w


--
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/f9cea397-3888-457a-a945-589f611c1ed7%40104d.net.


Re: [go-nuts] Re: Call the .net dlls into the golang

2024-05-22 Thread peterGo
cgo command
https://pkg.go.dev/cmd/cgo
Cgo enables the creation of Go packages that call C code.

On Wednesday, May 22, 2024 at 4:41:13 PM UTC-4 Carla Pfaff wrote:

> Yes, you can call C functions from Go, it's called Cgo: 
> https://go.dev/blog/cgo
>
> On Wednesday 22 May 2024 at 18:04:19 UTC+2 Pavan Kumar A R wrote:
>
>>
>>> Okay,  it's possible to call the C program to Golang. Because I also 
>>> have the C platform dlls and the C platform dlls  we using in the cross 
>>> platform mono and in the mono internally call the.net dlls function , 
>>> can I use the C program dlls in Golang?  
>>>
>>

-- 
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/3ca5ff36-58f5-42e2-910f-c2687c31af77n%40googlegroups.com.


Re: [go-nuts] Re: Call the .net dlls into the golang

2024-05-22 Thread 'Carla Pfaff' via golang-nuts
Yes, you can call C functions from Go, it's called 
Cgo: https://go.dev/blog/cgo

On Wednesday 22 May 2024 at 18:04:19 UTC+2 Pavan Kumar A R wrote:

>
>> Okay,  it's possible to call the C program to Golang. Because I also have 
>> the C platform dlls and the C platform dlls  we using in the cross platform 
>> mono and in the mono internally call the.net dlls function , can I use 
>> the C program dlls in Golang?  
>>
>

-- 
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/7282ba6c-8700-44f0-bd97-5a61807c963en%40googlegroups.com.


Re: [go-nuts] Errors trying to use external pkg z3

2024-05-22 Thread Kenneth Miller
I changed the terminal and then it worked.

On Wednesday, May 22, 2024 at 10:39:05 AM UTC-6 Brian Candler wrote:

> * Start in an empty directory
> * Run "go mod init example"
> * Create your main.go with that import statement in it
> * Run:
>
> go mod tidy
> go run .
>
> On Wednesday 22 May 2024 at 16:26:54 UTC+1 Kenneth Miller wrote:
>
>> I tried that, same error
>>
>> On Wednesday, May 22, 2024 at 9:12:58 AM UTC-6 Brian Candler wrote:
>>
>>> It's because the name of the module is "github.com/aclements/go-z3/z3", 
>>> not "z3"
>>>
>>> Only packages in the standard library have short names, like "fmt", 
>>> "strings" etc.
>>>
>>> On Wednesday 22 May 2024 at 15:46:30 UTC+1 robert engels wrote:
>>>
 If it is your own code, you have to use

 import “github.com/aclements/go-z3/z3”

 or you need a special go.mod file.

 On May 22, 2024, at 9:38 AM, robert engels  
 wrote:

 What are you trying to run? z3 is a library.

 On May 22, 2024, at 9:29 AM, Kenneth Miller  
 wrote:

 I did go get -u github.com/aclements/go-z3/z3

 but when I go run . I get

 main.go:5:2: package z3 is not in std

 the offending line is 

 import "z3"

 can someone help me please? I'm sure this has been asked before but I 
 couldn't find it

 -- 
 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/d46b52fb-fa96-4544-914a-42bf83d75322n%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...@googlegroups.com.

 To view this discussion on the web visit 
 https://groups.google.com/d/msgid/golang-nuts/EE0FDF46-94C6-44D6-98C0-19D52C371C20%40ix.netcom.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/15cc3662-ecf3-4d8b-b75b-8a22bfcd231en%40googlegroups.com.


Re: [go-nuts] Errors trying to use external pkg z3

2024-05-22 Thread 'Brian Candler' via golang-nuts
* Start in an empty directory
* Run "go mod init example"
* Create your main.go with that import statement in it
* Run:

go mod tidy
go run .

On Wednesday 22 May 2024 at 16:26:54 UTC+1 Kenneth Miller wrote:

> I tried that, same error
>
> On Wednesday, May 22, 2024 at 9:12:58 AM UTC-6 Brian Candler wrote:
>
>> It's because the name of the module is "github.com/aclements/go-z3/z3", 
>> not "z3"
>>
>> Only packages in the standard library have short names, like "fmt", 
>> "strings" etc.
>>
>> On Wednesday 22 May 2024 at 15:46:30 UTC+1 robert engels wrote:
>>
>>> If it is your own code, you have to use
>>>
>>> import “github.com/aclements/go-z3/z3”
>>>
>>> or you need a special go.mod file.
>>>
>>> On May 22, 2024, at 9:38 AM, robert engels  wrote:
>>>
>>> What are you trying to run? z3 is a library.
>>>
>>> On May 22, 2024, at 9:29 AM, Kenneth Miller  
>>> wrote:
>>>
>>> I did go get -u github.com/aclements/go-z3/z3
>>>
>>> but when I go run . I get
>>>
>>> main.go:5:2: package z3 is not in std
>>>
>>> the offending line is 
>>>
>>> import "z3"
>>>
>>> can someone help me please? I'm sure this has been asked before but I 
>>> couldn't find it
>>>
>>> -- 
>>> 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/d46b52fb-fa96-4544-914a-42bf83d75322n%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...@googlegroups.com.
>>>
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/EE0FDF46-94C6-44D6-98C0-19D52C371C20%40ix.netcom.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/75533bfc-b63b-41cc-9f66-0885d0c00c7cn%40googlegroups.com.


Re: [go-nuts] Re: Call the .net dlls into the golang

2024-05-22 Thread Pavan Kumar A R
>
> Okay,  it's possible to call the C program to Golang. Because I also have
> the C platform dlls and the C platform dlls  we using in the cross platform
> mono and in the mono internally call the.net dlls function , can I use
> the C program dlls in Golang?
>

-- 
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/CAAvcNiNwdeKEMUmz_QTAdz_B_J65ekznpX8_PTHZdUb3rAY_3w%40mail.gmail.com.


Re: [go-nuts] Errors trying to use external pkg z3

2024-05-22 Thread Kenneth Miller
I tried that, same error

On Wednesday, May 22, 2024 at 9:12:58 AM UTC-6 Brian Candler wrote:

> It's because the name of the module is "github.com/aclements/go-z3/z3", 
> not "z3"
>
> Only packages in the standard library have short names, like "fmt", 
> "strings" etc.
>
> On Wednesday 22 May 2024 at 15:46:30 UTC+1 robert engels wrote:
>
>> If it is your own code, you have to use
>>
>> import “github.com/aclements/go-z3/z3”
>>
>> or you need a special go.mod file.
>>
>> On May 22, 2024, at 9:38 AM, robert engels  wrote:
>>
>> What are you trying to run? z3 is a library.
>>
>> On May 22, 2024, at 9:29 AM, Kenneth Miller  
>> wrote:
>>
>> I did go get -u github.com/aclements/go-z3/z3
>>
>> but when I go run . I get
>>
>> main.go:5:2: package z3 is not in std
>>
>> the offending line is 
>>
>> import "z3"
>>
>> can someone help me please? I'm sure this has been asked before but I 
>> couldn't find it
>>
>> -- 
>> 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/d46b52fb-fa96-4544-914a-42bf83d75322n%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...@googlegroups.com.
>>
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/EE0FDF46-94C6-44D6-98C0-19D52C371C20%40ix.netcom.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/c4a72330-79c6-40cc-bcdc-e79dd382f4f6n%40googlegroups.com.


Re: [go-nuts] Errors trying to use external pkg z3

2024-05-22 Thread 'Brian Candler' via golang-nuts
It's because the name of the module is "github.com/aclements/go-z3/z3", not 
"z3"

Only packages in the standard library have short names, like "fmt", 
"strings" etc.

On Wednesday 22 May 2024 at 15:46:30 UTC+1 robert engels wrote:

> If it is your own code, you have to use
>
> import “github.com/aclements/go-z3/z3”
>
> or you need a special go.mod file.
>
> On May 22, 2024, at 9:38 AM, robert engels  wrote:
>
> What are you trying to run? z3 is a library.
>
> On May 22, 2024, at 9:29 AM, Kenneth Miller  wrote:
>
> I did go get -u github.com/aclements/go-z3/z3
>
> but when I go run . I get
>
> main.go:5:2: package z3 is not in std
>
> the offending line is 
>
> import "z3"
>
> can someone help me please? I'm sure this has been asked before but I 
> couldn't find it
>
> -- 
> 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/d46b52fb-fa96-4544-914a-42bf83d75322n%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...@googlegroups.com.
>
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/EE0FDF46-94C6-44D6-98C0-19D52C371C20%40ix.netcom.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/ebeb05d6-5649-4ad4-b0d7-28ef36ee6dd7n%40googlegroups.com.


Re: [go-nuts] Errors trying to use external pkg z3

2024-05-22 Thread robert engels
If it is your own code, you have to use

import “github.com/aclements/go-z3/z3 ”

or you need a special go.mod file.

> On May 22, 2024, at 9:38 AM, robert engels  wrote:
> 
> What are you trying to run? z3 is a library.
> 
>> On May 22, 2024, at 9:29 AM, Kenneth Miller > > wrote:
>> 
>> I did go get -u github.com/aclements/go-z3/z3 
>> 
>> 
>> but when I go run . I get
>> 
>> main.go:5:2: package z3 is not in std
>> 
>> the offending line is 
>> 
>> import "z3"
>> 
>> can someone help me please? I'm sure this has been asked before but I 
>> couldn't find it
>> 
>> -- 
>> 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/d46b52fb-fa96-4544-914a-42bf83d75322n%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/EE0FDF46-94C6-44D6-98C0-19D52C371C20%40ix.netcom.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/AF8256CE-EF92-432C-95E0-4F6198B3EDA2%40ix.netcom.com.


Re: [go-nuts] Errors trying to use external pkg z3

2024-05-22 Thread robert engels
What are you trying to run? z3 is a library.

> On May 22, 2024, at 9:29 AM, Kenneth Miller  
> wrote:
> 
> I did go get -u github.com/aclements/go-z3/z3
> 
> but when I go run . I get
> 
> main.go:5:2: package z3 is not in std
> 
> the offending line is 
> 
> import "z3"
> 
> can someone help me please? I'm sure this has been asked before but I 
> couldn't find it
> 
> -- 
> 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/d46b52fb-fa96-4544-914a-42bf83d75322n%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/EE0FDF46-94C6-44D6-98C0-19D52C371C20%40ix.netcom.com.


[go-nuts] Errors trying to use external pkg z3

2024-05-22 Thread Kenneth Miller
I did go get -u github.com/aclements/go-z3/z3

but when I go run . I get

main.go:5:2: package z3 is not in std

the offending line is 

import "z3"

can someone help me please? I'm sure this has been asked before but I 
couldn't find it

-- 
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/d46b52fb-fa96-4544-914a-42bf83d75322n%40googlegroups.com.


[go-nuts] Re: Call the .net dlls into the golang

2024-05-22 Thread 'Carla Pfaff' via golang-nuts
You can't call .NET functions directly from Go. Go programs and .NET have 
two completely different runtimes. You would need some form of 
inter-process communication (IPC).

On Wednesday 22 May 2024 at 14:31:04 UTC+2 Pavan Kumar A R wrote:

> Hello ,
>
> I build the.net dlls in the target framework, which is.net-framework 2.0, 
> and inside the.net dlls are some functions. I want to call this function 
> in Golang. How can I call the.net function in Golang? Please help out 
> here. 
>

-- 
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/6ca2d475-9fd3-4549-9f8e-576d92ed70b5n%40googlegroups.com.


[go-nuts] Call the .net dlls into the golang

2024-05-22 Thread Pavan Kumar A R
 

Hello ,

I build the.net dlls in the target framework, which is.net-framework 2.0, 
and inside the.net dlls are some functions. I want to call this function in 
Golang. How can I call the.net function in Golang? Please help out here. 

-- 
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/759a08e7-19de-49af-9bf6-bdcf7b45905en%40googlegroups.com.


[go-nuts] Re: Discover go-size-analyzer: Streamline Your Go Binary Insights

2024-05-22 Thread Peter Galbavy
Another thumbs up! Thanks

On Tuesday 21 May 2024 at 16:16:54 UTC+1 Zxilly Chou wrote:

> Hello go-nuts,
>
> I'm excited to share a new tool that has landed in our Go ecosystem: 
> go-size-analyzer. This utility is designed to give you a clear picture of 
> the size of your compiled Go binaries, with a focus on how dependencies 
> contribute to the overall footprint.
>
> It simplifies the process of binary size analysis and offers a range of 
> viewing options, from web interfaces to terminal UIs and text formats. It's 
> also highly customisable, so you can tailor the output to suit your needs.
>
> The project is open source and actively seeking contributions, so if 
> you're interested in this kind of tool, it's definitely worth a look.
>
> You can find more information and get started with go-size-analyzer on its 
> GitHub page: https://github.com/Zxilly/go-size-analyzer
>
> Happy coding!
>
> Best,
>
> Zxilly
>

-- 
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/c40129f5-9ae9-4ce2-a218-8943ad948cadn%40googlegroups.com.


[go-nuts] Re: replacement for filepath.HasPrefix?

2024-05-21 Thread Jason E. Aten
When I needed to follow symlinks and exclude application-specific 
directories, I ended
up copying and customizing Walk() and walk() from the filepath package. 
They are
short and it was a straightforward to adapt them to my needs.

https://cs.opensource.google/go/go/+/refs/tags/go1.22.3:src/path/filepath/path.go;l=555
https://cs.opensource.google/go/go/+/refs/tags/go1.22.3:src/path/filepath/path.go;l=476

-- 
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/5b6737dc-5783-4a45-afe9-1faa2d9cf5aan%40googlegroups.com.


[go-nuts] Re: Uses of reflect and unsafe packages

2024-05-21 Thread Jason E. Aten
I use "unsafe" for performance optimization and with Cgo[1][2][3]. 

I use "reflect" and "unsafe" for doing de-serialization in a serialization 
framework, 
and for cross-language work (Go <-> C, Go <-> scripting languages like 
Python, R, Lua, zygomys)[4][5][6]. 

If you are staying entirely within the Go language, then you aren't likely 
to need "reflect". It lets
you write very dynamic code to handle a Go struct whose layout you don't 
know about at compile
time.  You give up type safety. It is usually alot of painstaking work.

If you aren't profiling your code for performance tuning, you likely won't 
need to mess with "unsafe".
It does let you avoid certain redundant allocations if you can guarantee 
things about your memory's
access patterns.

Since, as the ancient maps used to say, "here be dragons," it is better to 
leave both of them alone until you really, really need them.

examples:

[1] 
https://github.com/glycerine/embedr/blob/96d03afc338c43add0f473ef1ea36ed7257b69f1/r2go.go#L762
[2] 
https://github.com/glycerine/embedr/blob/96d03afc338c43add0f473ef1ea36ed7257b69f1/embedr.go#L255
[3] 
https://github.com/glycerine/greenpack/blob/971e607bf20009e551605ed6a8480335629241f8/msgp/unsafe.go#L34
[4] 
https://github.com/glycerine/greenpack/blob/971e607bf20009e551605ed6a8480335629241f8/msgp/write.go#L775
[5] 
https://github.com/glycerine/zygomys/blob/b4e08088004ee5de19f294d53bb692122463aa10/zygo/callgo.go#L15
[6] https://github.com/glycerine/rmq/blob/master/src/rmq/rmq.go#L466

On Tuesday, May 21, 2024 at 1:44:27 PM UTC+1 Ketan Rathod wrote:

> I have seen many discussions using refflect and unsafe packages, so i am 
> curious to know their usecases and when it is useful to use this packages.

-- 
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/55e7d611-ca03-436c-a528-d95cb0ab3437n%40googlegroups.com.


Re: [go-nuts] Calling the .net dlls to the golang

2024-05-21 Thread peterGo
Kurtis Rader,

The OP's question: "I am new to Golang. I have the.net dlls, and I am 
trying to call the.net function in the dll in Golang. but its not working 
and i searching in the Google also i could not find the relavent 
information, please me out here and provide the sample program also"

The meaning of the question seemed obvious to me, but not to you. I 
wondered why. I also wondered whether AI would find the question obvious. 

Since .NET DLL is a Microsoft term, I asked Satya Nadella the question. 
Copilot replied, "Certainly! Calling a .NET DLL function from Go ..."

Since Google is the principal sponsor of Go, I asked Sundar Pichai the 
question. Gemini replied, "Calling directly from Go to a .NET DLL ..."

So it's true. Some people may be replaced by AI.

peter


On Tuesday, May 21, 2024 at 4:31:47 PM UTC-4 Kurtis Rader wrote:

> Since the question is incoherent and the link to the package you claim to 
> be using doesn't resolve to a valid host name I'm going to assume this is 
> spam and you're not really a person asking for help.
>
> P.S., Saying it "is not working" is meaningless. If you are a real person 
> asking for help show us the code you wrote and explain what you expected 
> and what actually happened when you compiled and ran your code.
>

-- 
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/ef095ee3-826f-426d-917c-d7dc55f7dae0n%40googlegroups.com.


Re: [go-nuts] Calling the .net dlls to the golang

2024-05-21 Thread peterGo

Kurtis Rader,

Please follow the Go Community Code of Conduct  
while posting here. In short:

   - Treat everyone with respect and kindness.
   - Be thoughtful in how you communicate.
   - Don’t be destructive or inflammatory.
   - 
   
You are fired from your self-appointed role as spam checker!

.NET for Beginners 
https://learn.microsoft.com/en-us/shows/dotnet-for-beginners/

Learn  .NET
Assemblies in .NET
https://learn.microsoft.com/en-us/dotnet/standard/assembly/

Assemblies take the form of executable (*.exe*) or dynamic link library (
*.dll*) files, and are the building blocks of .NET applications. They 
provide the common language runtime with the information it needs to be 
aware of type implementations.

peter

On Tuesday, May 21, 2024 at 4:31:47 PM UTC-4 Kurtis Rader wrote:

> Since the question is incoherent and the link to the package you claim to 
> be using doesn't resolve to a valid host name I'm going to assume this is 
> spam and you're not really a person asking for help.
>
> P.S., Saying it "is not working" is meaningless. If you are a real person 
> asking for help show us the code you wrote and explain what you expected 
> and what actually happened when you compiled and ran your code.
>

-- 
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/d8fa482d-bc9a-4151-9a95-3900c6389bf6n%40googlegroups.com.


Re: [go-nuts] Calling the .net dlls to the golang

2024-05-21 Thread Kurtis Rader
Since the question is incoherent and the link to the package you claim to
be using doesn't resolve to a valid host name I'm going to assume this is
spam and you're not really a person asking for help.

P.S., Saying it "is not working" is meaningless. If you are a real person
asking for help show us the code you wrote and explain what you expected
and what actually happened when you compiled and ran your code.

-- 
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/CABx2%3DD_MkwgpXx%2BfbcOdnM%3DJG8XJFVLsx4xdTF3TdywNM8sv5g%40mail.gmail.com.


[go-nuts] Re: vet: Respect PATH

2024-05-21 Thread andrew.p...@gmail.com
Same request for goimports.

func GoImports(args ...string) error {
mg.Deps(CollectGoFiles)

for pth := range CollectedGoFiles {
cmd := exec.Command("goimports")
cmd.Args = append(cmd.Args, args...)
cmd.Args = append(cmd.Args, pth)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

if err := cmd.Run(); err != nil {
return err
}
}

return nil
}

Instead of the above nonsense, the user should be able to scan a large Go 
project with:

goimports ./...

Maybe these features have been added in recent Go versions. If so, please 
comment which specific Go versions finally added basic directory recursion 
to more of these tools.

On Tuesday, May 21, 2024 at 10:48:12 AM UTC-5 andrew.p...@gmail.com wrote:

> Similar request for gofmt. It should accept the ordinary ./... Go project 
> recursion syntax, instead of the awkward, explicit:
>
> func GoFmt(args ...string) error {
> mg.Deps(CollectGoFiles)
>
> for pth := range CollectedGoFiles {
> cmd := exec.Command("gofmt")
> cmd.Args = append(cmd.Args, args...)
> cmd.Args = append(cmd.Args, pth)
> cmd.Stdout = os.Stdout
> cmd.Stderr = os.Stderr
>
> if err := cmd.Run(); err != nil {
> return err
> }
> }
>
> return nil
> }
>
> In other words, the user should be able to invoke gofmt on a large Go 
> project with:
>
> gofmt ./...
>
> Looping over files is a simple enough concept for the tool to implement 
> itself, directly. Looping over files in wrapping scripts, such as shell 
> code, invites dragons.
>
> On Tuesday, May 21, 2024 at 10:45:14 AM UTC-5 andrew.p...@gmail.com wrote:
>
>> go vet fails to obey the standard PATH environment variable (POSIX, 
>> Windows). This makes it unnecessarily cumbersome to use go vet.
>>
>> Here is an example (Mage) script to scan Go projects for variable 
>> shadowing:
>>
>> func GoVetShadow(args ...string) error {
>> shadowPath, err := exec.LookPath("shadow")
>>
>> if err != nil {
>> return err
>> }
>>
>> return GoVet(fmt.Sprintf("-vettool=%s", shadowPath))
>> }
>>
>> The shadow tool is unable to recurse over Go projects with the ordinary 
>> ./... syntax; It relies on go vet. And even with the x/tools shadow 
>> installed and on PATH, go vet nevertheless requires an absolute path to the 
>> program.
>>
>> Please simplify both of these, so that the user can simply run:
>>
>> go vet -vettool=shadow
>>
>> Or:
>>
>> shadow ./...
>>
>> Which are easier to remember and lighter on the fingers.
>>
>> Some gophers will point out that we already have a working solution with 
>> Mage, and it's conceivable that equivalents are available in related build 
>> systems like make (POSIX, GNU, BSD, etc.) or sh (POSIX, bash, zsh, etc.) 
>> However, the requirement for the user to provide an absolute path tends to 
>> create maintenance hassles, fragile build scripts, many portability 
>> problems, and general resource waste. PATH already provides the 
>> information; please stop breaking basic things at the process level.
>>
>

-- 
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/537fe765-873c-417c-b74d-772e33c3dc23n%40googlegroups.com.


[go-nuts] Re: vet: Respect PATH

2024-05-21 Thread andrew.p...@gmail.com
Similar request for gofmt. It should accept the ordinary ./... Go project 
recursion syntax, instead of the awkward, explicit:

func GoFmt(args ...string) error {
mg.Deps(CollectGoFiles)

for pth := range CollectedGoFiles {
cmd := exec.Command("gofmt")
cmd.Args = append(cmd.Args, args...)
cmd.Args = append(cmd.Args, pth)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

if err := cmd.Run(); err != nil {
return err
}
}

return nil
}

In other words, the user should be able to invoke gofmt on a large Go 
project with:

gofmt ./...

Looping over files is a simple enough concept for the tool to implement 
itself, directly. Looping over files in wrapping scripts, such as shell 
code, invites dragons.

On Tuesday, May 21, 2024 at 10:45:14 AM UTC-5 andrew.p...@gmail.com wrote:

> go vet fails to obey the standard PATH environment variable (POSIX, 
> Windows). This makes it unnecessarily cumbersome to use go vet.
>
> Here is an example (Mage) script to scan Go projects for variable 
> shadowing:
>
> func GoVetShadow(args ...string) error {
> shadowPath, err := exec.LookPath("shadow")
>
> if err != nil {
> return err
> }
>
> return GoVet(fmt.Sprintf("-vettool=%s", shadowPath))
> }
>
> The shadow tool is unable to recurse over Go projects with the ordinary 
> ./... syntax; It relies on go vet. And even with the x/tools shadow 
> installed and on PATH, go vet nevertheless requires an absolute path to the 
> program.
>
> Please simplify both of these, so that the user can simply run:
>
> go vet -vettool=shadow
>
> Or:
>
> shadow ./...
>
> Which are easier to remember and lighter on the fingers.
>
> Some gophers will point out that we already have a working solution with 
> Mage, and it's conceivable that equivalents are available in related build 
> systems like make (POSIX, GNU, BSD, etc.) or sh (POSIX, bash, zsh, etc.) 
> However, the requirement for the user to provide an absolute path tends to 
> create maintenance hassles, fragile build scripts, many portability 
> problems, and general resource waste. PATH already provides the 
> information; please stop breaking basic things at the process level.
>

-- 
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/ba413feb-99d3-401f-b6b9-14c8dad7127dn%40googlegroups.com.


Re: [go-nuts] Discover go-size-analyzer: Streamline Your Go Binary Insights

2024-05-21 Thread Luca Pascali
Nice

PSK

On Tue, May 21, 2024 at 5:17 PM Zxilly Chou  wrote:

> Hello go-nuts,
>
> I'm excited to share a new tool that has landed in our Go ecosystem:
> go-size-analyzer. This utility is designed to give you a clear picture of
> the size of your compiled Go binaries, with a focus on how dependencies
> contribute to the overall footprint.
>
> It simplifies the process of binary size analysis and offers a range of
> viewing options, from web interfaces to terminal UIs and text formats. It's
> also highly customisable, so you can tailor the output to suit your needs.
>
> The project is open source and actively seeking contributions, so if
> you're interested in this kind of tool, it's definitely worth a look.
>
> You can find more information and get started with go-size-analyzer on its
> GitHub page: https://github.com/Zxilly/go-size-analyzer
>
> Happy coding!
>
> Best,
>
> Zxilly
>
> --
> 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/af78ab03-f793-40f2-8721-20ef3f3a5a13n%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/CAJNBTx%2BSZ5hZ9UTehuP8BuTOqAmCt7k-jOFKpNuNnLLMpFkdKQ%40mail.gmail.com.


[go-nuts] vet: Respect PATH

2024-05-21 Thread andrew.p...@gmail.com
go vet fails to obey the standard PATH environment variable (POSIX, 
Windows). This makes it unnecessarily cumbersome to use go vet.

Here is an example (Mage) script to scan Go projects for variable shadowing:

func GoVetShadow(args ...string) error {
shadowPath, err := exec.LookPath("shadow")

if err != nil {
return err
}

return GoVet(fmt.Sprintf("-vettool=%s", shadowPath))
}

The shadow tool is unable to recurse over Go projects with the ordinary 
./... syntax; It relies on go vet. And even with the x/tools shadow 
installed and on PATH, go vet nevertheless requires an absolute path to the 
program.

Please simplify both of these, so that the user can simply run:

go vet -vettool=shadow

Or:

shadow ./...

Which are easier to remember and lighter on the fingers.

Some gophers will point out that we already have a working solution with 
Mage, and it's conceivable that equivalents are available in related build 
systems like make (POSIX, GNU, BSD, etc.) or sh (POSIX, bash, zsh, etc.) 
However, the requirement for the user to provide an absolute path tends to 
create maintenance hassles, fragile build scripts, many portability 
problems, and general resource waste. PATH already provides the 
information; please stop breaking basic things at the process level.

-- 
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/d7c16676-9cc3-477e-a822-af5deba12e12n%40googlegroups.com.


[go-nuts] Discover go-size-analyzer: Streamline Your Go Binary Insights

2024-05-21 Thread Zxilly Chou


Hello go-nuts,

I'm excited to share a new tool that has landed in our Go ecosystem: 
go-size-analyzer. This utility is designed to give you a clear picture of 
the size of your compiled Go binaries, with a focus on how dependencies 
contribute to the overall footprint.

It simplifies the process of binary size analysis and offers a range of 
viewing options, from web interfaces to terminal UIs and text formats. It's 
also highly customisable, so you can tailor the output to suit your needs.

The project is open source and actively seeking contributions, so if you're 
interested in this kind of tool, it's definitely worth a look.

You can find more information and get started with go-size-analyzer on its 
GitHub page: https://github.com/Zxilly/go-size-analyzer

Happy coding!

Best,

Zxilly

-- 
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/af78ab03-f793-40f2-8721-20ef3f3a5a13n%40googlegroups.com.


[go-nuts] Uses of reflect and unsafe packages

2024-05-21 Thread Ketan Rathod
I have seen many discussions using refflect and unsafe packages, so i am 
curious to know their usecases and when it is useful to use this packages.

-- 
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/07589604-959f-4d62-94e8-2e12e27126f6n%40googlegroups.com.


[go-nuts] Calling the .net dlls to the golang

2024-05-21 Thread Pavan Kumar A R
Hello , 

I am new to Golang. I have the.net dlls, and I am trying to call the.net 
function in the dll in Golang. but its not working and i searching in the 
Google also i could not find the relavent information, please me out here 
and provide the sample program also

Thanks for the advance.

-- 
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/5aad3949-6a1a-4884-a27c-69fc7246724bn%40googlegroups.com.


[go-nuts] Re: Alternative text/template function libraries to github.com/Masterminds/sprig?

2024-05-20 Thread twp...@gmail.com
Just following up on this old message, there now seems to be at least:

https://github.com/go-sprout/sprout
https://github.com/chezmoi/templatefuncs

Regards,
Tom

On Monday, January 9, 2023 at 8:53:41 PM UTC+1 Tom Payne wrote:

> github.com/Masterminds/sprig is a popular library of template functions, 
> used by some popular projects, e.g. Kubernetes Helm.
>
> Unfortunately, Masterminds/sprig also has a number of inherent flaws:
> 1. The order of arguments to many of its functions is incompatible with 
> text/template's pipeline syntax.
> 2. Many of its functions do not handle strings, []bytes, variable numbers 
> of arguments, and other argument variations in a sensible way.
> 3. It has, at the time of writing, 78 open issues 
> , most of them unaddressed, 
> and has seen only minor maintenance activity over the last few years.
> 4. Its function names do not follow Go's naming conventions.
>
> #1 and #2 cannot be fixed in a backwards-compatible way. #3 means that 
> fixes aren't practically accepted anyway. #4 just means that templates 
> using Masterminds/sprig are ugly to Go developer eyes.
>
> Instead, I want a library of template functions that works well with 
> text/template, has decent ergonomics, follows Go's naming conventions, and 
> is actively maintained. I don't care about backwards compatibility with 
> sprig as this is impossible to achieve anyway.
>
> Before I start such a project, are there any existing good existing 
> alternatives to Masterminds/sprig?
>
> Many thanks,
> Tom
>

-- 
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/af98d89e-2aa7-4758-9597-0a4192574e64n%40googlegroups.com.


Re: [go-nuts] using runtime cgo.Handle passing struct types

2024-05-19 Thread Sudarshan Soma
Thanks Ian, Yes i followed a similar approach and it's working fine..

On Sun, May 19, 2024 at 4:36 AM Ian Lance Taylor  wrote:

> On Thu, May 16, 2024 at 12:57 AM Pavan  wrote:
> >
> > Thanks . Yes it works when C API takes uintptr_t. In my case, the C API
> expects void * which i can not change, so I was trying to make it work with
> the variant example stated above.
>
> In C, unlike Go, you can convert between void* and uintptr_t.  When
> using cgo, one approach is a little wrapper function in the cgo
> comment that takes a uintptr_t and calls the real function with a
> conversion to void*.
>
> Ian
>
> > On Thursday, May 16, 2024 at 5:28:55 AM UTC+5:30 Ian Lance Taylor wrote:
> >>
> >> On Tue, May 14, 2024 at 10:37 PM Pavan  wrote:
> >> >
> >> > I need to pass value of struct type, which has C strings and
> functions to C function as void* argument. C layer would provide this
> struct type data back to go function. Below is the sample program. It
> panics if the handle used is returned from getH function. It works fine if
> the handle is global. Can the handle be dynamically returned from getH and
> make it work. Please correct if i missed something..
> >> >
> >> >
> >> >
> >> > package main
> >> >
> >> > /*
> >> > struct dt {
> >> > void *context;
> >> > };
> >> > typedef struct dt dt;
> >> >
> >> > extern void MyGoPrint(void *context);
> >> > static inline void myprint(struct dt *a1) {
> >> > MyGoPrint(a1->context);
> >> > }
> >> > */
> >> > import "C"
> >> > import (
> >> > "context"
> >> > "runtime/cgo"
> >> > "unsafe"
> >> > )
> >> >
> >> > //export MyGoPrint
> >> > func MyGoPrint(context unsafe.Pointer) {
> >> > h := *(*cgo.Handle)(context)
> >> > val := h.Value().(accessTokenCB)
> >> > println(val.id)
> >> > h.Delete()
> >> > }
> >> >
> >> > type At struct {
> >> > Tok string
> >> > }
> >> >
> >> > type accessTokenCB struct {
> >> > ctx context.Context
> >> > callback func(context.Context, *At) error
> >> > id uint64
> >> > ctoken *C.char
> >> > cprivateKey *C.char
> >> > }
> >> >
> >> > func getH() cgo.Handle {
> >> > cb := func(ctx context.Context, tok *At) error {
> >> > tok.Tok = "123"
> >> > return nil
> >> > }
> >> > val := accessTokenCB{callback: cb, ctx: context.Background(), id: 32,
> ctoken: nil, cprivateKey: nil}
> >> > h := cgo.NewHandle(val)
> >> > return h
> >> >
> >> > }
> >> >
> >> > var h cgo.Handle
> >> >
> >> > func main() {
> >> > var h cgo.Handle // commenting this line runs the program
> successfully else it panics. (cgo argument has Go pointer to unpinned Go
> pointer)
> >> > h = getH()
> >> > var poolCt C.dt
> >> > poolCt.context = unsafe.Pointer()
> >> > C.myprint()
> >> > // Output: 32
> >> > }
> >>
> >> You aren't following the pattern shown at
> >> https://pkg.go.dev/runtime/cgo#Handle. Pass the cgo.Handle value to C
> >> code, not the address of the cgo.Handle value. Catch the cgo.Handle
> >> value as a uintptr_t in C. The point of using cgo.Handle is to avoid
> >> difficulties passing pointers between Go and C. When you pass a
> >> pointer to a cgo.Handle, you just get those difficulties back again.
> >>
> >> 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/39afbb8b-8361-40a2-967f-0f462ef45994n%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/CAHJvL%3DYoTFAZ4o8Ep7%2Bgt7B5R82QY9JLEpCCqsBbFezHFHtdWg%40mail.gmail.com.


Re: [go-nuts] using runtime cgo.Handle passing struct types

2024-05-18 Thread Ian Lance Taylor
On Thu, May 16, 2024 at 12:57 AM Pavan  wrote:
>
> Thanks . Yes it works when C API takes uintptr_t. In my case, the C API 
> expects void * which i can not change, so I was trying to make it work with 
> the variant example stated above.

In C, unlike Go, you can convert between void* and uintptr_t.  When
using cgo, one approach is a little wrapper function in the cgo
comment that takes a uintptr_t and calls the real function with a
conversion to void*.

Ian

> On Thursday, May 16, 2024 at 5:28:55 AM UTC+5:30 Ian Lance Taylor wrote:
>>
>> On Tue, May 14, 2024 at 10:37 PM Pavan  wrote:
>> >
>> > I need to pass value of struct type, which has C strings and functions to 
>> > C function as void* argument. C layer would provide this struct type data 
>> > back to go function. Below is the sample program. It panics if the handle 
>> > used is returned from getH function. It works fine if the handle is 
>> > global. Can the handle be dynamically returned from getH and make it work. 
>> > Please correct if i missed something..
>> >
>> >
>> >
>> > package main
>> >
>> > /*
>> > struct dt {
>> > void *context;
>> > };
>> > typedef struct dt dt;
>> >
>> > extern void MyGoPrint(void *context);
>> > static inline void myprint(struct dt *a1) {
>> > MyGoPrint(a1->context);
>> > }
>> > */
>> > import "C"
>> > import (
>> > "context"
>> > "runtime/cgo"
>> > "unsafe"
>> > )
>> >
>> > //export MyGoPrint
>> > func MyGoPrint(context unsafe.Pointer) {
>> > h := *(*cgo.Handle)(context)
>> > val := h.Value().(accessTokenCB)
>> > println(val.id)
>> > h.Delete()
>> > }
>> >
>> > type At struct {
>> > Tok string
>> > }
>> >
>> > type accessTokenCB struct {
>> > ctx context.Context
>> > callback func(context.Context, *At) error
>> > id uint64
>> > ctoken *C.char
>> > cprivateKey *C.char
>> > }
>> >
>> > func getH() cgo.Handle {
>> > cb := func(ctx context.Context, tok *At) error {
>> > tok.Tok = "123"
>> > return nil
>> > }
>> > val := accessTokenCB{callback: cb, ctx: context.Background(), id: 32, 
>> > ctoken: nil, cprivateKey: nil}
>> > h := cgo.NewHandle(val)
>> > return h
>> >
>> > }
>> >
>> > var h cgo.Handle
>> >
>> > func main() {
>> > var h cgo.Handle // commenting this line runs the program successfully 
>> > else it panics. (cgo argument has Go pointer to unpinned Go pointer)
>> > h = getH()
>> > var poolCt C.dt
>> > poolCt.context = unsafe.Pointer()
>> > C.myprint()
>> > // Output: 32
>> > }
>>
>> You aren't following the pattern shown at
>> https://pkg.go.dev/runtime/cgo#Handle. Pass the cgo.Handle value to C
>> code, not the address of the cgo.Handle value. Catch the cgo.Handle
>> value as a uintptr_t in C. The point of using cgo.Handle is to avoid
>> difficulties passing pointers between Go and C. When you pass a
>> pointer to a cgo.Handle, you just get those difficulties back again.
>>
>> 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/39afbb8b-8361-40a2-967f-0f462ef45994n%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/CAOyqgcXiL6%2Bm_HtF0SYuExy2Bu9_o%2B3pVAt-FCG3WX05zUOb1A%40mail.gmail.com.


[go-nuts] Re: replacement for filepath.HasPrefix?

2024-05-16 Thread peterGo

Jochen,

"the first step is to define exactly what the function should do."

path/filepath: fix HasPrefix #18358
https://github.com/golang/go/issues/18358#issuecomment-497728574

Peter
On Thursday, May 16, 2024 at 7:15:45 AM UTC-4 Jochen Voss wrote:

> Dear all,
>
> filepath.HasPrefix is deprecated, because it doesn't alway work.  What 
> would be a replacement for this function, which at least respects path 
> boundaries, and maybe also ignores case when needed?
>
> All the best,
> Jochen
>
>

-- 
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/70b47126-1b97-4ef8-b8d0-90e8b6ede058n%40googlegroups.com.


[go-nuts] replacement for filepath.HasPrefix?

2024-05-16 Thread Jochen Voss
Dear all,

filepath.HasPrefix is deprecated, because it doesn't alway work.  What 
would be a replacement for this function, which at least respects path 
boundaries, and maybe also ignores case when needed?

All the best,
Jochen

-- 
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/4cca691c-ab0a-4081-9e60-2fa0b2155f62n%40googlegroups.com.


Re: [go-nuts] using runtime cgo.Handle passing struct types

2024-05-16 Thread Pavan
Thanks . Yes it works when C API takes uintptr_t. In my case, the C API 
expects void * which i can not change, so I was trying to make it work with 
the variant example stated above. 

On Thursday, May 16, 2024 at 5:28:55 AM UTC+5:30 Ian Lance Taylor wrote:

> On Tue, May 14, 2024 at 10:37 PM Pavan  wrote:
> >
> > I need to pass value of struct type, which has C strings and functions 
> to C function as void* argument. C layer would provide this struct type 
> data back to go function. Below is the sample program. It panics if the 
> handle used is returned from getH function. It works fine if the handle is 
> global. Can the handle be dynamically returned from getH and make it work. 
> Please correct if i missed something..
> >
> >
> >
> > package main
> >
> > /*
> > struct dt {
> > void *context;
> > };
> > typedef struct dt dt;
> >
> > extern void MyGoPrint(void *context);
> > static inline void myprint(struct dt *a1) {
> > MyGoPrint(a1->context);
> > }
> > */
> > import "C"
> > import (
> > "context"
> > "runtime/cgo"
> > "unsafe"
> > )
> >
> > //export MyGoPrint
> > func MyGoPrint(context unsafe.Pointer) {
> > h := *(*cgo.Handle)(context)
> > val := h.Value().(accessTokenCB)
> > println(val.id)
> > h.Delete()
> > }
> >
> > type At struct {
> > Tok string
> > }
> >
> > type accessTokenCB struct {
> > ctx context.Context
> > callback func(context.Context, *At) error
> > id uint64
> > ctoken *C.char
> > cprivateKey *C.char
> > }
> >
> > func getH() cgo.Handle {
> > cb := func(ctx context.Context, tok *At) error {
> > tok.Tok = "123"
> > return nil
> > }
> > val := accessTokenCB{callback: cb, ctx: context.Background(), id: 32, 
> ctoken: nil, cprivateKey: nil}
> > h := cgo.NewHandle(val)
> > return h
> >
> > }
> >
> > var h cgo.Handle
> >
> > func main() {
> > var h cgo.Handle // commenting this line runs the program successfully 
> else it panics. (cgo argument has Go pointer to unpinned Go pointer)
> > h = getH()
> > var poolCt C.dt
> > poolCt.context = unsafe.Pointer()
> > C.myprint()
> > // Output: 32
> > }
>
> You aren't following the pattern shown at
> https://pkg.go.dev/runtime/cgo#Handle. Pass the cgo.Handle value to C
> code, not the address of the cgo.Handle value. Catch the cgo.Handle
> value as a uintptr_t in C. The point of using cgo.Handle is to avoid
> difficulties passing pointers between Go and C. When you pass a
> pointer to a cgo.Handle, you just get those difficulties back again.
>
> 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/39afbb8b-8361-40a2-967f-0f462ef45994n%40googlegroups.com.


Re: [go-nuts] using runtime cgo.Handle passing struct types

2024-05-15 Thread Ian Lance Taylor
On Tue, May 14, 2024 at 10:37 PM Pavan  wrote:
>
> I need to pass value of struct type, which has C strings and functions to C 
> function as void* argument.  C layer would provide this struct type data back 
> to go function. Below is the sample program. It panics if the handle used is 
> returned from getH function. It works fine if the handle is global. Can the 
> handle be dynamically returned from getH and make it work. Please correct if 
> i missed something..
>
>
>
> package main
>
> /*
> struct dt {
>   void *context;
> };
> typedef struct dt dt;
>
> extern void MyGoPrint(void *context);
> static inline void myprint(struct dt *a1) {
> MyGoPrint(a1->context);
> }
> */
> import "C"
> import (
> "context"
> "runtime/cgo"
> "unsafe"
> )
>
> //export MyGoPrint
> func MyGoPrint(context unsafe.Pointer) {
> h := *(*cgo.Handle)(context)
> val := h.Value().(accessTokenCB)
> println(val.id)
> h.Delete()
> }
>
> type At struct {
> Tok string
> }
>
> type accessTokenCB struct {
> ctx context.Context
> callbackfunc(context.Context, *At) error
> id  uint64
> ctoken  *C.char
> cprivateKey *C.char
> }
>
> func getH() cgo.Handle {
> cb := func(ctx context.Context, tok *At) error {
> tok.Tok = "123"
> return nil
> }
> val := accessTokenCB{callback: cb, ctx: context.Background(), id: 32, ctoken: 
> nil, cprivateKey: nil}
> h := cgo.NewHandle(val)
> return h
>
> }
>
> var h cgo.Handle
>
> func main() {
> var h cgo.Handle // commenting this line runs the program successfully else 
> it panics. (cgo argument has Go pointer to unpinned Go pointer)
> h = getH()
> var poolCt C.dt
> poolCt.context = unsafe.Pointer()
> C.myprint()
> // Output: 32
> }

You aren't following the pattern shown at
https://pkg.go.dev/runtime/cgo#Handle.  Pass the cgo.Handle value to C
code, not the address of the cgo.Handle value.  Catch the cgo.Handle
value as a uintptr_t in C.  The point of using cgo.Handle is to avoid
difficulties passing pointers between Go and C.  When you pass a
pointer to a cgo.Handle, you just get those difficulties back again.

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/CAOyqgcXthcBN6-NP4n1ihCU2HW1YSwNSDdEd0QDft_SP6ULBHw%40mail.gmail.com.


Re: [go-nuts] Re: programmatic way to find if application go binary is built with -cover flag ?

2024-05-15 Thread 肖华冬
There is possibly a way to do this by parsing strings in the binary. Because when -cover is enabled, go will insert instrumentation statements into the source code, thus the resulting binary would contain these info.On May 14, 2024, at 17:19, Akash Kumar  wrote:I unable to find a flag from corresponds to -cover in the result returned from debug.buildInfoOn Monday, May 13, 2024 at 10:51:33 PM UTC+5:30 Tamás Gulácsi wrote:runtime/debug.ReadBuildInfo is a good source of truth:$ strings bin/godeb|grep '^build\s'build   -buildmode=exebuild   -compiler=gcbuild   DefaultGODEBUG=httplaxcontentlength=1,httpmuxgo121=1,panicnil=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1build   CGO_ENABLED=1build   CGO_CFLAGS=build   CGO_CPPFLAGS=build   CGO_CXXFLAGS=build   CGO_LDFLAGS=build   GOARCH=amd64build   GOOS=linuxbuild   GOAMD64=v1build   -buildmode=exebuild   -compiler=gcbuild   DefaultGODEBUG=httplaxcontentlength=1,httpmuxgo121=1,panicnil=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1build   CGO_ENABLED=1build   CGO_CFLAGS=build   CGO_CPPFLAGS=build   CGO_CXXFLAGS=build   CGO_LDFLAGS=build   GOARCH=amd64build   GOOS=linuxbuild   GOAMD64=v1Akash Kumar a következőt írta (2024. május 13., hétfő, 18:42:30 UTC+2):I am writing an external go program that will take the path to another go binary as argument, and checks if the binary was built with cover flag.`debug.ReadBuildInfo()` is meant for getting build info embedded in the running binary as > ReadBuildInfo returns the build information embedded in the running binary On Monday, May 13, 2024 at 6:37:46 PM UTC+5:30 Zxilly Chou wrote:try debug.ReadBuildInfo(), then iterate the pair in the buildinfo.Settings在2024年5月13日星期一 UTC+8 20:56:51 写道:Is there a way in go to find whether a go binary is built with -cover flag ?



-- 
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/9fda396a-b79e-4b9e-9bc0-13a9cef2c921n%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/50BA2D36-E4D4-4BE1-9117-A7BA15E17446%40gmail.com.


[go-nuts] SFTPGo 2.6.0 Released

2024-05-15 Thread Nicola Murino
Hi all,

I'm pleased to announce SFTPGo 2.6.0!

SFTPGo is an event-driven file transfer solution. It support multiple 
protocols (SFTP, SCP, FTP/S, WebDAV, HTTP/S) and multiple storage backends.

Main new features:

- Rewritten WebClient and WebAdmin UIs: we hope you find these new user 
interfaces more modern and easier to use. They also include a dark mode.
- Documentation moved to sftpgo.github.io.
- Experimental support for internazionalization.
- Time-based access restrictions.
- Allow to require password change and two-factor authentication also for 
admins, before it was possible only for users.
- Allow to automatically disable or delete inactive users.

Full release notes:

https://github.com/drakkan/sftpgo/releases/tag/v2.6.0

Commercial support:

https://sftpgo.com/#pricing

Yours sincerely,
Nicola

-- 
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/16faf97a-e696-4aa4-b223-980ae7914c3cn%40googlegroups.com.


Re: [go-nuts] Re: raw bit types without arithmetic

2024-05-15 Thread 'Kevin Chowski' via golang-nuts
By the way - I definitely don't feel strongly about this, and I am just 
guessing that it's more likely to support new operators for existing types 
than it is to create new built-in types. I think bitsN types are fine, 
although again I don't know if I'd personally ever use them. But I am 
enjoying the conversation so far, so here are some more thoughts I had :)

I think the fact that you can compare huge byte arrays with == means that 
there is some desire inside the Go compiler team to support variable-length 
operations based on the type regardless of whether it can be "efficiently" 
compiled on all systems, so I don't see that aspect as being inconsistent 
with the existing language. As another example that is more dynamic (and 
therefore even more "surprising"), doing `string1 == string2` might take a 
very long time if string1 and string2 have the same contents and have a 
huge length. To me, those seem the same (or worse) as accepting that 
`byteArray1 | byteArray2` might take a long time if they are statically 
known to be long byte arrays; it seems pretty straightforward that doing an 
operation on `[N]byte` will be faster than an operation on `[N*1000]byte` 
and I think people will intuit that.

As for whether it would be weird to support some operations on some arrays 
but not others, technically this is already true: you can't use == on an 
array when the elements are not comparable. And people seem OK with that 
:)   there are also some other special cases for the byte type, e.g. you 
can convert a byte slice into a string (and viceversa) but not with an int 
slice. I personally don't see this inconsistency as an issue or learning 
impediment, but I can understand that someone may disagree with my 
perspective here.

(Another idea: how about both? e.g. if we had both `bitsN` types AND the 
ability to use bitwise operations on arrays of (only) bitsN types? Or 
something along those lines. That would open up the ability to express some 
SIMD operations in otherwise extremely idiomatic-looking code, while also 
supporting the smaller-scale operations you are suggesting.)

On Tuesday, May 14, 2024 at 12:27:01 PM UTC-6 jimmy frasche wrote:

> Arrays are arrays regardless of what they're arrays of. So it would be
> strange for arrays of certain things to have properties that other
> arrays don't have and bitwise ops don't make sense for arrays of, say,
> strings.
>
> Also some processors support these sizes natively but wouldn't support
> a [4096]byte natively. On processors that don't support all or some of
> these sizes it would need to fake it by doing m operations† but that's
> bounded and if, for example, the target processor supports 256 bit but
> not 512 bit values it can use two 256 ORs instead of four 64 bit ORs.
> Maybe that could be made to work in general and if so that would be
> great but it's not the only benefit of these types.
>
> † except for shifts, those would have to deal with carries. That may
> be a problem, but I think even then it should be fast enough to not be
> an issue the way faking div or something very expensive like that
> would be.
>
> On Mon, May 13, 2024 at 8:41 PM Kevin Chowski  wrote:
> >
> > Sorry, sent too early.
> >
> > Obviously that doesn't support the bitwise type conversion you 
> mentioned; I don't really have an opinion on that one, I don't really 
> convert from float to bits very often.
> >
> > It seems like the compiler optimizations you mention could happen with 
> or without these extra types, if such optimizations just worked on byte 
> arrays in general.
> >
> > On Monday, May 13, 2024 at 9:38:36 PM UTC-6 Kevin Chowski wrote:
> >>
> >> How about just allowing bitwise operations on byte arrays (of the same 
> length)?
> >>
> >> On Monday, May 13, 2024 at 2:51:19 PM UTC-6 jimmy frasche wrote:
> >>>
> >>> I'm not 100% sure if this is a good idea but it's been knocking around
> >>> in my head all week so I thought I'd share in case it has any merit:
> >>>
> >>> Introduce bitsN types for N=8, 16, 32, 64, 128, 256, and 512.
> >>>
> >>> These are similar to uintN but they are unordered and have no
> >>> arithmetic operations defined.
> >>>
> >>> They only have literals, comparison, and bitwise operations.
> >>> (fmt.Print and friends should render them in hex by default.)
> >>>
> >>> Conversions between the numeric types and the bitN are allowed, which,
> >>> for example, let's us rewrite math.Float64bits as simply
> >>>
> >>> func Float64bits(f float64) uint64 {
> >>> return uint64(bits64(f))
> >>> }
> >>>
> >>> Since there are no arithmetic operations, the 128+ sizes should be
> >>> fairly efficient to fake on architectures without special
> >>> instructions/registers.
> >>>
> >>> Potential uses:
> >>>
> >>> UUIDs could be stored as a bits128 instead of a [2]uint64 or [16]byte.
> >>>
> >>> SIMD vectors could be created and stored easily, even if they need
> >>> assembly to operate on them efficiently.
> >>>
> >>> Same for int128/uint128 values or 

[go-nuts] Runtime error with golang 1.22.x

2024-05-15 Thread Masanori Matsumoto
Since updating golang to v1.22, I'm getting errors in my tests using 
pact-go.

So I raised issue to the pact-go repository:
https://github.com/pact-foundation/pact-go/issues/402

The error is as follows:
---
runtime: g 19: unexpected return pc for 
github.com/pact-foundation/pact-go/v2/internal/native.(*Interaction).GivenWithParameter
 
called from 0xe18a8f
stack: frame={sp:0xcb1bf8, fp:0xcb1d28} 
stack=[0xcb,0xcb2000)
...
fatal error: unknown caller pc
---

It only happens on amd64 when you run the test with the `-race` option.

My concern is that this is a golang issue, not pact-go, and I wonder if I 
should create a golang issue.

-- 
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/788005f9-5952-43cd-85dc-75f4c0ecfafcn%40googlegroups.com.


[go-nuts] tls.VerifyClientCertIfGiven

2024-05-15 Thread Jochen Voss
Hello,

In a server I use tls.Config.ClientAuth=tls.VerifyClientCertIfGiven.
If then a client manages to connect and I can see a certificate in
http.Request.TLS.PeerCertificates, does this just mean that the client
has the certificate, or does this also prove that the client has the 
associated private key?

Many thanks,
Jochen

-- 
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/7003fa55-2436-4b85-a5ab-eed2d54430d0n%40googlegroups.com.


[go-nuts] using runtime cgo.Handle passing struct types

2024-05-14 Thread Pavan
Hi, 
I need to pass value of struct type, which has C strings and functions to C 
function as void* argument.  C layer would provide this struct type data 
back to go function. Below is the sample program. It panics if the handle 
used is returned from getH function. It works fine if the handle is global. 
Can the handle be dynamically returned from getH and make it work. Please 
correct if i missed something..



package main

/*
struct dt {
  void *context;
};
typedef struct dt dt;

extern void MyGoPrint(void *context);
static inline void myprint(struct dt *a1) {
MyGoPrint(a1->context);
}
*/
import "C"
import (
"context"
"runtime/cgo"
"unsafe"
)

//export MyGoPrint
func MyGoPrint(context unsafe.Pointer) {
h := *(*cgo.Handle)(context)
val := h.Value().(accessTokenCB)
println(val.id)
h.Delete()
}

type At struct {
Tok string
}

type accessTokenCB struct {
ctx context.Context
callbackfunc(context.Context, *At) error
id  uint64
ctoken  *C.char
cprivateKey *C.char
}

func getH() cgo.Handle {
cb := func(ctx context.Context, tok *At) error {
tok.Tok = "123"
return nil
}
val := accessTokenCB{callback: cb, ctx: context.Background(), id: 32, 
ctoken: nil, cprivateKey: nil}
h := cgo.NewHandle(val)
return h

}

var h cgo.Handle

func main() {
var h cgo.Handle // commenting this line runs the program successfully else 
it panics. (cgo argument has Go pointer to unpinned Go pointer)
h = getH()
var poolCt C.dt
poolCt.context = unsafe.Pointer()
C.myprint()
// Output: 32
}

-- 
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/1b34c3ba-cf4b-4663-b509-5ef84e9600c1n%40googlegroups.com.


Re: [go-nuts] Re: raw bit types without arithmetic

2024-05-14 Thread jimmy frasche
Arrays are arrays regardless of what they're arrays of. So it would be
strange for arrays of certain things to have properties that other
arrays don't have and bitwise ops don't make sense for arrays of, say,
strings.

Also some processors support these sizes natively but wouldn't support
a [4096]byte natively. On processors that don't support all or some of
these sizes it would need to fake it by doing m operations† but that's
bounded and if, for example, the target processor supports 256 bit but
not 512 bit values it can use two 256 ORs instead of four 64 bit ORs.
Maybe that could be made to work in general and if so that would be
great but it's not the only benefit of these types.

† except for shifts, those would have to deal with carries. That may
be a problem, but I think even then it should be fast enough to not be
an issue the way faking div or something very expensive like that
would be.

On Mon, May 13, 2024 at 8:41 PM Kevin Chowski  wrote:
>
> Sorry, sent too early.
>
> Obviously that doesn't support the bitwise type conversion you mentioned; I 
> don't really have an opinion on that one, I don't really convert from float 
> to bits very often.
>
> It seems like the compiler optimizations you mention could happen with or 
> without these extra types, if such optimizations just worked on byte arrays 
> in general.
>
> On Monday, May 13, 2024 at 9:38:36 PM UTC-6 Kevin Chowski wrote:
>>
>> How about just allowing bitwise operations on byte arrays (of the same 
>> length)?
>>
>> On Monday, May 13, 2024 at 2:51:19 PM UTC-6 jimmy frasche wrote:
>>>
>>> I'm not 100% sure if this is a good idea but it's been knocking around
>>> in my head all week so I thought I'd share in case it has any merit:
>>>
>>> Introduce bitsN types for N=8, 16, 32, 64, 128, 256, and 512.
>>>
>>> These are similar to uintN but they are unordered and have no
>>> arithmetic operations defined.
>>>
>>> They only have literals, comparison, and bitwise operations.
>>> (fmt.Print and friends should render them in hex by default.)
>>>
>>> Conversions between the numeric types and the bitN are allowed, which,
>>> for example, let's us rewrite math.Float64bits as simply
>>>
>>> func Float64bits(f float64) uint64 {
>>> return uint64(bits64(f))
>>> }
>>>
>>> Since there are no arithmetic operations, the 128+ sizes should be
>>> fairly efficient to fake on architectures without special
>>> instructions/registers.
>>>
>>> Potential uses:
>>>
>>> UUIDs could be stored as a bits128 instead of a [2]uint64 or [16]byte.
>>>
>>> SIMD vectors could be created and stored easily, even if they need
>>> assembly to operate on them efficiently.
>>>
>>> Same for int128/uint128 values or even for more exotic numeric types
>>> like the various float16 definitions or "floating slash" rationals.
>>>
>>> It would also be handy to have larger bitsets that are easy to work with.
>
> --
> 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/1f0329c1-8b82-4683-999e-62b9a046c0a8n%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/CANG3jXLdcRs9AMS_xE15EEgqKmYFRgexgGBfpSxVA-%3D60A69sQ%40mail.gmail.com.


Re: [go-nuts] Bitmask is slower than modulo calculation

2024-05-14 Thread 'Keith Randall' via golang-nuts
Your test is benchmarking int->any conversions more than it is testing the 
underlying modulo/mask difference.
When you pass an integer to Enqueue, it is converted to any, which 
(usually) involves an allocation. That will swamp the cost of any single 
arithmetic operation.

There are a few ways to fix it. Probably the simplest is to make your ring 
buffers generic on the element type.
You could also fix the benchmark, by precomputing the any-typed elements 
you're going to enqueue before starting the timer.

When you get a surprising benchmark result, always run the benchmark with 
profiling on (-cpuprofile) and look at the resulting profile. This is a 
case where it would be obvious what the problem is.
On Sunday, May 12, 2024 at 10:18:38 PM UTC-7 robert engels wrote:

> Hi. This is still not correct. Use the “for.. in b.N” as discussed in the 
> blog in order to understand the per op difference - which will be more 
> accurate for a microbenchmark timing,
>
> But, if you really want to make a case that bit mask is slower than mod, 
> then a simpler test would be better - you can do these ops on in loop using 
> b.N to time the difference.
>
>
>
> On May 12, 2024, at 8:28 PM, Yuta MIYAKE  wrote:
>
> Thank you. 
>
> This is benchstat result. new test code follows:
>
> ❯ go test -test.bench BenchmarkTestSingleModulo -count=10 -cpu=1 > 
> modulo.txt
> ❯ go test -test.bench BenchmarkTestSingleBitMask -count=10 -cpu=1 > 
> bitmask.txt
> ❯ benchstat modulo.txt bitmask.txt
> goos: darwin
> goarch: arm64
> pkg: ringbuffer
>   │ modulo.txt │bitmask.txt│
>   │   sec/op   │   sec/opvs base   │
> TestSingleModulo6.648 ± 1%
> TestSingleBitMask6.694 ± 5%
> geomean 6.6486.694   ? ¹ ²
>
>
> new test code:
>
> const BufferSize = 2 * 1024 * 1024
>
> func benchmarkSingle(rb RingBuffer) {
>
>
> total := 50
> for i := 0; i < total; i++ {
> for j := 0; j < 1000; j++ {
> rb.Enqueue(j)
> }
> for j := 0; j < 1000; j++ {
> rb.Dequeue()
> }
> }
> }
>
>
> func BenchmarkTestSingleModulo(b *testing.B) {
> rb := NewRingBuffer0(BufferSize)
> b.ResetTimer()
> benchmarkSingle(rb)
> }
>
> func BenchmarkTestSingleBitMask(b *testing.B) {
> rb := NewRingBuffer1(BufferSize)
> b.ResetTimer()
> benchmarkSingle(rb)
> }
>
> On Monday, May 13, 2024 at 8:20:05 AM UTC+9 robert engels wrote:
>
>> Use the Go benchmarking facilities, see 
>> https://dave.cheney.net/2013/06/30/how-to-write-benchmarks-in-go
>>
>> On May 11, 2024, at 9:57 PM, leon  wrote:
>>
>> I'm trying to prove an optimization technique for ring buffer is 
>> effective. One of the technique is using bitmask instead of modulo to 
>> calculate a wrap around. However, in my environment, modulo is slightly 
>> faster in a test where 1 billion items are enqueued /dequeued by a single 
>> goroutine. What do you think could be the cause? 
>>
>> Full code:
>> https://go.dev/play/p/H933oqrhPI-
>>
>> Environment:
>> * go version go1.21.4 darwin/arm64
>> * Apple M1 Pro
>>
>> RingBuffer with modulo:
>> ```
>> type RingBuffer0 struct {
>> writeIdx uint64
>> readIdx  uint64
>> buffers  []any
>> size uint64
>> }
>>
>> func NewRingBuffer0(size uint64) *RingBuffer0 {
>> rb := {}
>> rb.init(size)
>> return rb
>> }
>>
>> func (rb *RingBuffer0) init(size uint64) {
>> rb.buffers = make([]any, size)
>> rb.size = size
>> }
>>
>> func (rb *RingBuffer0) Enqueue(item any) error {
>> if rb.writeIdx-rb.readIdx == rb.size {
>> return ErrBufferFull
>> }
>> rb.buffers[rb.writeIdx%rb.size] = item
>> rb.writeIdx++
>> return nil
>> }
>>
>> func (rb *RingBuffer0) Dequeue() (any, error) {
>> if rb.writeIdx == rb.readIdx {
>> return nil, ErrBufferEmpty
>> }
>> item := rb.buffers[rb.readIdx%rb.size]
>> rb.readIdx++
>> return item, nil
>> }
>> ```
>>
>> RingBuffer with bitmask:
>> change each module calculation to the code below
>> * rb.buffers[rb.writeIdx&(rb.size-1)] = item
>> * item := rb.buffers[rb.readIdx&(rb.size-1)]
>>
>> Test:
>> func TestSingle(rb RingBuffer) {
>> start := time.Now()
>> total := 50
>> for i := 0; i < total; i++ {
>> for j := 0; j < 1000; j++ {
>> rb.Enqueue(j)
>> }
>> for j := 0; j < 1000; j++ {
>> rb.Dequeue()
>> }
>> }
>> end := time.Now()
>> count := total * 2000
>> duration := end.Sub(start).Milliseconds()
>> fmt.Printf("%d ops in %d ms\n", count, duration)
>> }
>>
>>
>> -- 
>> 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/b9c4d2e0-4ab4-4d27-9359-abd8c090ae33n%40googlegroups.com
>>  
>> 
>> .
>>
>>
>>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" 

[go-nuts] Re: programmatic way to find if application go binary is built with -cover flag ?

2024-05-14 Thread Akash Kumar

I unable to find a flag from corresponds to -cover in the result returned 
from debug.buildInfo
On Monday, May 13, 2024 at 10:51:33 PM UTC+5:30 Tamás Gulácsi wrote:

> runtime/debug.ReadBuildInfo is a good source of truth:
> $ strings bin/godeb|grep '^build\s'
>
> build   -buildmode=exe
> build   -compiler=gc
> build   
> DefaultGODEBUG=httplaxcontentlength=1,httpmuxgo121=1,panicnil=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
> build   CGO_ENABLED=1
> build   CGO_CFLAGS=
> build   CGO_CPPFLAGS=
> build   CGO_CXXFLAGS=
> build   CGO_LDFLAGS=
> build   GOARCH=amd64
> build   GOOS=linux
> build   GOAMD64=v1
> build   -buildmode=exe
> build   -compiler=gc
> build   
> DefaultGODEBUG=httplaxcontentlength=1,httpmuxgo121=1,panicnil=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
> build   CGO_ENABLED=1
> build   CGO_CFLAGS=
> build   CGO_CPPFLAGS=
> build   CGO_CXXFLAGS=
> build   CGO_LDFLAGS=
> build   GOARCH=amd64
> build   GOOS=linux
> build   GOAMD64=v1
>
> Akash Kumar a következőt írta (2024. május 13., hétfő, 18:42:30 UTC+2):
>
>> I am writing an external go program that will take the path to another go 
>> binary as argument, and checks if the binary was built with cover flag.
>>
>> `debug.ReadBuildInfo()` is meant for getting build info embedded in the 
>> running binary as 
>> > ReadBuildInfo returns the build information embedded in the running 
>> binary 
>>
>> On Monday, May 13, 2024 at 6:37:46 PM UTC+5:30 Zxilly Chou wrote:
>>
>>> try debug.ReadBuildInfo(), then iterate the pair in the buildinfo.
>>> Settings
>>>
>>> 在2024年5月13日星期一 UTC+8 20:56:51 写道:
>>>
 Is there a way in go to find whether a go binary is built with -cover 
 flag ?
>>>
>>>

-- 
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/9fda396a-b79e-4b9e-9bc0-13a9cef2c921n%40googlegroups.com.


[go-nuts] Re: raw bit types without arithmetic

2024-05-13 Thread Kevin Chowski
Sorry, sent too early.

Obviously that doesn't support the bitwise type conversion you mentioned; I 
don't really have an opinion on that one, I don't really convert from float 
to bits very often.

It seems like the compiler optimizations you mention could happen with or 
without these extra types, if such optimizations just worked on byte arrays 
in general.

On Monday, May 13, 2024 at 9:38:36 PM UTC-6 Kevin Chowski wrote:

> How about just allowing bitwise operations on byte arrays (of the same 
> length)?
>
> On Monday, May 13, 2024 at 2:51:19 PM UTC-6 jimmy frasche wrote:
>
>> I'm not 100% sure if this is a good idea but it's been knocking around 
>> in my head all week so I thought I'd share in case it has any merit: 
>>
>> Introduce bitsN types for N=8, 16, 32, 64, 128, 256, and 512. 
>>
>> These are similar to uintN but they are unordered and have no 
>> arithmetic operations defined. 
>>
>> They only have literals, comparison, and bitwise operations. 
>> (fmt.Print and friends should render them in hex by default.) 
>>
>> Conversions between the numeric types and the bitN are allowed, which, 
>> for example, let's us rewrite math.Float64bits as simply 
>>
>> func Float64bits(f float64) uint64 { 
>> return uint64(bits64(f)) 
>> } 
>>
>> Since there are no arithmetic operations, the 128+ sizes should be 
>> fairly efficient to fake on architectures without special 
>> instructions/registers. 
>>
>> Potential uses: 
>>
>> UUIDs could be stored as a bits128 instead of a [2]uint64 or [16]byte. 
>>
>> SIMD vectors could be created and stored easily, even if they need 
>> assembly to operate on them efficiently. 
>>
>> Same for int128/uint128 values or even for more exotic numeric types 
>> like the various float16 definitions or "floating slash" rationals. 
>>
>> It would also be handy to have larger bitsets that are easy to work with. 
>>
>

-- 
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/1f0329c1-8b82-4683-999e-62b9a046c0a8n%40googlegroups.com.


[go-nuts] Re: raw bit types without arithmetic

2024-05-13 Thread Kevin Chowski
How about just allowing bitwise operations on byte arrays (of the same 
length)?

On Monday, May 13, 2024 at 2:51:19 PM UTC-6 jimmy frasche wrote:

> I'm not 100% sure if this is a good idea but it's been knocking around
> in my head all week so I thought I'd share in case it has any merit:
>
> Introduce bitsN types for N=8, 16, 32, 64, 128, 256, and 512.
>
> These are similar to uintN but they are unordered and have no
> arithmetic operations defined.
>
> They only have literals, comparison, and bitwise operations.
> (fmt.Print and friends should render them in hex by default.)
>
> Conversions between the numeric types and the bitN are allowed, which,
> for example, let's us rewrite math.Float64bits as simply
>
> func Float64bits(f float64) uint64 {
> return uint64(bits64(f))
> }
>
> Since there are no arithmetic operations, the 128+ sizes should be
> fairly efficient to fake on architectures without special
> instructions/registers.
>
> Potential uses:
>
> UUIDs could be stored as a bits128 instead of a [2]uint64 or [16]byte.
>
> SIMD vectors could be created and stored easily, even if they need
> assembly to operate on them efficiently.
>
> Same for int128/uint128 values or even for more exotic numeric types
> like the various float16 definitions or "floating slash" rationals.
>
> It would also be handy to have larger bitsets that are easy to work with.
>

-- 
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/d0507019-b796-47b6-a4e9-3e407879866cn%40googlegroups.com.


[go-nuts] raw bit types without arithmetic

2024-05-13 Thread jimmy frasche
I'm not 100% sure if this is a good idea but it's been knocking around
in my head all week so I thought I'd share in case it has any merit:

Introduce bitsN types for N=8, 16, 32, 64, 128, 256, and 512.

These are similar to uintN but they are unordered and have no
arithmetic operations defined.

They only have literals, comparison, and bitwise operations.
(fmt.Print and friends should render them in hex by default.)

Conversions between the numeric types and the bitN are allowed, which,
for example, let's us rewrite math.Float64bits as simply

func Float64bits(f float64) uint64 {
return uint64(bits64(f))
}

Since there are no arithmetic operations, the 128+ sizes should be
fairly efficient to fake on architectures without special
instructions/registers.

Potential uses:

UUIDs could be stored as a bits128 instead of a [2]uint64 or [16]byte.

SIMD vectors could be created and stored easily, even if they need
assembly to operate on them efficiently.

Same for int128/uint128 values or even for more exotic numeric types
like the various float16 definitions or "floating slash" rationals.

It would also be handy to have larger bitsets that are easy to work with.

-- 
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/CANG3jX%2B_%3DhjfGEVAaOTToTRHsOVVqTmWQEZz9kzD-uYT0jNosA%40mail.gmail.com.


[go-nuts] Re: programmatic way to find if application go binary is built with -cover flag ?

2024-05-13 Thread Tamás Gulácsi
runtime/debug.ReadBuildInfo is a good source of truth:
$ strings bin/godeb|grep '^build\s'

build   -buildmode=exe
build   -compiler=gc
build   
DefaultGODEBUG=httplaxcontentlength=1,httpmuxgo121=1,panicnil=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
build   CGO_ENABLED=1
build   CGO_CFLAGS=
build   CGO_CPPFLAGS=
build   CGO_CXXFLAGS=
build   CGO_LDFLAGS=
build   GOARCH=amd64
build   GOOS=linux
build   GOAMD64=v1
build   -buildmode=exe
build   -compiler=gc
build   
DefaultGODEBUG=httplaxcontentlength=1,httpmuxgo121=1,panicnil=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
build   CGO_ENABLED=1
build   CGO_CFLAGS=
build   CGO_CPPFLAGS=
build   CGO_CXXFLAGS=
build   CGO_LDFLAGS=
build   GOARCH=amd64
build   GOOS=linux
build   GOAMD64=v1

Akash Kumar a következőt írta (2024. május 13., hétfő, 18:42:30 UTC+2):

> I am writing an external go program that will take the path to another go 
> binary as argument, and checks if the binary was built with cover flag.
>
> `debug.ReadBuildInfo()` is meant for getting build info embedded in the 
> running binary as 
> > ReadBuildInfo returns the build information embedded in the running 
> binary 
>
> On Monday, May 13, 2024 at 6:37:46 PM UTC+5:30 Zxilly Chou wrote:
>
>> try debug.ReadBuildInfo(), then iterate the pair in the buildinfo.
>> Settings
>>
>> 在2024年5月13日星期一 UTC+8 20:56:51 写道:
>>
>>> Is there a way in go to find whether a go binary is built with -cover 
>>> flag ?
>>
>>

-- 
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/aa819a76-2c8e-4b9a-b37d-92abd3ff2877n%40googlegroups.com.


Re: [go-nuts] Re: VCS Stamping - How To Use It? How to debug failures?

2024-05-13 Thread Adam Kaplan
I forgot to add one more detail - the go-toolset image defaults to running
as user "default" (UID 1001).

Adding `USER root` right after the `FROM` declaration is another way to
work around the issue I described, but from a security perspective I would
advise against it.

On Mon, May 13, 2024 at 12:24 PM Adam Kaplan  wrote:

> Great suggestion Jason - adding `git status` took me in a very unexpected
> direction, and ultimately a solution.
>
> tl;dr if your build's base container image does not use root/uid 0, git
> commands won't work unless you add the `--chown=` flag to your `COPY`
> instruction. Go builds need this if you want `-buildvcs=auto|true` to
> succeed.
>
> When I changed my build command to `RUN git status && go build` in the
> Dockerfile, I got the following output:
>
> ```
> $ podman build -t localhost/sclorg/hello-openshift:latest .
> [1/2] STEP 1/3: FROM registry.redhat.io/ubi9/go-toolset:1.20.12 AS builder
> [1/2] STEP 2/3: COPY . .
> --> 10a13b463199
> [1/2] STEP 3/3: RUN git status && go build -o /tmp/hello
> fatal: detected dubious ownership in repository at '/opt/app-root/src'
> To add an exception for this directory, call:
>
> git config --global --add safe.directory /opt/app-root/src
> Error: building at STEP "RUN git status && go build -o /tmp/hello": while
> running runtime: exit status 128
> ```
>
> This was a new and different error message for me - but same exit code as
> before. A quick Google search brought me to CVE-2022-24765 [1], whose fix
> introduced this "dubious ownership" message/protection.
>
> I was finally able to piece everything together with a few more debug
> builds and internet searches:
>
> 1. On Fedora 39, podman runs in "rootless" mode. Files owned by me show up
> as owned by "root" in containers.
> 2. For Linux containers, `COPY` commands in Dockerfiles copy files as
> UID/GID 0 unless the `--chown` flag is passed. [2].
> 3. As part of the mitigation for CVE-2022-24765, git commands will succeed
> only if:
>   a. The `.git` directory is owned by the same user executing the `.git`
> command OR
>   b. The parent directory marked "safe" in the git configuration.
>
> Using `COPY --chown=default . .` instead of `COPY . .` works for the UBI
> go-toolset image referenced previously in this thread. Your results may
> vary using other golang "builder" images.
>
> [1] https://github.blog/2022-04-12-git-security-vulnerability-announced/
> [2] https://docs.docker.com/reference/dockerfile/#copy---chown---chmod
>
>
> On Sat, May 11, 2024 at 11:43 AM Jason E. Aten  wrote:
>
>> > how can developers debug and find the root cause?
>>
>> If it was me, I would start by going into the container (whatever the
>> podman equivalent of docker exec -it containernumber bash) and try to run
>> 'git status' or 'git log' and see why the git query is giving an error.
>> You could also try strace to see what git command specifically is being
>> execed, then try to get that command working manually.
>>
>> --
>> You received this message because you are subscribed to a topic in the
>> Google Groups "golang-nuts" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/golang-nuts/LZbM2WlZoJM/unsubscribe.
>> To unsubscribe from this group and all its topics, 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/ca680397-1497-4b3a-83ce-301c936308c1n%40googlegroups.com
>> 
>> .
>>
>
>
> --
>
> Adam Kaplan
>
> He/Him
>
> Principal Software Engineer
>
> Red Hat 
>
> 100 E. Davie Street
>
> adam.kap...@redhat.comT: 1-919-754-4843
> 
>
>

-- 

Adam Kaplan

He/Him

Principal Software Engineer

Red Hat 

100 E. Davie Street

adam.kap...@redhat.comT: 1-919-754-4843


-- 
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/CADmLb%2Bkfvd%3DYbnzW1QzgkTe93UUkOfW9TtCBf168DEi8YxWJ1w%40mail.gmail.com.


Re: [go-nuts] Re: VCS Stamping - How To Use It? How to debug failures?

2024-05-13 Thread Adam Kaplan
Great suggestion Jason - adding `git status` took me in a very unexpected
direction, and ultimately a solution.

tl;dr if your build's base container image does not use root/uid 0, git
commands won't work unless you add the `--chown=` flag to your `COPY`
instruction. Go builds need this if you want `-buildvcs=auto|true` to
succeed.

When I changed my build command to `RUN git status && go build` in the
Dockerfile, I got the following output:

```
$ podman build -t localhost/sclorg/hello-openshift:latest .
[1/2] STEP 1/3: FROM registry.redhat.io/ubi9/go-toolset:1.20.12 AS builder
[1/2] STEP 2/3: COPY . .
--> 10a13b463199
[1/2] STEP 3/3: RUN git status && go build -o /tmp/hello
fatal: detected dubious ownership in repository at '/opt/app-root/src'
To add an exception for this directory, call:

git config --global --add safe.directory /opt/app-root/src
Error: building at STEP "RUN git status && go build -o /tmp/hello": while
running runtime: exit status 128
```

This was a new and different error message for me - but same exit code as
before. A quick Google search brought me to CVE-2022-24765 [1], whose fix
introduced this "dubious ownership" message/protection.

I was finally able to piece everything together with a few more debug
builds and internet searches:

1. On Fedora 39, podman runs in "rootless" mode. Files owned by me show up
as owned by "root" in containers.
2. For Linux containers, `COPY` commands in Dockerfiles copy files as
UID/GID 0 unless the `--chown` flag is passed. [2].
3. As part of the mitigation for CVE-2022-24765, git commands will succeed
only if:
  a. The `.git` directory is owned by the same user executing the `.git`
command OR
  b. The parent directory marked "safe" in the git configuration.

Using `COPY --chown=default . .` instead of `COPY . .` works for the UBI
go-toolset image referenced previously in this thread. Your results may
vary using other golang "builder" images.

[1] https://github.blog/2022-04-12-git-security-vulnerability-announced/
[2] https://docs.docker.com/reference/dockerfile/#copy---chown---chmod


On Sat, May 11, 2024 at 11:43 AM Jason E. Aten  wrote:

> > how can developers debug and find the root cause?
>
> If it was me, I would start by going into the container (whatever the
> podman equivalent of docker exec -it containernumber bash) and try to run
> 'git status' or 'git log' and see why the git query is giving an error.
> You could also try strace to see what git command specifically is being
> execed, then try to get that command working manually.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/LZbM2WlZoJM/unsubscribe.
> To unsubscribe from this group and all its topics, 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/ca680397-1497-4b3a-83ce-301c936308c1n%40googlegroups.com
> 
> .
>


-- 

Adam Kaplan

He/Him

Principal Software Engineer

Red Hat 

100 E. Davie Street

adam.kap...@redhat.comT: 1-919-754-4843


-- 
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/CADmLb%2B%3DpPMFT5fnBpC4C8QuxD%3DFNTO1c74o6Nx6F6zL2eJALbg%40mail.gmail.com.


[go-nuts] Re: programmatic way to find if application go binary is built with -cover flag ?

2024-05-13 Thread Akash Kumar
I am writing an external go program that will take the path to another go 
binary as argument, and checks if the binary was built with cover flag.

`debug.ReadBuildInfo()` is meant for getting build info embedded in the 
running binary as 
> ReadBuildInfo returns the build information embedded in the running 
binary 

On Monday, May 13, 2024 at 6:37:46 PM UTC+5:30 Zxilly Chou wrote:

> try debug.ReadBuildInfo(), then iterate the pair in the buildinfo.Settings
>
> 在2024年5月13日星期一 UTC+8 20:56:51 写道:
>
>> Is there a way in go to find whether a go binary is built with -cover 
>> flag ?
>
>

-- 
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/81a62099-4b33-4048-80a6-15b3332767d1n%40googlegroups.com.


[go-nuts] Re: programmatic way to find if application go binary is built with -cover flag ?

2024-05-13 Thread Zxilly Chou
try debug.ReadBuildInfo(), then iterate the pair in the buildinfo.Settings

在2024年5月13日星期一 UTC+8 20:56:51 写道:

> Is there a way in go to find whether a go binary is built with -cover flag 
> ?

-- 
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/b78a192f-80f9-4a93-a1d6-bed613e56000n%40googlegroups.com.


[go-nuts] programmatic way to find if application go binary is built with -cover flag ?

2024-05-13 Thread Akash Kumar
Is there a way in go to find whether a go binary is built with -cover flag ?

-- 
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/e0a2d60f-9f86-48b9-a265-316a575a6427n%40googlegroups.com.


  1   2   3   4   5   6   7   8   9   10   >