aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/main.go51
-rw-r--r--cmd/ping.go31
2 files changed, 82 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}
diff --git a/cmd/ping.go b/cmd/ping.go
new file mode 100644
index 0000000..a046cb0
--- /dev/null
+++ b/cmd/ping.go
@@ -0,0 +1,31 @@
1package main
2
3import (
4 "bytes"
5 "codesaloon.com/torpedo"
6 "encoding/xml"
7 "fmt"
8 "net/url"
9)
10
11type ping struct {
12 torpedo.PostNotSupported
13 torpedo.PutNotSupported
14 torpedo.DeleteNotSupported
15}
16
17func (ping) Get(values url.Values) (int, string) {
18
19 data := &subsonicresponse{Version: "1.1.1", Status: "ok", Xmlns: "http://subsonic.org/restapi"}
20
21 buf := new(bytes.Buffer)
22 enc := xml.NewEncoder(buf)
23
24 if err := enc.Encode(data); err != nil {
25 fmt.Printf("error: %v\n", err)
26 } else {
27 fmt.Println(buf.String())
28 }
29
30 return 200, buf.String()
31}