title: Send JSON to a unix socket with golang
body: <p>I'm trying to write a golang program to control <code>mpv</code> via issuing commands to a unix socket running at <code>/tmp/mpvsocket</code>.</p>
  
  <p>This is what I've tried so far:</p>
  
  <pre><code>func main() {                                     
    c, err := net.Dial("unix", "/tmp/mpvsocket")    
    if err != nil {                                 
      panic(err)                                    
    }                                               
    defer c.Close()                                 
  
    _, err = c.Write([]byte(`{"command":["quit"]}`))
    if err != nil {                                 
      log.Fatal("write error:", err)                
    }                                               
  }                                                 
  </code></pre>
  
  <p>This should cause mpv to quit but nothing happens.</p>
  
  <p>This command can be issued via the command line to get the expected results:</p>
  
  <pre><code>echo '{ "command": ["quit"] }' | socat - /tmp/mpvsocket
  </code></pre>
  
  <p>It uses <code>socat</code> to send the JSON to the socket. How can I send this to the socket using Golang?</p>