|
|
|
@ -28,7 +28,7 @@ import ( |
|
|
|
"encoding/json" |
|
|
|
"net/http" |
|
|
|
"strings" |
|
|
|
"os" |
|
|
|
//"os"
|
|
|
|
"io" |
|
|
|
) |
|
|
|
|
|
|
|
@ -41,10 +41,10 @@ type version struct { |
|
|
|
} |
|
|
|
|
|
|
|
func (handler *ApiHandler) ServeHTTP( |
|
|
|
response ResponseWriter, |
|
|
|
request *Request, |
|
|
|
response http.ResponseWriter, |
|
|
|
request *http.Request, |
|
|
|
) { |
|
|
|
dirs := strings.split(request.URL.Path, "/") |
|
|
|
dirs := strings.Split(request.URL.Path, "/") |
|
|
|
switch dirs[0] { |
|
|
|
case "version": |
|
|
|
v, err := json.Marshal( |
|
|
|
@ -55,21 +55,20 @@ func (handler *ApiHandler) ServeHTTP( |
|
|
|
}, |
|
|
|
) |
|
|
|
if err != nil { |
|
|
|
http.Error(w, "Unable to encode version information", 500) |
|
|
|
http.Error(response, "Unable to encode version information", 500) |
|
|
|
return |
|
|
|
} |
|
|
|
io.WriteString(w, string(v[:])) |
|
|
|
io.WriteString(response, string(v[:])) |
|
|
|
default: |
|
|
|
http.NotFound(w, req) |
|
|
|
http.NotFound(response, request) |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func router() { |
|
|
|
http.HandleFunc( |
|
|
|
"/api/0.0.1/", |
|
|
|
http.StripPrefix("/api/0.0.1/", ApiHandler{}), |
|
|
|
) |
|
|
|
handler := ApiHandler{} |
|
|
|
|
|
|
|
http.Handle("/api/0.0.1/", http.StripPrefix("/api/0.0.1/", &handler)) |
|
|
|
} |
|
|
|
|
|
|
|
// vim: ts=4 sts=4 sw=4 noet tw=72:
|