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:
commit
b9ba065ba4
4 changed files with 63 additions and 15 deletions
20
protocols.go
20
protocols.go
|
@ -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)
|
||||
}
|
||||
|
|
19
routes.go
19
routes.go
|
@ -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)
|
||||
}
|
||||
|
|
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