StatusApp/server/server.go

31 lines
642 B
Go

package server
import (
"fmt"
"net/http"
"strconv"
)
var (
validTarget = make(map[string]bool)
)
func apiEndpoints() {
http.HandleFunc("/api/latest", allStatus)
http.HandleFunc("/api/history/day", dayHistory)
http.HandleFunc("/api/history/week", weekHistory)
http.HandleFunc("/api/history/month", monthHistory)
http.HandleFunc("/api/history/year", yearHistory)
}
func StartServer(port int, validTargets []string) {
for _, v := range validTargets {
validTarget[v] = true
}
apiEndpoints()
err := http.ListenAndServe(":"+strconv.Itoa(port), nil)
if err != nil {
fmt.Printf("ListenAndServe returned an error: %v", err)
}
}