diff options
| -rw-r--r-- | main.go | 48 |
1 files changed, 48 insertions, 0 deletions
| @@ -0,0 +1,48 @@ | |||
| 1 | package main | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "bytes" | ||
| 5 | "encoding/xml" | ||
| 6 | "fmt" | ||
| 7 | "github.com/sideshowdave7/torpedo" | ||
| 8 | "net/url" | ||
| 9 | ) | ||
| 10 | |||
| 11 | type 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 | |||
| 18 | type ping struct { | ||
| 19 | torpedo.PostNotSupported | ||
| 20 | torpedo.PutNotSupported | ||
| 21 | torpedo.DeleteNotSupported | ||
| 22 | } | ||
| 23 | |||
| 24 | func (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 | |||
| 40 | func 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 | } | ||