diff options
| author | jason | 2016-04-18 01:42:32 +0000 |
|---|---|---|
| committer | jason | 2016-04-18 01:42:32 +0000 |
| commit | 5f953277f8b141819f8c85ad829fe367b98ac6e5 (patch) | |
| tree | 9dd71e938901b96cfb6c96f37ec609c21128a89f /cmd | |
| parent | 380a772e585fdf116c846f77d28a6fa5f4ed51ec (diff) | |
| parent | 17bff1d0204a766d07ab127152fd006bc302138c (diff) | |
| download | torpedo-master.tar.gz torpedo-master.zip | |
add initial server with ping.view endpoint
Issue #1
See merge request !1
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/main.go | 51 | ||||
| -rw-r--r-- | cmd/ping.go | 31 |
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 @@ | |||
| 1 | package main | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "bytes" | ||
| 5 | "codesaloon.com/torpedo" | ||
| 6 | "encoding/xml" | ||
| 7 | "flag" | ||
| 8 | "fmt" | ||
| 9 | "net/url" | ||
| 10 | ) | ||
| 11 | |||
| 12 | type 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 | |||
| 19 | type ping struct { | ||
| 20 | torpedo.PostNotSupported | ||
| 21 | torpedo.PutNotSupported | ||
| 22 | torpedo.DeleteNotSupported | ||
| 23 | } | ||
| 24 | |||
| 25 | func (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 | |||
| 41 | func 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 @@ | |||
| 1 | package main | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "bytes" | ||
| 5 | "codesaloon.com/torpedo" | ||
| 6 | "encoding/xml" | ||
| 7 | "fmt" | ||
| 8 | "net/url" | ||
| 9 | ) | ||
| 10 | |||
| 11 | type ping struct { | ||
| 12 | torpedo.PostNotSupported | ||
| 13 | torpedo.PutNotSupported | ||
| 14 | torpedo.DeleteNotSupported | ||
| 15 | } | ||
| 16 | |||
| 17 | func (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 | } | ||