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