From ffaa95b5f89cd43ee4e4c53c28ecbaeab6229daf Mon Sep 17 00:00:00 2001 From: Hunter Long Date: Sun, 24 Jun 2018 23:21:18 -0700 Subject: [PATCH] building --- .travis.yml | 18 +++++------ Dockerfile | 9 +++--- api.go | 28 +++++++++++++++-- build.sh | 29 ++++++++++++++---- html/js/setup.js | 5 +++ html/tmpl/setup.html | 2 +- services.go | 72 ++++---------------------------------------- 7 files changed, 75 insertions(+), 88 deletions(-) diff --git a/.travis.yml b/.travis.yml index a0647756..47f17be2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ services: env: global: - - VERSION=0.22 + - VERSION=0.23 matrix: allow_failures: @@ -33,14 +33,14 @@ deploy: - provider: releases api_key: $GH_TOKEN file: - - "build/statup-osx-x64" - - "build/statup-osx-x32" - - "build/statup-linux-x64" - - "build/statup-linux-x32" - - "build/statup-linux-arm64" - - "build/statup-linux-arm7" - - "build/statup-windows-x64.exe" - - "build/statup-linux-alpine" + - "build/statup-osx-x64.tar.gz" + - "build/statup-osx-x32.tar.gz" + - "build/statup-linux-x64.tar.gz" + - "build/statup-linux-x32.tar.gz" + - "build/statup-linux-arm64.tar.gz" + - "build/statup-linux-arm7.tar.gz" + - "build/statup-linux-alpine.tar.gz" + - "build/statup-windows-x64.zip" skip_cleanup: true notifications: diff --git a/Dockerfile b/Dockerfile index 5cc4af13..d956a4da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,12 @@ FROM alpine:latest -ENV VERSION=v0.22 +ENV VERSION=v0.23 RUN apk --no-cache add ca-certificates -RUN wget https://github.com/hunterlong/statup/releases/download/$VERSION/statup-linux-alpine && \ - chmod +x statup-linux-alpine && \ - mv statup-linux-alpine /usr/local/bin/statup +RUN wget https://github.com/hunterlong/statup/releases/download/$VERSION/statup-linux-alpine.tar.gz && \ + tar -xvzf statup-linux-alpine.tar.gz && \ + chmod +x statup && \ + mv statup /usr/local/bin/statup WORKDIR /app VOLUME /app RUN statup version diff --git a/api.go b/api.go index 89a42a71..b4de58f1 100644 --- a/api.go +++ b/api.go @@ -4,6 +4,9 @@ import ( "encoding/json" "github.com/gorilla/mux" "net/http" + "crypto/sha1" + "fmt" + "math/rand" ) func ApiIndexHandler(w http.ResponseWriter, r *http.Request) { @@ -27,11 +30,9 @@ func ApiServiceHandler(w http.ResponseWriter, r *http.Request) { func ApiServiceUpdateHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) service := SelectService(StringInt(vars["id"])) - var s Service decoder := json.NewDecoder(r.Body) decoder.Decode(&s) - json.NewEncoder(w).Encode(service) } @@ -50,3 +51,26 @@ func ApiAllUsersHandler(w http.ResponseWriter, r *http.Request) { users, _ := SelectAllUsers() json.NewEncoder(w).Encode(users) } + +func NewSHA1Hash(n ...int) string { + noRandomCharacters := 32 + if len(n) > 0 { + noRandomCharacters = n[0] + } + randString := RandomString(noRandomCharacters) + hash := sha1.New() + hash.Write([]byte(randString)) + bs := hash.Sum(nil) + return fmt.Sprintf("%x", bs) +} + +var characterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") + +// RandomString generates a random string of n length +func RandomString(n int) string { + b := make([]rune, n) + for i := range b { + b[i] = characterRunes[rand.Intn(len(characterRunes))] + } + return string(b) +} diff --git a/build.sh b/build.sh index bba54e5f..5a3b9ada 100755 --- a/build.sh +++ b/build.sh @@ -22,9 +22,26 @@ cd build ls cd ../ -mv build/$APP-darwin-10.6-amd64 build/$APP-osx-x64 -mv build/$APP-darwin-10.6-386 build/$APP-osx-x32 -mv build/$APP-linux-amd64 build/$APP-linux-x64 -mv build/$APP-linux-386 build/$APP-linux-x32 -mv build/$APP-windows-6.0-amd64.exe build/$APP-windows-x64.exe -mv build/$APP-linux-arm-7 build/$APP-linux-arm7 +mv build/$APP-darwin-10.6-amd64 build/$APP +tar -czvf build/$APP-osx-x64.tar.gz build/$APP + +mv build/$APP-darwin-10.6-386 build/$APP +tar -czvf build/$APP-osx-x32.tar.gz build/$APP + +mv build/$APP-linux-amd64 build/$APP +tar -czvf build/$APP-linux-x64.tar.gz build/$APP + +mv build/$APP-linux-386 build/$APP +tar -czvf build/$APP-linux-x32.tar.gz build/$APP + +mv build/$APP-windows-6.0-amd64.exe build/$APP.exe +zip $APP-windows-x64.zip build/$APP.exe + +mv build/$APP-linux-arm-7 build/$APP +tar -czvf build/$APP-linux-arm7.tar.gz build/$APP + +mv build/$APP-linux-arm64 build/$APP +tar -czvf build/$APP-linux-arm64.tar.gz build/$APP + +mv build/$APP-linux-alpine build/$APP +tar -czvf build/$APP-linux-alpine.tar.gz build/$APP \ No newline at end of file diff --git a/html/js/setup.js b/html/js/setup.js index de253c6e..a5933557 100644 --- a/html/js/setup.js +++ b/html/js/setup.js @@ -1,6 +1,11 @@ var currentLocation = window.location; $("#domain_input").val(currentLocation.origin); +function forceLower(strInput) +{ + strInput.value=strInput.value.toLowerCase(); +}​ + $('select#database_type').on('change', function(){ var selected = $('#database_type option:selected').val(); if (selected=="sqlite") { diff --git a/html/tmpl/setup.html b/html/tmpl/setup.html index 174943d1..d91db1ac 100644 --- a/html/tmpl/setup.html +++ b/html/tmpl/setup.html @@ -78,7 +78,7 @@
- +
diff --git a/services.go b/services.go index 0f3941db..e1a18911 100644 --- a/services.go +++ b/services.go @@ -1,10 +1,8 @@ package main import ( - "crypto/sha1" "encoding/json" "fmt" - "math/rand" "strconv" "time" "upper.io/db.v3" @@ -109,63 +107,28 @@ type DateScan struct { func (s *Service) GraphData() string { var d []DateScan - since := time.Now().Add(time.Hour*-12 + time.Minute*0 + time.Second*0) - sql := fmt.Sprintf("SELECT date_trunc('minute', created_at), AVG(latency)*1000 AS value FROM hits WHERE service=%v AND created_at > '%v' GROUP BY 1 ORDER BY date_trunc ASC;", s.Id, since.Format(time.RFC3339)) - - fmt.Println(sql) - dated, err := dbSession.Query(db.Raw(sql)) if err != nil { - panic(err) + fmt.Println(err) + return "" } - for dated.Next() { - var gd DateScan - var ff float64 - dated.Scan(&gd.CreatedAt, &ff) gd.Value = int64(ff) - d = append(d, gd) - } - + data, err := json.Marshal(d) if err != nil { - panic(err) + fmt.Println(err) + return "" } - // - //hits, _ := s.LimitedHits() - //for _, h := range hits { - // val := h.CreatedAt - // o := GraphJson{ - // X: val.String(), - // Y: h.Latency * 1000, - // } - // d = append(d, o) - //} - data, _ := json.Marshal(d) return string(data) } -//func (s *Service) GraphData() string { -// var d []GraphJson -// hits, _ := s.LimitedHits() -// for _, h := range hits { -// val := h.CreatedAt -// o := GraphJson{ -// X: val.String(), -// Y: h.Latency * 1000, -// } -// d = append(d, o) -// } -// data, _ := json.Marshal(d) -// return string(data) -//} - func (s *Service) AvgUptime() string { failed, _ := s.TotalFailures() total, _ := s.TotalHits() @@ -233,27 +196,4 @@ func CountOnline() int { } } return amount -} - -func NewSHA1Hash(n ...int) string { - noRandomCharacters := 32 - if len(n) > 0 { - noRandomCharacters = n[0] - } - randString := RandomString(noRandomCharacters) - hash := sha1.New() - hash.Write([]byte(randString)) - bs := hash.Sum(nil) - return fmt.Sprintf("%x", bs) -} - -var characterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") - -// RandomString generates a random string of n length -func RandomString(n int) string { - b := make([]rune, n) - for i := range b { - b[i] = characterRunes[rand.Intn(len(characterRunes))] - } - return string(b) -} +} \ No newline at end of file