1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00

Merge branch 'master' into regexps

This commit is contained in:
Daniel Melani 2016-10-23 15:43:23 +02:00
commit b9ba065ba4
4 changed files with 63 additions and 15 deletions

View file

@ -1,11 +1,25 @@
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()
lines, err := readLines(conf.Conf.FileName)
if err != nil {
return
}
pattern(conf.Res["getprotocol"], lines)
js, _ := json.Marshal(res)
w.Header().Set("Content-Type", "application/json")
w.Write(js)
}

View file

@ -1,19 +1,18 @@
package main
import (
"fmt"
"net/http"
"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{})
lines, err := readLines(conf.Conf.FileName)
if err != nil {
return
}
res["api"] = GetApiInfo()
pattern(conf.Res["getprotocol"], lines)
js, _ := json.Marshal(res)
w.Header().Set("Content-Type", "application/json")
w.Write(js)
}

View file

@ -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
View 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
}