blob: 074a4f30c397729f6c4f060eec438ba1d3444706 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package main
import (
"bytes"
"codesaloon.com/torpedo"
"encoding/xml"
"flag"
"fmt"
"net/url"
)
type subsonicresponse struct {
XMLName xml.Name `xml:"subsonic-response"`
Xmlns string `xml:"xmlns,attr"`
Status string `xml:"status,attr"`
Version string `xml:"version,attr"`
}
type ping struct {
torpedo.PostNotSupported
torpedo.PutNotSupported
torpedo.DeleteNotSupported
}
func (ping) Get(values url.Values) (int, string) {
data := &subsonicresponse{Version: "1.1.1", Status: "ok", Xmlns: "http://subsonic.org/restapi"}
buf := new(bytes.Buffer)
enc := xml.NewEncoder(buf)
if err := enc.Encode(data); err != nil {
fmt.Printf("error: %v\n", err)
} else {
fmt.Println(buf.String())
}
return 200, buf.String()
}
func main() {
var port = flag.Int("port", 8000, "Port number to listen on")
flag.Parse()
ping := new(ping)
var api = new(torpedo.API)
api.AddResource(ping, "/rest/ping.view")
api.Start(*port)
}
|