Re: [go-nuts] Where is my type?

2024-04-24 Thread cpu...@gmail.com
Your answer has put me on the right track. Here's the long version: https://stackoverflow.com/questions/48790663/why-value-stored-in-an-interface-is-not-addressable-in-golang On Wednesday, April 24, 2024 at 6:55:53 PM UTC+2 cpu...@gmail.com wrote: > > In the first case, the interface co

Re: [go-nuts] Where is my type?

2024-04-24 Thread cpu...@gmail.com
second case the > interface contains *S, which is writable, so unmarshal fills it in via > reflection. > > On Wed, Apr 24, 2024 at 10:46 AM cpu...@gmail.com > wrote: > > > > Every time I feel I've come to terms with how Go works I round a corner > and hit a wall, even

[go-nuts] Re: Where is my type?

2024-04-24 Thread cpu...@gmail.com
It's worth noting that before the Unmarshal v is {}(main.S) and afterwards {}(map[string]interface{}) On Wednesday, April 24, 2024 at 6:46:18 PM UTC+2 cpu...@gmail.com wrote: > Every time I feel I've come to terms with how Go works I round a corner > and hit a wall, even after

[go-nuts] Where is my type?

2024-04-24 Thread cpu...@gmail.com
Every time I feel I've come to terms with how Go works I round a corner and hit a wall, even after doing this for >5 years. Here's one. Consider this simple code (https://go.dev/play/p/bph5I80vc99): package main import ( "encoding/json" "fmt" ) type S struct { Foo int } func update(v any) {

[go-nuts] Re: How to add labels to Go runtime prometheus metrics?

2024-03-06 Thread cpu...@gmail.com
label for the hostname (e.g. > node_exporter, windows_exporter etc). > > If there's something special about your situation which means you need to > do this, can you explain your use case further? > > On Wednesday 6 March 2024 at 10:40:29 UTC cpu...@gmail.com wrote: > >> T

[go-nuts] How to add labels to Go runtime prometheus metrics?

2024-03-06 Thread cpu...@gmail.com
The Go runtime exposes various metrics. To collect metrics from multiple servers I'd like to add labels for server name. Is it possible to extend the build-in metrics for this purpose? Thanks, Andi -- You received this message because you are subscribed to the Google Groups "golang-nuts"

[go-nuts] Re: Go 1.22 binary size improvements?

2024-02-09 Thread cpu...@gmail.com
Yes, CGO is disabled. ldd doesn't seem to exist on MacOS: make build && ls -la ./evcc && otool -L ./evcc 1.21.7 CGO_ENABLED=0 go build -v -tags=release -trimpath -ldflags='-X github.com/evcc-io/evcc/server.Version=0.124.1 -X github.com/evcc-io/evcc/server.Commit=596071b42 -s -w' -rwxr-xr-x 1

[go-nuts] Re: Go 1.22 binary size improvements?

2024-02-09 Thread cpu...@gmail.com
Just gave it another try cross-compiling to Arm on Linux. This time binary size stays the same. Sorry if my excitement was too premature. On Friday, February 9, 2024 at 2:11:25 PM UTC+1 cpu...@gmail.com wrote: > It's really surprising (positively). Compiling with -ldflags='-s -w' if >

[go-nuts] Re: Go 1.22 binary size improvements?

2024-02-09 Thread cpu...@gmail.com
y size. > However, from 93MB to 81MB, I think it is most likely the result of the > joint efforts of many CLs. > > On Friday, February 9, 2024 at 7:46:48 PM UTC+8 cpu...@gmail.com wrote: > >> I was surprised to see my application (MacOS binary) go from 93MB to 81MB >&

[go-nuts] Go 1.22 binary size improvements?

2024-02-09 Thread cpu...@gmail.com
I was surprised to see my application (MacOS binary) go from 93MB to 81MB (no PGO). Release notes don't mention this. Has anyone made similar experience or knows why that is? Thanks, Andi -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To

[go-nuts] Re: Using log/slog with log.Logger format?

2023-07-22 Thread cpu...@gmail.com
Seems it's not possible to create a logger using the log.Logger format in a straight-forward way? On Thursday, July 20, 2023 at 3:48:49 PM UTC+2 cpu...@gmail.com wrote: > The log/slog logger uses the log.Logger format by default. Implementation > is internal. > > In a gradual sw

[go-nuts] Using log/slog with log.Logger format?

2023-07-20 Thread cpu...@gmail.com
The log/slog logger uses the log.Logger format by default. Implementation is internal. In a gradual switch to slog I'd like to keep that format for time being but customize other handler options- hence need to create a new Logger. Is there a good way to do that without reimplementing the

[go-nuts] Using struct{} for context keys

2023-05-28 Thread cpu...@gmail.com
I've recently stumbled across code like this https://go.dev/play/p/u3UER2ywRlr: type clientContextKey struct{} ctx := context.Background() ctx = context.WithValue(ctx, clientContextKey{}, "foo") _, ok := ctx.Value(clientContextKey{}).(string) Naively, I had expected this to fail since I

[go-nuts] Drain channel on demand without busy looping?

2023-02-05 Thread cpu...@gmail.com
I have the requirement of being able to drain a channel, i.e. make sure that downstream processes all data currently being sent. One possible pattern is something like for{ select{ case <-q.data: default: } } where the default branch could indicate that channel has been drained. My concern

[go-nuts] 1.19.2: gofmt fails on CI but not locally

2022-10-27 Thread cpu...@gmail.com
Really strange issue, have been scratching my head for hours now. Consider https://github.com/evcc-io/evcc/blob/0b8105d36d245a2169961c48e50fbb830fd38147/charger/ocpp_decorators.go. Absolutely fine imho. Yet gofmt fails, but only on CI:

[go-nuts] Patching Go sources - which files end up in the build?

2022-10-02 Thread cpu...@gmail.com
For various reasons we need to patch cryptobytes for our build (https://github.com/evcc-io/eebus/issues/1#issuecomment-1146843187). We've tried to do this in a consistent way for local, Docker and Github CI build by vendoring our modules (go mod vendor) and patching the vendored copy. Test

[go-nuts] Error-checking with errors.As() is brittle with regards to plain vs pointer types

2022-09-21 Thread cpu...@gmail.com
Consider https://go.dev/play/p/jgPMwLRRsqe: errors.As(err, ) will not match if error is of pointer type. As a result, a library consumer needs to understand if a library returns Error or *Error. However, that is not part of the API spec as both returns would satisfy error if Error() is

Re: [go-nuts] encoding/asn1 overly strict?

2022-06-09 Thread cpu...@gmail.com
On Wednesday, June 8, 2022 at 5:53:50 PM UTC+2 Brian Candler wrote: > On Wednesday, 8 June 2022 at 10:09:26 UTC+1 andig wrote: > >> We've not found an approach for communicating with the device sofar >> unless using patched Go stdlib. >> > > Connect via a proxy like stunnel? > > Out of

Re: [go-nuts] encoding/asn1 overly strict?

2022-06-08 Thread cpu...@gmail.com
Sorry to revive this ancient discussion. We've come across https://forum.golangbridge.org/t/x509-certificate-parse-error-with-iot-device/27622/2 where an IOT device from a large vendor uses BER for it's TLS certificate. It's unlikely, that the vendor will fix the certificate any time soon.

[go-nuts] x/exp/slices: add Map/Extract function

2022-03-20 Thread cpu...@gmail.com
Playing with 1.18 I've noticed that I can immediately replace pretty much all uses of https://github.com/thoas/go-funk with the new slices package. One common use case that I happen to have in the codebase quite a lot is extracting data from a slice of objects: funk.Map(chargers, func(c

[go-nuts] What are best practices for synchronizing data access in web applications?

2022-03-01 Thread cpu...@gmail.com
I've developed a semi-complex server application (https://evcc.io) with web ui. Since web requests are async per nature and I wan't to service them quickly, mutexes are used. I'm now at the point where I realise that sprinkling (un)locks over the code quickly leads to deadlocks and

[go-nuts] Re: gob: decoding into local type []float64, received remote type []float

2021-11-29 Thread cpu...@gmail.com
couldn't find anything regarding enc that should prevent reusing it? Cheers, Andi On Sunday, November 28, 2021 at 9:10:37 PM UTC+1 cpu...@gmail.com wrote: > I'm trying to transfer arbitrary structs over gRPC. To achieve this I've > trying to use gob for encoding the interface{} part of the s

[go-nuts] gob: decoding into local type []float64, received remote type []float

2021-11-28 Thread cpu...@gmail.com
I'm trying to transfer arbitrary structs over gRPC. To achieve this I've trying to use gob for encoding the interface{} part of the structs. The code looks somewhat like https://go.dev/play/p/4Q5CQE4Wcy2 but not entirely. Two things strike me strange: - I receive "gob: decoding into local type

[go-nuts] How to diagnose a stuck program

2021-11-06 Thread cpu...@gmail.com
Developing https://github.com/evcc-io/evcc I've recently had a bug report of unresponsive application. Logfile shows, that the program still has alive go routines but the main loop doesn't show up in the logs any more, to it seems stuck. This may be more a Unix than a Go question: can I

[go-nuts] Re: How to use errors.As with sentinel errors?

2021-08-02 Thread cpu...@gmail.com
the errors in a chain. So I should just use errors.Is here... Sorry for the confusion! On Monday, August 2, 2021 at 10:02:11 AM UTC+2 cpu...@gmail.com wrote: > Consider this example: https://play.golang.org/p/16cU0kc8Lku, basically > > var Err = errors.New("sentinel") >

[go-nuts] How to use errors.As with sentinel errors?

2021-08-02 Thread cpu...@gmail.com
Consider this example: https://play.golang.org/p/16cU0kc8Lku, basically var Err = errors.New("sentinel") err := errors.New("foo") if errors.As(err, ) { fmt.Println("why?") } I'm wondering why this matches the sentinel error, or rather how to properly use sentinel errors. errors.As says "An

[go-nuts] A little love for x/oauth2

2021-05-19 Thread cpu...@gmail.com
I've recently worked a bit with oauth2 and noticed that issue tracker and PRs could use a little love. Quite a number of PRs have gone through Gerrit review without merging and the issues contain some imho valid points. Is there a policy for maintaining x/oauth2 or putting it into slower

Re: [go-nuts] How can I check error types of gRPC calls?

2021-05-18 Thread cpu...@gmail.com
: > On Sat, 2021-05-15 at 04:47 -0700, cpu...@gmail.com wrote: > > In my local code, I'm using things like > > > > if errors.Is(err, api.ErrMustRetry) { ... } > > > > How would I achieve the same on errors returned by the gRCP > > interface? I've noticed the

[go-nuts] How can I check error types of gRPC calls?

2021-05-15 Thread cpu...@gmail.com
In my local code, I'm using things like if errors.Is(err, api.ErrMustRetry) { ... } How would I achieve the same on errors returned by the gRCP interface? I've noticed these are wrapped: rpc error: code = Unknown desc = must retry rpc error: code = Unknown desc = must retry I assume the

[go-nuts] Re: Suggestion to extend x/OAuth2 API

2021-05-09 Thread cpu...@gmail.com
There is some support for a configurable token source in https://github.com/golang/oauth2/pull/448#issuecomment-835811792, no feedback otherwise. Cheers, Andi On Thursday, April 22, 2021 at 6:10:38 PM UTC+2 cpu...@gmail.com wrote: > After working with a few more-or-less OAuth2 APIs lately

[go-nuts] Suggestion to extend x/OAuth2 API

2021-04-22 Thread cpu...@gmail.com
After working with a few more-or-less OAuth2 APIs lately, I would like to propose slightly extending the API footprint of the oauth2 library. By doing so I expect that the amount of userland/provider-specific code can be reduced- both inside oauth2 and outside in realworld applications. Some

[go-nuts] Re: Autocert failure with HTTP handler

2021-04-19 Thread cpu...@gmail.com
That makes perfect sense as the simple reproducer shows: https://play.golang.org/p/vSEBtdV2CzR Only in this case I didn't see it as there were more go routines alive. Much appreciated, thank you! On Monday, April 19, 2021 at 11:29:31 PM UTC+2 Brian Candler wrote: > As far as I understand it:

[go-nuts] Autocert failure with HTTP handler

2021-04-19 Thread cpu...@gmail.com
Hello, I have a very stupid problem with autocert. The below code works: log.Println("sslHosts:", sslHosts) log.Println("sslCertDir:", sslCertDir) certManager := autocert.Manager{ Prompt: autocert.AcceptTOS, HostPolicy: autocert.HostWhitelist(strings.Split(sslHosts, " ")...), Cache:

[go-nuts] Can I import a package from a git submodule?

2021-03-31 Thread cpu...@gmail.com
Consider this layout: - Repo A contains module foo - Repo B contains module bar (of course ;) - Repo B is added as submodule to repo A at /baz I was expecting that I can import "foo/baz/bar" in repo A, but that leads to error ("no required module provides package..."). Shouldn't

Re: [go-nuts] How to wait for HTTP server to start?

2021-03-30 Thread cpu...@gmail.com
p", ":"+port) if err != nil { log.Fatal(err) } var wg sync.WaitGroup wg.Add(1) go func() { server := {Addr: ":" + port, Handler: handler} wg.Done() log.Fatal(server.Serve(ln)) }() wg.Wait() Cheers, Andi > > On Sat, 27 Mar 2021, 14:13 cpu...@gmail.com, wrote:

[go-nuts] How to wait for HTTP server to start?

2021-03-27 Thread cpu...@gmail.com
The typical Go tutorials pattern for starting a server is something like log.Fatal(http.ListenAndServe(":8080")) But what if the application needs to do other things after the server is started? It seems there is virtually no method to wait for the server actually start listening to

[go-nuts] Re: Fixing deprecated: golang.org/x/oauth2: Transport.CancelRequest no longer does anything; use contexts

2021-03-22 Thread cpu...@gmail.com
Opened https://github.com/golang/oauth2/issues/487 to propose removing the `CancelRequest` method. Cheers, Andreas On Friday, March 19, 2021 at 5:44:21 PM UTC+1 cpu...@gmail.com wrote: > Hi all, > > I've recently learned about oauth2 and started to convert some of my > "manua

Re: [go-nuts] No generic, part -2

2021-03-19 Thread cpu...@gmail.com
On Thursday, March 18, 2021 at 1:53:30 PM UTC+1 ren...@ix.netcom.com wrote: > One other point on this. Generics will be trivial for 95% of the people - > they will only need to be able to read and write the instantiation > statements of type safe collections. > > Most developers don’t write

[go-nuts] Fixing deprecated: golang.org/x/oauth2: Transport.CancelRequest no longer does anything; use contexts

2021-03-19 Thread cpu...@gmail.com
Hi all, I've recently learned about oauth2 and started to convert some of my "manual" code using net/http to use an underlying oauth2.Transport for executing authenticated requests and token refresh. As a result, my application now sometimes shows deprecated: golang.org/x/oauth2:

Re: [go-nuts] Why do type aliases change behaviour (i.e. json.Unmarshal)?

2021-03-15 Thread cpu...@gmail.com
oken (since > both identifier denote the same type). > > But maybe that is not what you are looking for, if that's the case, there > are other ways around the problem, like type embedding and such. > Hope this helps, > > Le lun. 15 mars 2021 à 13:49, cpu...@gmail.com a > écri

[go-nuts] Why do type aliases change behaviour (i.e. json.Unmarshal)?

2021-03-15 Thread cpu...@gmail.com
I've just tried doing something like this in my code: // Token is an OAuth2 token which includes decoding the expires_in attribute type Token struct { oauth2.Token ExpiresIn int `json:"expires_in"` // expiration time in seconds } func (t *Token) UnmarshalJSON(data []byte) error { ... } type

[go-nuts] Re: CSS-like selectors for Go AST?

2020-10-14 Thread cpu...@gmail.com
[1 + 2 * 3]") > y := ast2.AnyToAst(x, nil) // wrap the existing AST. does not allocate > memory. > > ythree := y.Get(1).Get(1).Get(1) // extract the "3" as ast2.Node > > // now unwrap it, getting the *ast.BasicLit and the Value inside it > var three s

[go-nuts] CSS-like selectors for Go AST?

2020-10-13 Thread cpu...@gmail.com
Good morning. I've recently found myself writing a code generator for dynamic interface composition at runtime. It became ugly and I had to pass in quite a number of parameters that should have been available from reading the source code. In a second attempt I've reimplemented the generator

Re: [go-nuts] What are the best practices for go build tools?

2020-09-19 Thread cpu...@gmail.com
Hi Paul! Thank you for taking the time to reply. On Friday, September 18, 2020 at 11:33:49 AM UTC+2 Paul Jolly wrote: > Hi Andi, > > > 1) I cannot do go install tools.go: > > go install takes main packages as arguments, so no, this will not > work. The tools.go file (like the example you

[go-nuts] What are the best practices for go build tools?

2020-09-13 Thread cpu...@gmail.com
Hello experts, I'm currently using //go:generate with external and module-internal tools. All external tools are documented in tools.go: // +build tools package main import ( _ "github.com/golang/mock/mockgen" _ "github.com/mjibson/esc" ) However, the existing setup has a couple of

Re: [go-nuts] Dynamic composition of interfaces at runtime?

2020-08-26 Thread cpu...@gmail.com
ou might > introduce very hard to find bugs. > > On Wed, Aug 26, 2020 at 5:49 PM cpu...@gmail.com wrote: > >> Hi All, >> >> using interfaces for behavioural testing seems a common pattern in go: >> >> if typed, hasCapability := d.(Capability); hasCa