Re: [go-nuts] BUGFIX-66: Algorithmic Puzzles in Go

2022-11-13 Thread Matt Harden
Sounds fun! Go doesn't prevent race conditions and those can result in undefined behavior, so I don't think you're safe just restricting imports and limiting CPU and memory. You need to run code in a sandbox of some sort. I would look at what the Go playground does. On Fri, Nov 11, 2022, 10:47 BU

Re: [go-nuts] Help with tcpserver

2021-03-30 Thread Matt Harden
Why are you using channels for this? I see some issues in the code, but without knowing what you're actually trying to accomplish, it's hard to give advice. To do exactly what you described, I would simply change handleDeviceConnection() to look similar to this: func handleDeviceConnection(c net.

Re: [go-nuts] Looking for a Go-Lang Developer

2020-12-23 Thread Matt Harden
Since Go version 1.0 was not released until March 2012, you might find it hard to find people with 10 years of experience with it. On Wed, Dec 23, 2020 at 1:07 PM Kavya S wrote: > Hi Everyone, > > Happy Holidays! > > Urgent requirement for a GO Language Developer with 7-10 years of > experience

Re: [go-nuts] Performance issue with os.File.Write

2020-12-23 Thread Matt Harden
On Tue, Dec 22, 2020 at 11:21 AM komuW wrote: > The bufio package also uses a max buffer of 64KB: > https://go.googlesource.com/go/+/go1.15.6/src/bufio/scan.go#80 > That limit is for bufio.Scanner. It doesn't have anything to do with bufio.Reader and bufio.Writer, which don't have any particular

Re: [go-nuts] [generics] use of new predeclared name `any`

2020-12-23 Thread Matt Harden
Although "any" is a new predefined identifier, I still find that conceptually simpler than assigning a second meaning to "_". On Wed, Dec 23, 2020 at 9:27 AM Ian Lance Taylor wrote: > On Wed, Dec 23, 2020 at 9:03 AM LeoY wrote: > > > > Following the blog post about generics in Go, I want to joi

Re: [go-nuts] Re: Give the zero time value a location, and it won't survive a roundtrip to JSON?

2020-11-28 Thread Matt Harden
On Fri, Nov 27, 2020 at 4:14 PM 'Robert Ma' via golang-nuts < golang-nuts@googlegroups.com> wrote: > Is this because the 2-second offset of LMT gets lost in RFC 3339 > representation? > Yes, that's exactly it. > On Fri, Nov 27, 2020 at 6:33 PM Robert Ma wrote: > >> Hi all, >> >> Time is compli

Re: [go-nuts] TLS dial error pkg variables - Best way to logically detect the type of tls failure

2020-06-07 Thread Matt Harden
I suspect your (possibly wrapped) error will be of type x509.UnknownAuthorityError, so you should be able to check for it with errors.As: var uaerr x509.UnknownAuthorityError if errors.As(err, &uaerr) { // handle as an unknown authority error } On Tue, Jun 2, 2020 at 8:22 AM Kevin Chadwick wro

Re: [go-nuts] Avoiding resource leaks with racing channels

2019-07-08 Thread Matt Harden
Only a buffered channel can "hold" anything. If the channel is unbuffered, then you are guaranteed that another goroutine has at least received the item you sent when the send statement returns. On Mon, Jul 8, 2019 at 9:42 PM Burak Serdar wrote: > On Mon, Jul 8, 2019 at 10:14 PM Daniel Eloff wr

Re: [go-nuts] [ANN] Simple DNS Server implemented in Go

2019-06-25 Thread Matt Harden
I realize this is a learning exercise for you, but in case you're interested, the DNS message types are implemented for you in https://godoc.org/golang.org/x/net/dns/dnsmessage. On Tue, Jun 25, 2019 at 1:36 PM Eric S. Raymond wrote: > Daniel Lorch : > > I have implemented a simple authoritative

Re: [go-nuts] binary.Read cgo fields

2019-05-06 Thread Matt Harden
n the Go side. You could serialize/deserialize using a language independent format like protobufs (there are many of these formats). Then you can serialize the data from any language, and deserialize it in any other language. On Sat, May 4, 2019 at 10:50 AM Matt Harden wrote: > >>

Re: [go-nuts] binary.Read cgo fields

2019-05-03 Thread Matt Harden
Why do you think binary.Read should handle padding for you? Based on the documentation, it would be a bug if it did. On Tue, Apr 30, 2019 at 4:42 AM Immueggpain S wrote: > I guess I have no other choice then? BTW binary.Read shoud handle padding > automatically. > > On Mon, Apr 22, 2019 at 10:53

Re: [go-nuts] Re: Flushing keyboard buffer (cross platform) ?

2019-05-03 Thread Matt Harden
You may want http://godoc/github.com/pkg/term/termios. It looks like it supports Tcflush on UNIX, including Solaris: https://github.com/pkg/term/blob/master/termios/termios_solaris.go#L63. On Fri, May 3, 2019 at 9:45 AM gbarr wrote: > For BSD systems I think you need to use TIOCFLUSH instead of

Re: [go-nuts] What happens to global vars when main() ends ?

2019-05-03 Thread Matt Harden
On Fri, May 3, 2019, 17:28 wrote: > Does Go GC destroy all global vars prior to the end of main() ? > What do you mean by "destroy"? Go is not an object oriented language and doesn't have the concept of a destructor. So no, it doesn't, but it also doesn't need to. May I ask, what led you to as

Re: [go-nuts] Re: Go if else syntax .. suggested replacement

2019-04-24 Thread Matt Harden
On Wed, Apr 24, 2019 at 8:42 PM David Koblas wrote: > IMHO I've wanted a switch expression, rather than a switch statement for a > while. > I've wanted that too, but what we already have really isn't that bad. > value := switch test { > case true => "red" > case false => "blue" > } > > value

Re: [go-nuts] Re: Should SIGTERM be included in the os package?

2019-04-16 Thread Matt Harden
I think the docs on os.Signal explain it: The only signal values guaranteed to be present in the os package on all systems are os.Interrupt (send the process an interrupt) and os.Kill (force the process to exit). On Windows, sending os.Interrupt to a process with os.Process.Signal is not implement

Re: [go-nuts] Concurrency safe struct access

2019-04-14 Thread Matt Harden
No, you don't need sync/atomic. The mutex is sufficient. By the way, you should put the mutex inside of guardedState, next to the data being guarded. Had you done that originally, Go Vet would have complained about you passing guardedState by value (mutexes should never by copied). https://play.go

Re: [go-nuts] Re: Persistence of value, or Safely close what you expected

2019-03-13 Thread Matt Harden
On Wed, Mar 13, 2019 at 4:01 PM Andrey Tcherepanov < xnow4fippy...@sneakemail.com> wrote: > Roger, it is not that I wondering it is async assignments are bad, it is > more of a question "why does it have to be SO complicated"? > > (please forgive me for a long ranty post) > > There were couple of

Re: [go-nuts] Re: Unmarshal nested XML value from dynamic XML document

2019-02-24 Thread Matt Harden
You don't have to use an xml.Decoder. You may be able to use the `xml:",any"` tag for this case. type Response struct { XMLName xml.Name Return string `xml:"return"` } type Outer struct { XMLName struct{} `xml:"outer"` Responses []Response `xml:",any"` } https://play.golang.org/p/j4w4-1uuYa

Re: [go-nuts] Custom dialer for go-mail/mail?

2019-01-13 Thread Matt Harden
It looks like the thing to do is set mail.NetDialTimeout (see https://godoc.org/github.com/go-mail/mail#pkg-variables). Unfortunately, the socks proxy module doesn't appear to support timeouts. If you don't need connection timeouts, though, it should work to create your own DialTimeout that ignore

Re: [go-nuts] regexp: is there a way to match single byte ?

2018-12-29 Thread Matt Harden
I don't believe the regexp package allows matching of bytes rather than utf-8 sequences. On Sat, Dec 15, 2018 at 3:05 AM Tamás Gulácsi wrote: > For such a simple match, I'd use two bytes.Index with an if in a for cycle. > > -- > You received this message because you are subscribed to the Google

Re: [go-nuts] Pure functions and Go2

2018-12-16 Thread Matt Harden
In my opinion, it's even more useful to the programmer to know that a function is pure, than it is to the compiler. If checked by the compiler, the annotation is also useful to ensure that the function remains pure as it is modified over time. On Fri, Dec 14, 2018 at 2:57 PM 'Axel Wagner' via gola

Re: [go-nuts] When set time.Location, will be detected Data Race

2018-12-05 Thread Matt Harden
Just wrapping a write with a mutex is not enough; you have to wrap all the reads as well. In this case that's not possible because there are reads of time.Local all over the place. Anyway, as has been said, time.Local should never be written to in user code. On Fri, Nov 30, 2018 at 7:46 AM Agniva

Re: [go-nuts] How to make UDP server performance better?

2018-08-30 Thread Matt Harden
The time spent in the syscall would include time blocked, waiting for a packet to arrive. I would look at the other parts of the profile for possible improvements. The kernel may also be dropping packets if there is not enough buffer space to receive them into; see the SO_RCVBUF socket option. Mayb

Re: [go-nuts] Re: os.WriteFile not writing files in long running process

2018-08-29 Thread Matt Harden
>From the program's perspective the file is indeed flushed on close. The kernel deferring writes to disk can only have any effect if the system crashes, and the files will be flushed to disk within a short time anyway. You absolutely do NOT need to call fsync every file on close unless you require

Re: [go-nuts] glr support in goyacc?

2018-03-18 Thread Matt Harden
I believe Ian was saying he's not aware of anybody working on adding GLR support to goyacc. On Mon, Mar 12, 2018 at 1:23 AM David Wahlstedt < david.wahlstedt@gmail.com> wrote: > There are people working on it. This for instance: > https://github.com/chemikadze/asn1go > > Furthermore, if you w

Re: [go-nuts] Re: [Advice needed] How to vendor common dependencies for plugins

2018-03-18 Thread Matt Harden
Do you have to use plugins? I would avoid them whenever possible. What benefit do you expect to get from using them? On Sun, Mar 11, 2018 at 1:03 AM Jay Guo wrote: > Bump.. any thoughts? Thanks! > > - J > > > On Thursday, March 8, 2018 at 2:03:37 PM UTC+8, Jay Guo wrote: >> >> Golang gurus, >> >

Re: [go-nuts] Wrapping executable that takes input and output files such that it uses stdin and stdout instead (using named pipes)

2018-02-09 Thread Matt Harden
You need to close fIn after the copy is done. As it is now, fIn.Close() happens after io.Copy(os.Stdout, buf), which completes after your cat command finishes. But cat won't finish until its input pipe returns EOF, which happens after fIn.Close(). On Wed, Feb 7, 2018 at 5:46 PM Or Rikon wrote: >

Re: [go-nuts] How to get mount point or device name by directory?

2018-01-27 Thread Matt Harden
syscall.Stat_t does have the Dev field, which is documented by POSIX: https://linux.die.net/man/2/stat: "The st_dev field describes the device on which this file resides. (The major(3) and minor(3) macros may be useful to decompose the device ID in this field.)" In Go we don't have the major and m

Re: [go-nuts] Re: [ANN] Go Jupyter kernel and an interactive REPL

2018-01-27 Thread Matt Harden
That's very nice! On Wed, Jan 17, 2018 at 8:29 AM Glen Newton wrote: > Wow! This is great and positions Go better in the 'data science' world! > > Thanks, > Glen > > > On Tuesday, January 16, 2018 at 8:53:39 AM UTC-5, Yu Watanabe wrote: >> >> Hi Gophers, >> >> I developed a new Go's Jupyter Note

Re: [go-nuts] Re: Any plans to add ASN.1 PER support?

2018-01-27 Thread Matt Harden
It isn't something that is likely to be added to the stdlib. If anything, a library like https://github.com/Logicalis/asn1 might be interested in supporting it / accepting a pull request to add it. On Fri, Jan 12, 2018 at 9:50 AM David Wahlstedt < david.wahlstedt@gmail.com> wrote: > ASN.1 is

Re: [go-nuts] Re: Ensuring resource cleanup when app is killed

2018-01-24 Thread Matt Harden
When the program exits, all goroutines die instantly. The doc is saying that the program does not wait for any goroutine to complete except the "main" goroutine (the one that invoked the function main at startup). If you do want to wait for other goroutines to exit before exiting the program, which

Re: [go-nuts] How to know if interface{} data is nil w/o reflecting?

2017-12-30 Thread Matt Harden
ence type seems absurd to me. > > Matt > > > On Friday, December 29, 2017 at 11:07:31 PM UTC-6, Matt Harden wrote: > >> I really wish Go had not chosen to propagate Hoare's billion-dollar >> mistake. I do realize it's all tied up with the idea that initializa

Re: [go-nuts] Re: select is still a little unfair if there are more than 4 cases?

2017-12-29 Thread Matt Harden
n" > from? Xorshift+ is already good enough for most usages. > > PCG performance page didn't include results neither for xorshift128+, nor > for xoroshiro128. > > But xoroshiro page has comparisons: http://xoroshiro.di.unimi.it/#speed > > And, did you measure b

Re: [go-nuts] Re: GoLang dependency -> dep installation Issue , Burrow golang tool issues

2017-12-29 Thread Matt Harden
It's probably better to install the latest binary from the releases page ( https://github.com/golang/dep/releases), which is the first recommendation under Setup. On Mon, Dec 11, 2017 at 3:11 AM Arun Singh wrote: > *No* I have not been able to install the dep tool, I used this dep >

Re: [go-nuts] Re: multiple commands in one ssh session

2017-12-29 Thread Matt Harden
Did you try out my suggestion in reply to Dominik, namely to use session.Shell instead of session.Run? On Sat, Dec 9, 2017 at 3:38 AM wrote: > Hi Dominik. Have you finally found the solution? I'm working on similar > task to run commands on cisco routers. Could you share you code for this? > > >

Re: [go-nuts] How to know if interface{} data is nil w/o reflecting?

2017-12-29 Thread Matt Harden
I really wish Go had not chosen to propagate Hoare's billion-dollar mistake. I do realize it's all tied up with the idea that initialization is cheap and zero values should be useful when possible, and therefore pointers, interfaces, channels, etc. need zero values. I wonder how different Go would

Re: [go-nuts] Re: select is still a little unfair if there are more than 4 cases?

2017-12-29 Thread Matt Harden
PCG isn't faster than xorshift+multiplication? Do you have a rebuttal to their website that indicates it is? (called xorshift* on that page) http://www.pcg-random.org/rng-performance.html Or are you just saying it's not meaningfully faster for the purpose of channels because the other channel over

Re: [go-nuts] Where to stick temporary go files after an AST rewrite?

2017-12-26 Thread Matt Harden
You can put them anywhere on your GOPATH. So for example, if you're on a unix-y system, $HOME/go is normally your GOPATH, and you want to rewrite the file $HOME/go/src/github.com/my/repo/hello.go, you could store the rewritten file at /tmp/go/src/github.com/my/repo/hello.go, and run the go tool wit

Re: [go-nuts] Go get -f still checking VCS

2017-12-26 Thread Matt Harden
AFAIK, go get can't download anything via "basic HTTP/S fetch". It always uses some kind of VCS. So if you don't have a VCS installed, go get won't work for you. You will need to determine all the dependencies yourself and place their source code in your GOPATH. On Wed, Oct 4, 2017 at 1:26 AM Volk

Re: [go-nuts] Go channels overused and hyped?

2017-08-20 Thread Matt Harden
Mutexes are good for a some low level tasks, and when you must have a shared data structure with no clear owner. When in doubt, and when designing your app, prefer communication over sharing, i.e. channels. On Fri, Aug 18, 2017, 16:03 John Souvestre wrote: > Interesting. So you think it is a ge

Re: [go-nuts] []T(nil) vs []T {}

2017-08-20 Thread Matt Harden
The first one is a type conversion, not the second. On Thu, Aug 17, 2017, 14:59 Soumya Mukherjee wrote: > Thank you both. I did not realize the latter syntax is that of a type > conversion. > > On Thursday, August 17, 2017 at 1:43:45 PM UTC-4, Axel Wagner wrote: >> >> >> >> On Thu, Aug 17, 2017

Re: [go-nuts] Computations with complex numbers may be slow if care is not taken

2017-08-03 Thread Matt Harden
So it sounds like the special case that would be helpful is when the real part of the complex base is 0. On Thu, Aug 3, 2017, 18:26 Dorival Pedroso wrote: > Thanks for the advice. > > This is the piece of code where I use that function: > // compute hat(Du) > pf := float64(p) > for j := 0; j < N

Re: [go-nuts] Is there some way to set value for unexported nil ptr field of a struct using reflect?

2017-07-27 Thread Matt Harden
Just to be clear, when using unsafe it's possible to do pretty much anything; reflect by itself doesn't give you this ability. That's by design AIUI. On Wed, Jul 26, 2017 at 6:53 PM feilengcui008 wrote: > Thanks for your answer :), even though the original question has been > deleted. > > I've u

Re: [go-nuts] Re: No Allman-Style, No go!

2017-07-27 Thread Matt Harden
"me": regarding purely functional programs, they can exist, but they can't actually "do" anything, since by definition, "doing" means altering some state in the outside world. But reasoning as much as possible in a functional way, and expressing your programs in this way (again as much as possible)

Re: [go-nuts] Understanding least significant byte operation

2017-07-25 Thread Matt Harden
unsigned integers as -1 > overflows. Therefore, -x in the case of unsigned types is interpreted > differently by the compiler, resulting in a ^x + 1 operation. Is that a > correct assumption? > > By the way, yes, the title should say Bit instead of Byte, sorry about the > confusion. &

Re: [go-nuts] Re: Merging several XML into 1

2017-07-25 Thread Matt Harden
The decoder will actually accumulate the pages for you, so you only need one Foo: https://play.golang.org/p/VDZvoJaSZW On Tue, Jul 25, 2017 at 6:56 AM wrote: > I change some structs so now it works as expected. > Here's the playground: https://play.golang.org/p/DXlajwirtt > > > On Tuesday, July

Re: [go-nuts] Parsing XML with namespaces in golang

2017-07-25 Thread Matt Harden
When you leave the namespace out, it will match that tag in *any* namespace (or none). On Mon, Jul 24, 2017 at 11:56 PM Konstantin Khomoutov wrote: > On Mon, Jul 24, 2017 at 07:44:33PM -0700, emartinez1...@gmail.com wrote: > > [...] > >>> So I'm trying to unmarshal an XML with namespaces in go b

Re: [go-nuts] Understanding least significant byte operation

2017-07-25 Thread Matt Harden
Both statements are true for both signed and unsigned integers. On Mon, Jul 24, 2017, 04:11 Pablo Rozas Larraondo < p.rozas.larrao...@gmail.com> wrote: > Thanks Bakul, I think I have a better understanding of what's going on > after reading your response. > > Is it correct to say that the Go comp

Re: [go-nuts] net/http: Redirect writes HTML for GET requests without setting Content-Type, how come?

2017-07-22 Thread Matt Harden
That sounds like a bug. The whole reason for including a message is for older user-agents that don't understand redirects (must be *really* old! So the Content-Type should be set as if responding normally to a GET request. I think Redirect should be setting Content-Type (perhaps only if it's not al

Re: [go-nuts] encoding/csv: Is this a bug?

2017-07-17 Thread Matt Harden
I suspect that this has to do with the line-ending characters on a Mac. I think Excel is writing the file with each line ending with a CR character. The encoding/csv package expects RFC 4180 format (each line terminated with CRLF), which is what Excel writes when you select "Windows Comma Separated

Re: [golang-dev] Re: [go-nuts] net: ReadMsg and reading error queue

2017-07-14 Thread Matt Harden
Take a look at https://godoc.org/golang.org/x/net/icmp#PacketTooBig On Fri, Jul 14, 2017 at 6:01 AM wrote: > I want to process the ICMP error and implement UDP PMTU discovery, so I > have to call recvmsg with MSG_ERRQUEUE > > It has been 4 years, any reasonable solutions for this problem?? > >

Re: [go-nuts] Help with mapping XML to struct

2017-07-14 Thread Matt Harden
The sample document you gave actually doesn't have any attributes at all. I guess you meant namespaces? Are you leaving out the namespace declarations from your sample? They usually look like xmlns:soapenv="http://some_url";. Those are important to parsing with namespaces in Go. If you don't have

Re: [go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-14 Thread Matt Harden
he Go program exits, and all other goroutines cease to exist. On Thu, Jul 13, 2017 at 11:56 PM wrote: > Well that makes sense! But shouldn't it have hung instead of exiting then? > > On Friday, July 14, 2017 at 12:01:36 PM UTC+10, Matt Harden wrote: > >> Oh! In retrospect, i

Re: [go-nuts] Customized Go template FuncMap example

2017-07-14 Thread Matt Harden
eturns your own template type instead. That's why I don't think it's a good idea to create your own Template type. On Fri, Jul 14, 2017 at 7:29 AM Tong Sun wrote: > On Thu, Jul 13, 2017 at 10:10 PM, Matt Harden wrote: > >> Can you do what you want just by building a

Re: [go-nuts] Customized Go template FuncMap example

2017-07-13 Thread Matt Harden
tomized template functions together using a series of > `.Funcs` calls. > > That's what I had in mind. Hope that I've express it clear enough. Thx. > > > On Sun, Jul 9, 2017 at 10:20 PM, Matt Harden > wrote: > >> Why are you trying to do that? It feels like yo

Re: [go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-13 Thread Matt Harden
Oh! In retrospect, it's obvious. The whole point of Shutdown() is to give running handlers a chance to finish, so if we call it from within a handler (and wait for it to finish there) then we have a deadlock. On Sun, Jul 9, 2017 at 10:10 PM wrote: > Yes! That works :-) Thanks so much. > > So app

Re: [go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-09 Thread Matt Harden
Try a channel to wait for shutdown in main. func main() { srv := &http.Server{Addr: ":8080", Handler: http.DefaultServeMux} *done := make(chan struct{})* http.Handle("/web/", http.FileServer(http.Dir("./"))) http.HandleFunc("/stop", func(w http.ResponseWriter, r *http.Request) {

Re: [go-nuts] Checking for expired certificates

2017-07-09 Thread Matt Harden
To detect revoked certificates, you have to either have a current CRL for the CA that issued the cert, or use OSCP. This doesn't appear to be easy to do in Go yet, but https://godoc.org/golang.org/x/crypto/ocsp may help. On Sat, Jul 8, 2017 at 1:06 AM gwhelbig via golang-nuts < golang-nuts@googleg

Re: [go-nuts] Customized Go template FuncMap example

2017-07-09 Thread Matt Harden
Why are you trying to do that? It feels like you're trying to do object-oriented programming in Go. Don't do that. What are you trying to achieve that the *template.Template type doesn't allow? If you just want a template with a FuncMap already applied, write a function to do that: func MyTemplat

Re: [go-nuts] Installing a package

2017-07-02 Thread Matt Harden
e pkg install location. > > On Mon, Jul 3, 2017, 9:02 AM Martin Spasov > wrote: > >> Does that mean that it is not possible to chose where you want to install >> the pkg ? >> On Mon, Jul 3, 2017 at 12:00 AM, Matt Harden >> wrote: >> >> I believe it&#x

Re: [go-nuts] Installing a package

2017-07-02 Thread Matt Harden
I believe it's the first folder in GOPATH, not the last. On Sun, Jul 2, 2017 at 1:21 PM wrote: > From what I found here when you install packages with go get, they get > installed in the last folder of your GOPATH env variable. Mine is > ''/home/Documents/GoProjects'' but the installed packages

Re: [go-nuts] multiple commands in one ssh session

2017-05-20 Thread Matt Harden
Instead of session.Run, use session.Shell. To interact with the shell, you will need to connect to at least Stdin, probably using StdinPipe() (NOTE I left out error handling): session, err := client.NewSession() in, err := session.StdinPipe() out, err := session.StdoutPipe() session.Stderr = out

Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-21 Thread Matt Harden
On Fri, Apr 21, 2017 at 12:43 AM Ian Davis wrote: > > > > On Fri, 21 Apr 2017, at 03:31 AM, Ivan Kurnosov wrote: > > @Rob, > > honestly to me they look the same: > > > func IsSorted(data Interface) bool { > n := data.Len() > for i := n - 1; i > 0; i-- { > if data.Less(i, i-1) { >

Re: [go-nuts] Zero value of the map

2017-04-21 Thread Matt Harden
collisions seem unavoidable. But I have no idea of the extra > cost of dealing with a "versioned" immutable map, where each new version is > not overwriting the previous one. > > > On Wednesday, April 19, 2017 at 4:12:20 AM UTC+2, Matt Harden wrote: > >> It seems to

Re: [go-nuts] Re: Semicolons in Go

2017-04-21 Thread Matt Harden
a = ( b + c + d * e ) On Thu, Apr 20, 2017 at 1:24 PM John McKown wrote: > On Thu, Apr 20, 2017 at 12:20 PM, Michael Jones > wrote: > >> >> On Thu, Apr 20, 2017 at 8:27 AM, wrote: >> >>> If I can't format my programs the way I want, and I much prefer putting >>> operato

Re: [go-nuts] doubt about sync.NewCond

2017-04-21 Thread Matt Harden
There is no guarantee that any of your goroutines will execute even Lock(), much less Wait(), before the main goroutine executes Broadcast(). On Thu, Apr 20, 2017 at 8:39 PM Allan wrote: > I run a demo program to learn sync.NewCond: > > package main > > import ( >"fmt" >"sync" >"time

Re: [go-nuts] Zero value of the map

2017-04-18 Thread Matt Harden
It seems to me the equivalent of append for maps is merge, which would be a very useful operation to have in its own right. A useful design for map could have been an immutable structure supporting literals, merge, lookup and delete operations, where all except lookup would return a new map value.

Re: [go-nuts] XML Stream Parser examples

2017-04-05 Thread Matt Harden
Here's my favorite way to handle such situations. It can probably be adapted to your situation. https://play.golang.org/p/FQ0g4rytz3 On Wed, Apr 5, 2017 at 4:44 PM Mandolyte wrote: > First, never thought I'd have to parse XML again (it's been over 10 > years), but life happens... > > After a lot

Re: [go-nuts] debugging with delve

2017-04-02 Thread Matt Harden
Add $GOHOME/bin to your $PATH. On Sun, Apr 2, 2017 at 8:56 AM Robert Solomon wrote: > I am a newbie to Go. I'm trying to figure out how to use delve, but I > think the documentation assumes I know more than I do. > > I did the go get command, and there were no errors. But when I try to > invok

Re: [go-nuts] Re: [ANN] fsq 1.4.0 released

2017-03-17 Thread Matt Harden
It's common to use go get to download programs as well, for instance goimports. On Sun, Mar 12, 2017, 21:25 wrote: > Thanks for the input! By 'checking', I assume you mean check y.go into the > git repository. I realize the motivation for this (go get), but since > parser.y contains the actual c

Re: [go-nuts] How to prevent net/http from canonicalizing request paths?

2017-03-02 Thread Matt Harden
You could wrap ServeMux with one that escapes // to /%2f (or use your own escaping mechanism) and then passes the request on to ServeMux. You would have to unescape the path in the handler or use a wrapper for that also. On Tue, Feb 28, 2017 at 12:16 AM tsuna wrote: > Hi there, > the code in > h

Re: [go-nuts] [Newbie] Why this code is so slow?

2017-02-25 Thread Matt Harden
It's not always faster than the JVM, but I'm pretty sure you can't be comparing exactly the same algorithm here. Can you post one or all of the other implementations? On Sat, Feb 25, 2017 at 6:38 PM Éric Jacoboni wrote: Hi, I'm just trying to learn Go and, as i do with other languages, i first

Re: [go-nuts] http: do not recover a panic

2017-02-25 Thread Matt Harden
I believe it's already been admitted to have been a mistake, and I don't know why we haven't created an option to turn it off (maybe because "Options Are Bad™"). On Sat, Feb 25, 2017 at 11:02 AM Manlio Perillo wrote: > I'm starting to use Go for the development of my web applications, but I > ca

Re: [go-nuts] Passing Already Accepted Connection to http.Serve()

2017-02-25 Thread Matt Harden
You're not waiting for the server to finish handling the connection before returning from main, which abruptly ends your program. Try importing context and using this at the end of main() (note that Shutdown was recently added): ctx := context.TODO() s

Re: [go-nuts] Reflection: Constructing a struct type that satisfies an interface

2017-02-22 Thread Matt Harden
Is the intermediate Go struct necessary, or do you just want to convert a text proto to a binary representation? On Wed, Feb 22, 2017 at 6:10 PM wrote: > Hi, > > I'm fiddling with gRPC and its service reflection. I discovered a neat > package (github.com/jhump/protoreflect) that let me quickly e

Re: [go-nuts] flag: possible issue with intValue.Set

2017-02-21 Thread Matt Harden
Sizeof does exist in the unsafe package and returns a compile time constant. On Tue, Feb 21, 2017, 13:56 Manlio Perillo wrote: > Il giorno martedì 21 febbraio 2017 22:14:38 UTC+1, Ian Lance Taylor ha > scritto: > > On Tue, Feb 21, 2017 at 9:51 AM, Manlio Perillo > wrote: > > I have noted that t

Re: [go-nuts] Question about net/http package implementation

2017-02-20 Thread Matt Harden
Oh, interesting. The code inline to his sentences is italicized like *this*. It looks like that gets surrounded by asterisks in the text-only version, leading to confusion in this case. On Sun, Feb 19, 2017 at 6:44 PM Dan Kortschak wrote: > On Sat, 2017-02-18 at 23:15 +0000, Matt Harden wr

Re: [go-nuts] Argument types of: anonymous function literals used as arguments of other function calls

2017-02-20 Thread Matt Harden
It looks like you're asking if you can leave out the parameter types in a function literal, and have them automatically derived from context. You can't currently. Are you asking for the language to be changed to allow it? On Sun, Feb 19, 2017 at 11:12 PM Marco Ippolito wrote: > Consider: > >

Re: [go-nuts] How do you implement and use Context.Done?

2017-02-19 Thread Matt Harden
Done does not need to be called unless you want to detect when the context is either canceled or times out. It doesn't have any effect on the context itself. On Sun, Feb 19, 2017 at 2:57 PM wrote: > Thanks, I see you build it up with decorators on a standard prototype. > For example: https://pla

Re: [go-nuts] is this race condition normal?

2017-02-19 Thread Matt Harden
Doing it in C would also require a mutex or other synchronization primitive. On Sun, Feb 19, 2017 at 7:11 AM Marwan abdel moneim wrote: > i didn't want to use Mutex because i wanted to learn the topic from the > beginning, and see how it could be done without channels or Mutex > > like how you c

Re: [go-nuts] Question about net/http package implementation

2017-02-18 Thread Matt Harden
Correction. They didn't say *r2 := *r; they said r2 := *r. Also read the example. They returned &r2 instead of r2. The code is equivalent to but shorter than the original. On Sat, Feb 18, 2017 at 3:11 PM Matt Harden wrote: They didn't say *r2 := *r; he said r2 := *r. Also re

Re: [go-nuts] Question about net/http package implementation

2017-02-18 Thread Matt Harden
They didn't say *r2 := *r; he said r2 := *r. Also read the example. They returned &r instead of r. The code is equivalent but shorter than the code in the package. On Sat, Feb 18, 2017 at 2:32 PM Dan Kortschak wrote: > On Fri, 2017-02-17 at 22:59 -0800, vova...@gmail.com wrote: > > I'm wondering

Re: [go-nuts] Initializing nested struct, by dynamically forming struct member path

2017-02-18 Thread Matt Harden
Why do you want to to this? What are you actually trying to accomplish? See http://xyproblem.info/ On Sat, Feb 18, 2017 at 7:04 AM wrote: > Hi, > > I am learning Go language and also to technical terms like in subject > "struct member path" (don't know if right). > > I need help to initialize a

Re: [go-nuts] Re: Why Go doesn't see my local package?

2017-02-18 Thread Matt Harden
https://github.com/golang/go/issues/3515#issuecomment-66066361 On Sat, Feb 18, 2017 at 7:04 AM Angel Java Lopez wrote: > Hi! > > Just curious... About: > > " don't use relative imports like the one you posted from the "The Way to > Go", that is't really what you are supposed to do. " > > Why? >

Re: [go-nuts] About 64bits alignment

2017-02-04 Thread Matt Harden
On Sat, Feb 4, 2017 at 7:34 AM 'Axel Wagner' via golang-nuts < golang-nuts@googlegroups.com> wrote: > I find this an inappropriate answer. Yes, they need care, but it should at > least be possible to figure out how to use them from reading documentation > (carefully). I tend to agree, that neither

Re: [go-nuts] About 64bits alignment

2017-02-03 Thread Matt Harden
that example. On Fri, Feb 3, 2017 at 8:49 PM T L wrote: > > > On Saturday, February 4, 2017 at 11:03:11 AM UTC+8, Matt Harden wrote: > > Never mind; I just realized that a WaitGroup is not necessarily at the > start of an allocation or global variable. > > > Not very get

Re: [go-nuts] About 64bits alignment

2017-02-03 Thread Matt Harden
Never mind; I just realized that a WaitGroup is not necessarily at the start of an allocation or global variable. On Fri, Feb 3, 2017 at 7:01 PM Matt Harden wrote: > Doesn't the statement "32-bit compilers to not ensure [64 bit alignment at > the start of an allocation]"

Re: [go-nuts] About 64bits alignment

2017-02-03 Thread Matt Harden
Doesn't the statement "32-bit compilers to not ensure [64 bit alignment at the start of an allocation]" contradict the sync/atomic statement "The first word in a global variable or in an allocated struct or slice can be relied upon to be 64-bit aligned."? On Fri, Feb 3, 2017 at 6:44 AM Ian Lance T

Re: [go-nuts] Parse JSON question

2017-01-30 Thread Matt Harden
https://play.golang.org/p/uvbJYQoqtl On Mon, Jan 30, 2017 at 7:39 AM Konstantin Khomoutov < flatw...@users.sourceforge.net> wrote: > On Mon, 30 Jan 2017 07:14:23 -0800 (PST) > Rich wrote: > > > If I have JSON that looks like this: > [...] > > > My question is that the JSON I have to parse the IP

Re: [go-nuts] Parse JSON question

2017-01-30 Thread Matt Harden
https://play.golang.org/p/uvbJYQoqtl On Mon, Jan 30, 2017 at 7:39 AM Konstantin Khomoutov < flatw...@users.sourceforge.net> wrote: > On Mon, 30 Jan 2017 07:14:23 -0800 (PST) > Rich wrote: > > > If I have JSON that looks like this: > [...] > > > My question is that the JSON I have to parse the IP

Re: [go-nuts] Question regarding goroutines

2017-01-24 Thread Matt Harden
connection reading from and writing to that central (sort of) queue. You still obviously need some form of coordination of access to the queue. On Tue, Jan 24, 2017 at 7:25 PM Matt Harden wrote: > Yes, a hang in one goroutine will spread to the rest of the goroutines, > because the loop in

Re: [go-nuts] Question regarding goroutines

2017-01-24 Thread Matt Harden
Yes, a hang in one goroutine will spread to the rest of the goroutines, because the loop in engine() is run while holding the lock on the map. If it hangs in Write(), any other goroutine trying to run engine() would block on m.Lock(). By the way, in main() you might as well just say server() inste

Re: [go-nuts] Re: Trying to use a Struct with a variable named "type" for JSON

2017-01-22 Thread Matt Harden
Note that you can't use lowercase struct field names with encoding/json anyway, because fields must be exported for encoding/json to see them, and fields are exported by starting them with an uppercase letter. So if you want the JSON field names to be lower case, you have to use struct tags. I thin

Re: [go-nuts] exec.Command("cp", "-r", "./*.json", artifact.dir fails with exit status 1

2017-01-17 Thread Matt Harden
In Go, don't try to combine those actions into a single line. Also you shouldn't ignore the error from filepath.Abs. On Tue, Jan 17, 2017 at 11:14 AM Deepak Jain wrote: > I fixed the error by invoking Copy command with abs source path. > > srcPath, _ := > e := util.Copy(srcPath, dst) > > If i co

Re: [go-nuts] encoding.BinaryMarshaler interface

2017-01-11 Thread Matt Harden
I would start with the naive implementation first, and only make it fancier (and more complicated) if that turns out not to be fast enough. Go's GC is pretty good already and getting better. You must not change the data in the returned slice after returning it, unless you somehow know that the cal

Re: [go-nuts] Re: How Can I Find Out The Number Of Empty Line On File

2017-01-04 Thread Matt Harden
Since the token is not actually used, sc.Bytes() can be used instead of sc.Text() to avoid allocation. On Wed, Jan 4, 2017 at 6:17 PM Dave Cheney wrote: > https://play.golang.org/p/dwYZTQ4qDs > > > On Thursday, 5 January 2017 12:28:48 UTC+11, Alihan Kayhan wrote: > > Hello > > I want to find emp

Re: [go-nuts] Re: http: TLS handshake error from :: EOF

2016-12-31 Thread Matt Harden
Oh sorry, I misunderstood the question. On Sat, Dec 31, 2016, 19:06 Matt Harden wrote: > Probably because we do? It's just that the default minimum version is > TLS1.1. > > On Sat, Dec 31, 2016, 17:04 Einthusan Vigneswaran < > einthu...@paperboardinc.com> wrote: >

Re: [go-nuts] Re: http: TLS handshake error from :: EOF

2016-12-31 Thread Matt Harden
Probably because we do? It's just that the default minimum version is TLS1.1. On Sat, Dec 31, 2016, 17:04 Einthusan Vigneswaran < einthu...@paperboardinc.com> wrote: > But what I don’t get is why SSL Labs test shows that we do indeed support > TLS 1.0? > > https://www.ssllabs.com/ssltest/analyze.

Re: [go-nuts] Re: Unexpected type switch case listing & equality behaviour for float64

2016-12-30 Thread Matt Harden
Values of different types cannot be compared in Go. *The int 0 cannot be compared to the float64 0.0.* I think the first line in your example is probably confusing you because Go is coercing those untyped numbers to the same type (float64, I believe) at compile time, then comparing the same types a

Re: [go-nuts] custom json unmarshaling between object or arrays

2016-12-29 Thread Matt Harden
https://play.golang.org/p/gWQuthS0D6 On Wed, Dec 28, 2016 at 11:55 PM Sathish VJ wrote: > aah, got it. the case []interface{}: is what I'd not gotten right. > Thanks for the detailed examples. > > > On Thursday, 29 December 2016 12:57:54 UTC+5:30, Konstantin Khomoutov > wrote: > > On Wed, 28 De

  1   2   >