aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/main.go')
-rw-r--r--cmd/main.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/cmd/main.go b/cmd/main.go
new file mode 100644
index 0000000..074a4f3
--- /dev/null
+++ b/cmd/main.go
@@ -0,0 +1,51 @@
1package main
2
3import (
4 "bytes"
5 "codesaloon.com/torpedo"
6 "encoding/xml"
7 "flag"
8 "fmt"
9 "net/url"
10)
11
12type subsonicresponse struct {
13 XMLName xml.Name `xml:"subsonic-response"`
14 Xmlns string `xml:"xmlns,attr"`
15 Status string `xml:"status,attr"`
16 Version string `xml:"version,attr"`
17}
18
19type ping struct {
20 torpedo.PostNotSupported
21 torpedo.PutNotSupported
22 torpedo.DeleteNotSupported
23}
24
25func (ping) Get(values url.Values) (int, string) {
26
27 data := &subsonicresponse{Version: "1.1.1", Status: "ok", Xmlns: "http://subsonic.org/restapi"}
28
29 buf := new(bytes.Buffer)
30 enc := xml.NewEncoder(buf)
31
32 if err := enc.Encode(data); err != nil {
33 fmt.Printf("error: %v\n", err)
34 } else {
35 fmt.Println(buf.String())
36 }
37
38 return 200, buf.String()
39}
40
41func main() {
42 var port = flag.Int("port", 8000, "Port number to listen on")
43 flag.Parse()
44
45 ping := new(ping)
46
47 var api = new(torpedo.API)
48 api.AddResource(ping, "/rest/ping.view")
49 api.Start(*port)
50
51}