2020-04-23 07:42:16 +07:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
func apiEndpoints() {
|
|
|
|
http.HandleFunc("/api/latest", allStatus)
|
2020-04-23 12:55:30 +07:00
|
|
|
http.HandleFunc("/api/history/day", dayHistory)
|
2020-04-23 13:44:23 +07:00
|
|
|
http.HandleFunc("/api/history/week", weekHistory)
|
2020-04-23 13:49:23 +07:00
|
|
|
http.HandleFunc("/api/history/month", monthHistory)
|
|
|
|
http.HandleFunc("/api/history/year", yearHistory)
|
2020-04-23 07:42:16 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
func StartServer(port int) {
|
|
|
|
apiEndpoints()
|
|
|
|
err := http.ListenAndServe(":"+strconv.Itoa(port), nil)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("ListenAndServe returned an error: %v", err)
|
|
|
|
}
|
|
|
|
}
|