Commit e4be5e7e authored by Aksel Baardsen's avatar Aksel Baardsen
Browse files

a try for /diag/

parent 12bd11c4
......@@ -12,6 +12,7 @@ import (
//returns json ready for parsing as string
func main() {
r := mux.NewRouter()
c := r.PathPrefix("/conservation/v1").Methods("GET").Subrouter()
......@@ -45,7 +46,13 @@ func helloHandle(w http.ResponseWriter, r *http.Request) {
*/
func dHandler(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprintln(w, "aiaiai")
//_, _ = fmt.Fprintln(w, "aiaiai")
var d pkg.Diag
pkg.GetDiag(&d)
marsh, _ := json.Marshal(d)
fmt.Fprintln(w, string(marsh))
}
......
package pkg
import (
"log"
"net/http"
)
const gbifApi = "http://api.gbif.org/v1/"
const restApi = "https://restcountries.eu/rest/v2"
type Diag struct {
Gbif string `json:"gbif"`
Restcountries string `json:"restcountries"`
Gbif int `json:"gbif"`
Restcountries int `json:"restcountries"`
Version string `json:"version"`
Uptime string `json:"uptime"`
}
func GetDiag(d* Diag) {
getGbifStatus(d)
getRestStatus(d)
getVersion(d)
getUptime(d)
}
func getGbifStatus(d *Diag) {
resp, err := http.Get(gbifApi)
if err != nil {
log.Fatal(err)
}
d.Gbif = resp.StatusCode
}
func getRestStatus(d *Diag) {
resp, err := http.Get(restApi)
if err != nil {
log.Fatal(err)
}
d.Restcountries = resp.StatusCode
}
func getVersion(d *Diag) {
d.Version = "v1"
}
func getUptime(d *Diag) {
d.Uptime = "42sec"
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment