diff --git a/protocols.go b/protocols.go index 997c8ca..1e82171 100644 --- a/protocols.go +++ b/protocols.go @@ -1,11 +1,18 @@ package main import ( - "fmt" + "encoding/json" "github.com/julienschmidt/httprouter" "net/http" ) -func Routes(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { - fmt.Fprint(w, "routes\n") +func Protocols(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + res := make(map[string]interface{}) + + res["api"] = GetApiInfo() + + js, _ := json.Marshal(res) + + w.Header().Set("Content-Type", "application/json") + w.Write(js) } diff --git a/routes.go b/routes.go index 0392dd0..ac8a7bd 100644 --- a/routes.go +++ b/routes.go @@ -1,11 +1,18 @@ package main import ( - "fmt" + "encoding/json" "github.com/julienschmidt/httprouter" "net/http" ) -func Protocols(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { - fmt.Fprint(w, "protocols\n") +func Routes(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { + res := make(map[string]interface{}) + + res["api"] = GetApiInfo() + + js, _ := json.Marshal(res) + + w.Header().Set("Content-Type", "application/json") + w.Write(js) } diff --git a/status.go b/status.go index 65f341f..0bb104f 100644 --- a/status.go +++ b/status.go @@ -1,11 +1,18 @@ package main import ( - "fmt" + "encoding/json" "github.com/julienschmidt/httprouter" "net/http" ) func Status(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { - fmt.Fprint(w, "status\n") + res := make(map[string]interface{}) + + res["api"] = GetApiInfo() + + js, _ := json.Marshal(res) + + w.Header().Set("Content-Type", "application/json") + w.Write(js) } diff --git a/utils.go b/utils.go new file mode 100644 index 0000000..a034053 --- /dev/null +++ b/utils.go @@ -0,0 +1,28 @@ +package main + +type TimeInfo struct { + Date string `json:"date"` + TimezoneType string `json:"timezone_type"` + Timezone string `json:"timezone"` +} + +type CacheStatus struct { + OrigTTL int `json:"orig_ttl"` + CachedAt TimeInfo `json:"cached_at"` +} + +type APIInfo struct { + Version string + ResultFromCache bool `json:"result_from_cache"` + CacheStatus CacheStatus `json:"cache_status"` +} + +func GetApiInfo() *APIInfo { + ai := &APIInfo{} + + /* Dummy data until we implement caching */ + ai.Version = "1.0" + ai.ResultFromCache = false + + return ai +}