[go-nuts] constructors vs lazy initialization

2018-03-03 Thread 'Anmol Sethi' via golang-nuts
How do you guys choose between constructors and lazy initialization? For example. Struct constructors: type meow struct { x http.Handler } func newMeow() *meow { return &meow{ x: http.NewServeMux(), } } func (m *meow) do() { // stuff } Lazy initialization: type meow

[go-nuts] Would this race condition be considered a bug?

2018-03-15 Thread 'Anmol Sethi' via golang-nuts
https://play.golang.org/p/82Um1jSntBo Please run with the race detector to see the race. This race condition arises because private variables are read via reflection by the fmt package. Is there any elegant way to avoid such a race? -- Best, Anmol -- You received this message because you are

[go-nuts] Why does Go not include a stack trace by default in the errors package?

2018-08-06 Thread 'Anmol Sethi' via golang-nuts
Such traces can be extremely useful for debugging an error caused deep inside some library. Does Go opt not to do this by default in the errors package because of the performance implications? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To

Re: [go-nuts] Re: golang and http2

2017-11-15 Thread 'Anmol Sethi' via golang-nuts
It’s really easy to do, see https://github.com/nhooyr/lily/blob/fb72112455ade17f36ed773d87902bb5eefe051e/lily.go#L82-L109 The only disadvantage is that you will not have graceful shutdown. > On Nov

Re: [go-nuts] Re: context.C and context.BG

2017-11-18 Thread 'Anmol Sethi' via golang-nuts
Ah, thanks! > On Nov 18, 2017, at 9:00 AM, Sameer Ajmani wrote: > > Context.TODO and Background have different String values; see emptyCtx.String. > On Fri, Nov 17, 2017 at 9:25 PM me via golang-nuts > mailto:golang-nuts@googlegroups.com>> wrote: > I've found a hint. Apparently, both context.TO

Re: [go-nuts] Re: Parsing OpenSSH ed25519 private keys

2017-11-19 Thread 'Anmol Sethi' via golang-nuts
That library will not work either. See https://github.com/fudanchii/edssh/blob/bd7d88fd1d85351bf598cdcd1fb7b04528cf42e2/keys.go#L44 > On Nov 19, 2017, at 11:49 AM, Nurahmadie Nurahmadie > wrote: > > Hi Chandru, > > I made a library to support openssh ed25519 key format. > It can be used as a

[go-nuts] dialing a name with multiple addresses

2016-09-27 Thread 'Anmol Sethi' via golang-nuts
For https://godoc.org/net#Dialer , it says "When dialing a name with multiple IP addresses, the timeout may be divided between them." Why? Wouldn't the name still be resolved to a single IP? E.g. if I have 5 IPs for example.com, one would be selected and used. Why would the timeout need to be div

[go-nuts] context.Context in a TLS proxy

2016-10-08 Thread 'Anmol Sethi' via golang-nuts
My TLS proxy used to create two goroutines of `io.Copy` to copy between the incoming and outgoing connection. As soon as `io.Copy` returned, with or without an error, I closed both connections. This had the effect that on the other goroutine, the Read/Write returned with errors about the "use of a

[go-nuts] Re: context.Context in a TLS proxy

2016-10-08 Thread 'Anmol Sethi' via golang-nuts
Sorry, my mistake. Use https://github.com/nhooyr/tlswrapd/blob/15b03321169039a4042434086d841a660a7afd88/proxy.go#L88-L143 as the link incase I change things and the line numbers become incorrect. On Sat, Oct 8, 2016 at 11:43 PM Anmol Sethi wrote: > My TLS proxy used to create two goroutines of `

[go-nuts] Re: context.Context in a TLS proxy

2016-10-08 Thread 'Anmol Sethi' via golang-nuts
Ok, so I think I've got it really nice now: https://github.com/nhooyr/tlswrapd/blob/master/proxy.go#L87-L110 Much simpler by only using the first error. On Sat, Oct 8, 2016 at 11:45 PM Anmol Sethi wrote: > Sorry, my mistake. Use > https://github.com/nhooyr/tlswrapd/blob/15b03321169039a404243408

[go-nuts] Re: context.Context in a TLS proxy

2016-10-08 Thread 'Anmol Sethi' via golang-nuts
Arg, use https://github.com/nhooyr/tlswrapd/blob/965c34913d5c8635b07ec8fb4918174298fa4855/proxy.go#L87-L110 On Sun, Oct 9, 2016 at 12:45 AM Anmol Sethi wrote: > Ok, so I think I've got it really nice now: > https://github.com/nhooyr/tlswrapd/blob/master/proxy.go#L87-L110 > > Much simpler by only

[go-nuts] Code Review for TLS Proxies

2016-10-10 Thread 'Anmol Sethi' via golang-nuts
My school uses DPI (deep packet inspection) to block protocols like SSH and OpenVPN. Additionally, few remote ports are enabled. Sometimes I want to login to my VPS from school to fix or work on something, but I cannot because SSH is blocked. Furthermore, my school has a approved (yes, approved by

Re: [go-nuts] Re: printf in color

2016-11-07 Thread 'Anmol Sethi' via golang-nuts
I wrote a similar library once https://github.com/nhooyr/color But I like your approach better because you can just use fmt.Printf On Sun, Nov 6, 2016 at 10:07 PM 'Константин Иванов' via golang-nuts < golang-nuts@googlegroups.com> wrote: > Hello. I wrote the library that allows to use ANSI-colors

[go-nuts] http.Redirect's short note

2016-11-09 Thread &#x27;Anmol Sethi&#x27; via golang-nuts
RFC 2616 states that for 301 redirects: "Unless the request method was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s)." https://tools.ietf.org/html/rfc2616#section-10.3.2 I noticed that Go's net/http library's Redirect function only adds

Re: [go-nuts] Re: Interface vs first-class function

2016-11-20 Thread &#x27;Anmol Sethi&#x27; via golang-nuts
In relation to this question, do you guys think it would have been better had http.Handler been a function, not an interface? On Sun, Nov 20, 2016 at 11:23 PM Henry wrote: > Thanks for the replies. In terms of future extensibility, is it safe to > say that interface is superior to first-class fu

Re: [go-nuts] Re: Interface vs first-class function

2016-11-20 Thread &#x27;Anmol Sethi&#x27; via golang-nuts
https://github.com/julienschmidt/httprouter https://github.com/pressly/chi and others actually use a function by default because it's the more common case. See https://github.com/pressly/chi/issues/94#issuecomment-254516724 On Mon, Nov 21, 2016 at 12:39 AM Tamás Gulácsi wrote: > I don't think

Re: [go-nuts] The issue with "Writing Web Applications"

2016-12-06 Thread &#x27;Anmol Sethi&#x27; via golang-nuts
Yes, this is the correct place. On Tue, Dec 6, 2016 at 4:31 PM Shawn Milochik wrote: > Just ask. People here are generally very helpful and friendly. > > If the question should be redirected elsewhere I'm sure someone will tell > you, but they can't help you with that until they know what the >

Re: [go-nuts] does the syscall package allow zero bytes in the filename?

2017-01-08 Thread &#x27;Anmol Sethi&#x27; via golang-nuts
Alright, thanks! On Sat, Jan 7, 2017 at 11:43 AM Ian Lance Taylor wrote: > On Sat, Jan 7, 2017 at 7:00 AM, anmol via golang-nuts > wrote: > > Was the suggestion from this commit > > > https://github.com/golang/go/commit/706832a0882c7300889238d5f4d476dc2ee83ad0 > > ever implemented? > > Yes: htt

[go-nuts] best way to write a file handler to serve gzipped files

2017-01-10 Thread &#x27;Anmol Sethi&#x27; via golang-nuts
Hello, I'm trying to write a http handler to serve gzipped files but if the client does not accept the gzip content-encoding, it falls back to identity. I see three ways to do this. First is dynamic gzipping. If a client supports it and a file is gzippable, I gzip the file on the fly and then ser

[go-nuts] should every .gz file be served with content-encoding gzip?

2017-01-14 Thread &#x27;Anmol Sethi&#x27; via golang-nuts
Say in my http fileserver, I have /static/foo.tar.gz. Should my fileserver be serving it as /static/foo.tarwith content-encoding: gzip always or should it be served as /static/foo.tar.gz with content-type: gzip? Change foo.tar.gz with any file that ends in .gz. My question boils down to whether or

Re: [go-nuts] Re: should every .gz file be served with content-encoding gzip?

2017-01-14 Thread &#x27;Anmol Sethi&#x27; via golang-nuts
While it is unexpected, what is wrong with just serving a tar file and redirecting a foo.gz request to a foo request? Why should a user want to have a .gz file after downloading? On Sat, Jan 14, 2017 at 1:38 PM wrote: > Say you have this foo.tar.gz, > served as /foo.tar.gz with a content-encodin

Re: [go-nuts] Re: should every .gz file be served with content-encoding gzip?

2017-01-14 Thread &#x27;Anmol Sethi&#x27; via golang-nuts
How will it take longer to download? The gzipped version will still be transferred, just without the extension and the Content-Encoding set to gzip. On Sat, Jan 14, 2017 at 3:12 PM wrote: if you do so, it will be longer to download, it also put more pressure on the server as it needs to decompres

[go-nuts] Are functional options idiomatic

2017-07-09 Thread &#x27;Anmol Sethi&#x27; via golang-nuts
Hello everyone! I’m writing a new library where I need to be able to configure a struct. This struct and its configuration will be accessed concurrently. One design pattern I see throughout the standard library and community is to make the struct and its configuration fields public but all othe