Showing
1 changed file
with
10 additions
and
11 deletions
| @@ -28,7 +28,7 @@ import ( | @@ -28,7 +28,7 @@ import ( | ||
| 28 | "encoding/json" | 28 | "encoding/json" |
| 29 | "net/http" | 29 | "net/http" |
| 30 | "strings" | 30 | "strings" |
| 31 | - "os" | 31 | + //"os" |
| 32 | "io" | 32 | "io" |
| 33 | ) | 33 | ) |
| 34 | 34 | ||
| @@ -41,10 +41,10 @@ type version struct { | @@ -41,10 +41,10 @@ type version struct { | ||
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | func (handler *ApiHandler) ServeHTTP( | 43 | func (handler *ApiHandler) ServeHTTP( |
| 44 | - response ResponseWriter, | ||
| 45 | - request *Request, | 44 | + response http.ResponseWriter, |
| 45 | + request *http.Request, | ||
| 46 | ) { | 46 | ) { |
| 47 | - dirs := strings.split(request.URL.Path, "/") | 47 | + dirs := strings.Split(request.URL.Path, "/") |
| 48 | switch dirs[0] { | 48 | switch dirs[0] { |
| 49 | case "version": | 49 | case "version": |
| 50 | v, err := json.Marshal( | 50 | v, err := json.Marshal( |
| @@ -55,21 +55,20 @@ func (handler *ApiHandler) ServeHTTP( | @@ -55,21 +55,20 @@ func (handler *ApiHandler) ServeHTTP( | ||
| 55 | }, | 55 | }, |
| 56 | ) | 56 | ) |
| 57 | if err != nil { | 57 | if err != nil { |
| 58 | - http.Error(w, "Unable to encode version information", 500) | 58 | + http.Error(response, "Unable to encode version information", 500) |
| 59 | return | 59 | return |
| 60 | } | 60 | } |
| 61 | - io.WriteString(w, string(v[:])) | 61 | + io.WriteString(response, string(v[:])) |
| 62 | default: | 62 | default: |
| 63 | - http.NotFound(w, req) | 63 | + http.NotFound(response, request) |
| 64 | return | 64 | return |
| 65 | } | 65 | } |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | func router() { | 68 | func router() { |
| 69 | - http.HandleFunc( | ||
| 70 | - "/api/0.0.1/", | ||
| 71 | - http.StripPrefix("/api/0.0.1/", ApiHandler{}), | ||
| 72 | - ) | 69 | + handler := ApiHandler{} |
| 70 | + | ||
| 71 | + http.Handle("/api/0.0.1/", http.StripPrefix("/api/0.0.1/", &handler)) | ||
| 73 | } | 72 | } |
| 74 | 73 | ||
| 75 | // vim: ts=4 sts=4 sw=4 noet tw=72: | 74 | // vim: ts=4 sts=4 sw=4 noet tw=72: |
Please
register
or
login
to post a comment