[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

[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] 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

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

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: 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

[go-nuts] Are functional options idiomatic

2017-07-09 Thread 'Anmol Sethi' 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

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

2017-01-14 Thread 'Anmol Sethi' via golang-nuts
, January 14, 2017 at 7:55:33 PM UTC+1, Anmol Sethi wrote: 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

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

2017-01-14 Thread 'Anmol Sethi' via golang-nuts
xt/css, and certainly not application/x-gzip) > > > On Saturday, January 14, 2017 at 7:08:55 PM UTC+1, Anmol Sethi wrote: > > 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 shou

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

2017-01-14 Thread 'Anmol Sethi' 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

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

2017-01-10 Thread 'Anmol Sethi' 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

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

2017-01-08 Thread 'Anmol Sethi' 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

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

2016-12-06 Thread 'Anmol Sethi' 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] Re: Interface vs first-class function

2016-11-20 Thread 'Anmol Sethi' 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] Re: Interface vs first-class function

2016-11-20 Thread 'Anmol Sethi' 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

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

2016-11-09 Thread 'Anmol Sethi' 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: 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] Code Review for TLS Proxies

2016-10-10 Thread &#x27;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

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

2016-10-08 Thread &#x27;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 > >

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

2016-10-08 Thread &#x27;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/tl

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

2016-10-08 Thread &#x27;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

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

2016-10-08 Thread &#x27;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] dialing a name with multiple addresses

2016-09-27 Thread &#x27;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

Re: [go-nuts] What was the rationale behind using braces for scoping?

2016-09-07 Thread Anmol Sethi
Additionally, I found Rob’s talk here https://youtu.be/VoS7DsT1rdM?t=1263 that also explains the decision. > On Sep 7, 2016, at 8:13 PM, Anmol Sethi wrote: > > I’m not here to argue for using indentation for scoping. I just want to know > why go decided to go with braces (hehe).

Re: [go-nuts] What was the rationale behind using braces for scoping?

2016-09-07 Thread Anmol Sethi
f section 4. > > -rob > > > On Thu, Sep 8, 2016 at 10:13 AM, Anmol Sethi wrote: > I’m not here to argue for using indentation for scoping. I just want to know > why go decided to go with braces (hehe). > > No but seriously, I only found a section on the FAQ that says

[go-nuts] What was the rationale behind using braces for scoping?

2016-09-07 Thread Anmol Sethi
I’m not here to argue for using indentation for scoping. I just want to know why go decided to go with braces (hehe). No but seriously, I only found a section on the FAQ that says "Go uses brace brackets for statement grouping, a syntax familiar to programmers who have worked with any language

[go-nuts] compile vs stylistic errors

2016-09-05 Thread Anmol Sethi
What seperates a compile and stylistic error? As in, why not make the non-gofmt style illegal and enforce the gofmt style by the compiler? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails f

Re: [go-nuts] Error: cannot use Value literal (type Value) as type []Value in field value

