mirror of
https://github.com/alice-lg/birdwatcher.git
synced 2025-03-09 00:00:05 +01:00
Output api header in json. Odd
This commit is contained in:
parent
f331b7c350
commit
9aa4fe5dfe
4 changed files with 57 additions and 8 deletions
13
protocols.go
13
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)
|
||||
}
|
||||
|
|
13
routes.go
13
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)
|
||||
}
|
||||
|
|
11
status.go
11
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)
|
||||
}
|
||||
|
|
28
utils.go
Normal file
28
utils.go
Normal file
|
@ -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
|
||||
}
|
Loading…
Add table
Reference in a new issue