mirror of https://github.com/statping/statping
JS updates
parent
3c2bd33aad
commit
cdcfa2f481
|
@ -35,7 +35,7 @@ func Router() *mux.Router {
|
|||
dir := utils.Directory
|
||||
CacheStorage = NewStorage()
|
||||
r := mux.NewRouter()
|
||||
r.Handle("/", cached("120s", "text/html", http.HandlerFunc(indexHandler)))
|
||||
r.Handle("/", cached("15s", "text/html", http.HandlerFunc(indexHandler)))
|
||||
if source.UsingAssets(dir) {
|
||||
indexHandler := http.FileServer(http.Dir(dir + "/assets/"))
|
||||
r.PathPrefix("/css/").Handler(http.StripPrefix("/css/", http.FileServer(http.Dir(dir+"/assets/css"))))
|
||||
|
@ -94,7 +94,7 @@ func Router() *mux.Router {
|
|||
r.Handle("/api/services", http.HandlerFunc(apiCreateServiceHandler)).Methods("POST")
|
||||
r.Handle("/api/services/{id}", http.HandlerFunc(apiServiceHandler)).Methods("GET")
|
||||
r.Handle("/api/services/reorder", http.HandlerFunc(reorderServiceHandler)).Methods("POST")
|
||||
r.Handle("/api/services/{id}/data", cached("120s", "application/json", http.HandlerFunc(apiServiceDataHandler))).Methods("GET")
|
||||
r.Handle("/api/services/{id}/data", cached("30s", "application/json", http.HandlerFunc(apiServiceDataHandler))).Methods("GET")
|
||||
r.Handle("/api/services/{id}/ping", http.HandlerFunc(apiServicePingDataHandler)).Methods("GET")
|
||||
r.Handle("/api/services/{id}", http.HandlerFunc(apiServiceUpdateHandler)).Methods("POST")
|
||||
r.Handle("/api/services/{id}", http.HandlerFunc(apiServiceDeleteHandler)).Methods("DELETE")
|
||||
|
|
|
@ -109,7 +109,7 @@ function AjaxChart(chart, service, start=0, end=9999999999, group="hour") {
|
|||
url: "/api/services/"+service+"/data?start="+start+"&end="+end+"&group="+group,
|
||||
type: 'GET',
|
||||
success: function(data) {
|
||||
if (data.data.length <= 3) {
|
||||
if (data.data.length < 12) {
|
||||
AjaxChart(chart, service, 0, 9999999999, "second")
|
||||
return;
|
||||
} else if (data.data.length === 0) {
|
||||
|
|
|
@ -203,9 +203,9 @@ func copyAndCapture(w io.Writer, r io.Reader) ([]byte, error) {
|
|||
}
|
||||
|
||||
// DurationReadable will return a time.Duration into a human readable string
|
||||
// t := time.Duration(5 * time.Minute)
|
||||
// DurationReadable(t)
|
||||
// // 5 minutes
|
||||
// // t := time.Duration(5 * time.Minute)
|
||||
// // DurationReadable(t)
|
||||
// // returns: 5 minutes
|
||||
func DurationReadable(d time.Duration) string {
|
||||
if d.Hours() >= 1 {
|
||||
return fmt.Sprintf("%0.0f hours", d.Hours())
|
||||
|
@ -225,6 +225,12 @@ func SaveFile(filename string, data []byte) error {
|
|||
}
|
||||
|
||||
// HttpRequest is a global function to send a HTTP request
|
||||
// // url - The URL for HTTP request
|
||||
// // method - GET, POST, DELETE, PATCH
|
||||
// // content - The HTTP request content type (text/plain, application/json, or nil)
|
||||
// // headers - An array of Headers to be sent (KEY=VALUE) []string{"Authentication=12345", ...}
|
||||
// // body - The body or form data to send with HTTP request
|
||||
// // timeout - Specific duration to timeout on. time.Duration(30 * time.Seconds)
|
||||
func HttpRequest(url, method string, content interface{}, headers []string, body io.Reader, timeout time.Duration) ([]byte, *http.Response, error) {
|
||||
var err error
|
||||
transport := &http.Transport{
|
||||
|
|
Loading…
Reference in New Issue