News for hackers. Stuff that matters.
Re:Having a Go - first time experience with Golang by jgrahamc on Monday July 09, 2012 @09:19AM (#4217960)
When you write:

  cli_host := os.Getenv("STOMP_HOST")
  if cli_host != "" {
    client.Host = cli_host
  }
you would be more idiomatic if you use a ; like this:

  if cli_host := os.Getenv("STOMP_HOST"); cli_host != "" {
    client.Host = cli_host
  }
But given how repetitive your setOpts is I think I might have rewritten it something like this:

  func getEnv(e string, d string) (r string) {
    if r = os.Getenv(e); r == "" {
      r = d
    } 

    return
  }

  func (client *Client) setOpts() {
    client.Host = getEnv("STOMP_HOST", "localhost")
    client.Port = getEnv("STOMP_PORT", "62613")
    client.User = getEnv("STOMP_USER", "")
    client.Password = getEnv("STOMP_PASSWORD", "")
    client.Uuid = getEnv("STOMP_UUID", stompngo.Uuid())
  }
But then I have a thing about duplication.

Have fun with Go!

Re:Having a Go - first time experience with Golang by robotmay on Monday July 09, 2012 @09:22AM (#4217979)
Ah ha, I'd seen that style being used in a couple of libraries but I wasn't sure which was the more accepted standard. I'll make sure I use that format in the future.

Update for your update:

Aye, I wouldn't normally write so repetitively but I wasn't too sure about the best practice for things like that and I decided to just hash it out so I could play with the data. Thanks for the tips; I'm really keen to improve quickly with Go, as it's very enjoyable.

Re:Having a Go - first time experience with Golang by james4k on Monday July 09, 2012 @02:18PM (#4219553)
I've always had a bit of an issue with these if statements. It might be slightly more concise, but your code also isn't as straightforward to read. In fact, it's really only more concise in its use of vertical space, so for clarity's sake I'm not sure I see the point.