Re: [go-nuts] Cannot set http 413 status from http.MaxBytesReader

2023-08-29 Thread Rory Campbell-Lange
On 29/08/23, Nagaev Boris (bnag...@gmail.com) wrote: > On Tue, Aug 29, 2023 at 5:44 PM Rory Campbell-Lange > wrote: > > > > I've made an http middleware that uses http.MaxBytesReader to limit the > > accepted size of requests. ... > > It seems sensible to send a 413 status code to any clients tra

Re: [go-nuts] Cannot set http 413 status from http.MaxBytesReader

2023-08-29 Thread Nagaev Boris
On Tue, Aug 29, 2023 at 5:44 PM Rory Campbell-Lange wrote: > > I've made an http middleware that uses http.MaxBytesReader to limit the > accepted size of requests. > > The middleware is as follows: > > func bodyLimitMiddleware(next http.Handler) http.Handler { > return http.HandlerFun

[go-nuts] Cannot set http 413 status from http.MaxBytesReader

2023-08-29 Thread Rory Campbell-Lange
I've made an http middleware that uses http.MaxBytesReader to limit the accepted size of requests. The middleware is as follows: func bodyLimitMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { r.Body = http

Re: [go-nuts] Interface embedding

2023-08-29 Thread Remko Tronçon
3. We want to be resilient when other methods are added to the DatastoreClient interface so that the code will still compile when that happens. That was my guess too: that it's a tradeoff between safety and future compatibility. This allows your library users to use newer versions of the pr

Re: [go-nuts] Would it be possible to make this work in the future?

2023-08-29 Thread roger peppe
> We would have to have careful definitions of what kinds of code are permitted in a case with multiple types. ISTM that we already have such a careful definition with generics: given a case in a `switch x.(type)` statement of the form `T1, T2, ..., Tn`, where `x` is of type `S`, we could define t

Re: [go-nuts] Interface embedding

2023-08-29 Thread roger peppe
On Tue, 29 Aug 2023 at 13:35, Remko Tronçon wrote: > The Google Cloud Go library contains the following code (See > https://github.com/googleapis/google-cloud-go/blob/38a040e213cc8af5b01b3afe422481493f54382f/datastore/client.go#L36 > ) > > // datastoreClient is a wrapper for the pb.DatastoreC

[go-nuts] Interface embedding

2023-08-29 Thread Remko Tronçon
The Google Cloud Go library contains the following code (See https://github.com/googleapis/google-cloud-go/blob/38a040e213cc8af5b01b3afe422481493f54382f/datastore/client.go#L36 ) // datastoreClient is a wrapper for the pb.DatastoreClient type datastoreClient struct { // Embed so we stil

[go-nuts] Refining the State Pattern in Go

2023-08-29 Thread Jose Corral
Hi! I got to write an article about applying and refining the State Pattern in Go . I would appreciate some feedback as the approach itself still does fill like a work in progress, and somehow, it does still feel like "h

[go-nuts] Re: [slog] customize defaultHandler

2023-08-29 Thread Tamás Gulácsi
Sorry for my wrong answer - I thought that should work. https://go.dev//issues/61892 explains it: the default slog handler uses the default log.Logger. This answers my other question, too: why is the default slog.Handler (newDefaultHandler) unexported? Because it's error prone. https://go.dev/p

Re: [go-nuts] Re: [slog] customize defaultHandler

2023-08-29 Thread Andrew Harris
Piping JSON output through jq is worth exploring. This much is enough to be nicer to human eyes: cat log.json | jq -c 'del(.time)' There's a nice Go implementation at https://github.com/itchyny/gojq. On Tuesday, August 29, 2023 at 12:59:55 AM UTC-7 Marcello H wrote: > After playing with it some

Re: [go-nuts] Re: [slog] customize defaultHandler

2023-08-29 Thread Marcello H
After playing with it some more: This also does the trick h := NewHandler(os.Stdout, &MyOptions{Level: slog.LevelDebug, TimeFormat: time.DateTime}) l := slog.New(h) slog.SetDefault(l) slog.Debug("hello") slog.Info("hello") slog.Warn("hello") slog.Error("hello") type MyOptions struct { // En

Re: [go-nuts] Re: [slog] customize defaultHandler

2023-08-29 Thread 'Sean Liao' via golang-nuts
cycle: https://go.dev//issues/61892 default handler, copied/exported: https://pkg.go.dev/github.com/jba/slog/handlers/loghandler - sean On Tue, Aug 29, 2023 at 7:53 AM Marcello H wrote: > Yesterday, I came up with the same question and found this: > "github.com/lmittmann/tint" > > (This solut