title: converting curl command to golang conn.publish code
body: <p>I am trying to talk to server via Golang
  and I am unable to get it to work:</p>
  
  <p>However, the following CURL Command works:</p>
  
  <p>"curl <a href="http://localhost:8888/auth" rel="nofollow noreferrer">http://localhost:8888/auth</a>"</p>
  
  <p>I know the form is:  </p>
  
  <pre><code>&lt;subject&gt; &lt;payload length&gt; "\r\n" &lt;payload&gt;
  </code></pre>
  
  <p>but everything I try fails.</p>
  
  <p>The publish code is as follows:</p>
  
  <pre><code>// Publish takes a subject as an immutable string and payload inbytes,
  // then sends the message to the server.
  
  func (c *Client) Publish(subject string, payload []byte) error {
      c.Lock()
      pub := fmt.Sprintf("%s %d\r\n", subject, len(payload))
      _, err := c.w.WriteString(pub)
  
      if err == nil {
          _, err = c.w.Write(payload)
      }
      if err == nil {
          _, err = c.w.WriteString("\r\n")
      }
      if err == nil {
          err = c.w.Flush()
      }
      c.Unlock()
      if err != nil {
          return err
      }
  
      return nil
  }
  </code></pre>
  
  <p>I would appreciate any help that can be offered.</p>