2016-08-24 Thread Anmol Sethi
So together it would look like []Values{Value{}} > On Aug 24, 2016, at 10:00 AM, j...@ramhorst.eu wrote: > > Hello, > I have a problem with structs: > > I defined the following structs: > > type Value struct { > Type string `json:"type"` > Unity string `json:"unity"` > Data float64 `json:

Re: [go-nuts] Error: cannot use Value literal (type Value) as type []Value in field value

2016-08-24 Thread Anmol Sethi
slice* > On Aug 24, 2016, at 10:00 AM, j...@ramhorst.eu wrote: > > Hello, > I have a problem with structs: > > I defined the following structs: > > type Value struct { > Type string `json:"type"` > Unity string `json:"unity"` > Data float64 `json:"data"` > } > > > type Phase struct { >

Re: [go-nuts] Error: cannot use Value literal (type Value) as type []Value in field value

2016-08-24 Thread Anmol Sethi
Values is an array. So you need []Values{} > On Aug 24, 2016, at 10:00 AM, j...@ramhorst.eu wrote: > > Hello, > I have a problem with structs: > > I defined the following structs: > > type Value struct { > Type string `json:"type"` > Unity string `json:"unity"` > Data float64 `json:"data"

Re: [go-nuts] when an interface type embeds two other interface types, why the other two interface types can't have non-zero intersection?

2016-08-18 Thread Anmol Sethi
If you did: var i I // initialize i i.f1() Embedding I1 and I2 exposes their methods/fields as members of I. So when you do i.f1(), which f1 method should be called? > On Aug 18, 2016, at 1:41 PM, T L wrote: > > > package main > > type I1 interface { > f1() >

Re: [go-nuts] what is the meaning of ENV GOEXE

2016-08-13 Thread Anmol Sethi
I looked in the Go source code. You can’t actually set it as a environment variable. It’s the value of the executable suffix. It’s set automatically in build.go. Like if running on windows, it is '.exe’ or for c-archives it is ‘.a’. I don’t think it matters for an end user. > On Aug 13, 2016, a

Re: [go-nuts] keyed vs unkeyed fields

2016-08-13 Thread Anmol Sethi
Thing is, since keyed fields are almost always better, why were unkeyed fields even allowed for struct literals? I see what you mean in your example, but I think it would be simpler to only have unkeyed fields. Was it a mistake or is there a even better reason? > On Aug 12, 2016, at 10:12 PM, N

Re: [go-nuts] keyed vs unkeyed fields

2016-08-12 Thread Anmol Sethi
My bad. I should have specified that I meant struct literals. > On Aug 12, 2016, at 6:02 PM, Ian Lance Taylor wrote: > > On Fri, Aug 12, 2016 at 2:29 PM, Anmol Sethi wrote: >> Keyed fields seem to be always better than unkeyed fields in a composite >> literal. >&g

[go-nuts] keyed vs unkeyed fields

2016-08-12 Thread Anmol Sethi
Keyed fields seem to be always better than unkeyed fields in a composite literal. Under what circumstances would I want to use unkeyed fields? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emai

Re: [go-nuts] Small complete examples which show the power of Go?

2016-08-10 Thread Anmol Sethi
You can shorten that by 6 lines package main import "net/http" func main() { http.ListenAndServe(":8080", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello World!")) })) } A bare bones web server in just 9 lines! > On Aug 10,

Re: [go-nuts] create dmg

2016-07-30 Thread Anmol Sethi
And check this out: http://ramezanpour.net/post/2014/05/12/how-to-create-installation-dmg-files-in-os-x/ > On Jul 30, 2016, at 7:00 PM, Joe Blue wrote: > > recommended way for a gopher to make a dmg, so my users can install my golang > app ? > > i searched for a pure golang solution, but go n

Re: [go-nuts] create dmg

2016-07-30 Thread Anmol Sethi
I think you mean you want an .app they can drop in their /Applications folder. A dmg is just a disk image. You can very easily create that: https://support.apple.com/kb/PH22247?locale=en_US See https://mathiasbynens.be/notes/shell-script-mac-apps for creating a custom .app. I know it says scri

[go-nuts] how is log.Panic useful?

2016-07-24 Thread Anmol Sethi
I cannot seem to think of many situations where log.Panic is very useful. Can someone provide a quick example? -- 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 go

[go-nuts] OCSP Basic Response Certificates

2016-07-19 Thread Anmol Sethi
https://github.com/golang/crypto/blob/master/ocsp/ocsp.go#L428 Why does the OCSP package limit the number of certificates in the response to one? RFC 6960 says The responder MAY include certificates in the certs field of BasicOCSPResponse that help the OCSP client verify the

Re: [go-nuts] TLSUnique in tls.ConnectionState

2016-07-17 Thread Anmol Sethi
I understand now. Thank you very much. > On Jul 18, 2016, at 12:17 AM, Sam Whited wrote: > > On Sat, Jul 16, 2016 at 6:33 PM, Anmol Sethi wrote: >> I noticed the TLSUnique field of tls.ConnectionState. >> >> https://golang.org/pkg/crypto/tls/#ConnectionState >

[go-nuts] TLSUnique in tls.ConnectionState

2016-07-16 Thread Anmol Sethi
Hello, I noticed the TLSUnique field of tls.ConnectionState. https://golang.org/pkg/crypto/tls/#ConnectionState I tried to read RFC 5056 and 5929 but I still do not understand its purpose. What exactly does it accomplish? Why would we want to use it? -- You received this message because you

Re: [go-nuts] filepath.Clean

2016-07-13 Thread Anmol Sethi
I’ve cced him, hopefully he can state exactly why. > On Jul 13, 2016, at 4:02 PM, Ian Lance Taylor wrote: > > On Wed, Jul 13, 2016 at 10:40 AM, Anmol Sethi wrote: >> Why does filepath.Clean replace each slash with a separator at the end of >> the function? What’s the p

Re: [go-nuts] filepath.Join

2016-07-13 Thread Anmol Sethi
ah they are, I understand now, thanks! > On Jul 13, 2016, at 3:59 PM, Steven Hartland wrote: > > Are the unexported methods OS specific? > > On 13/07/2016 20:56, Anmol Sethi wrote: >> Why does filepath.Join only call to the unexported join? Why not just export &

[go-nuts] filepath.Join

2016-07-13 Thread Anmol Sethi
Why does filepath.Join only call to the unexported join? Why not just export the unexported join? -- 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+uns

Re: [go-nuts] Rel in path package

2016-07-13 Thread Anmol Sethi
Thanks Ian! > On Jul 13, 2016, at 10:23 AM, Ian Lance Taylor wrote: > > On Wed, Jul 13, 2016 at 2:43 AM, Anmol Sethi wrote: >> Right here: >> https://github.com/nsf/gocode/blob/f535dc686130fcc7b942c504ce5903222a205ca3/autocompletecontext.go#L254 >>

Re: [go-nuts] Rel in path package

2016-07-13 Thread Anmol Sethi
fixed here: https://github.com/nsf/gocode/pull/361/files Not sure what I was thinking when I wrote that code. My bad. > On Jul 13, 2016, at 10:23 AM, Ian Lance Taylor wrote: > > On Wed, Jul 13, 2016 at 2:43 AM, Anmol Sethi wrote: >> Right here: >> https://githu

[go-nuts] filepath.Clean

2016-07-13 Thread Anmol Sethi
Why does filepath.Clean replace each slash with a separator at the end of the function? What’s the point of attempting to clean it if the separator used is incorrect? Wouldn’t doing this at the start of the function make more sense? -- You received this message because you are subscribed to the

Re: [go-nuts] Rel in path package

2016-07-13 Thread Anmol Sethi
t 5:17 PM, Anmol Sethi wrote: >> Why is there no function in the path package to get relative paths, like >> filepath.Rel? > > When would you want to use it? > > Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts"

[go-nuts] Rel in path package

2016-07-12 Thread Anmol Sethi
Why is there no function in the path package to get relative paths, like filepath.Rel? -- 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...@go

Re: [go-nuts] http.Handler method name

2016-07-12 Thread Anmol Sethi
wouldn’t that make for a very awkward exported name? http.HTTPHandler? > On Jul 12, 2016, at 4:20 PM, Ian Lance Taylor wrote: > > On Tue, Jul 12, 2016 at 1:14 PM, Anmol Sethi wrote: >> If you were to redesign it now, would you name the method Handle? > > Speaking per

Re: [go-nuts] http.Handler method name

2016-07-12 Thread Anmol Sethi
If you were to redesign it now, would you name the method Handle? I’ve got a similar interface in my project and I was just wondering what the most idiomatic method name would be. > On Jul 12, 2016, at 4:13 PM, Ian Lance Taylor wrote: > > On Tue, Jul 12, 2016 at 12:10 PM, Anmol Set

[go-nuts] http.Handler method name

2016-07-12 Thread Anmol Sethi
Why is http.Handler’s method name ServeHTTP and not Handle? Handle seems to be more idiomatic. -- 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+unsubs

[go-nuts] which approach to appending a slice to another slice by creating a new slice look best to you?

2016-07-10 Thread Anmol Sethi
https://gist.github.com/nhooyr/7b773ea98f0d08e698d4fe706b4f5b2a -- 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. For more

Re: [go-nuts] Error vs. Panic: Should functions like strings.Repeat return an error value?

2016-07-06 Thread Anmol Sethi
What about gzip.NewWriterLevel(w, level)? It returns an error if level is invalid. Shouldn’t it panic instead if the level is invalid? > On Jun 30, 2016, at 12:30 PM, Andy Balholm wrote: > > When a function is used incorrectly, a panic is appropriate. If the count > comes from an untrusted sou