mirror of https://github.com/statping/statping
testing - comments
parent
a65455d099
commit
138e81e1d1
23
cmd/doc.go
23
cmd/doc.go
|
@ -2,11 +2,26 @@
|
||||||
// connects to all the other packages to make a runnable binary for multiple
|
// connects to all the other packages to make a runnable binary for multiple
|
||||||
// operating system.
|
// operating system.
|
||||||
//
|
//
|
||||||
// To build Statup from source, run the follow command in the root directory:
|
// Compile Assets
|
||||||
// // go build -o statup ./cmd
|
|
||||||
//
|
//
|
||||||
// Remember that you'll need to compile the static assets using Rice:
|
// Before building, you must compile the Statup Assets with Rice, to install rice run the command below:
|
||||||
// // cd source && rice embed-go
|
// go get github.com/GeertJohan/go.rice
|
||||||
|
// go get github.com/GeertJohan/go.rice/rice
|
||||||
|
//
|
||||||
|
// Once you have rice install, you can run the following command to build all assets inside the source directory.
|
||||||
|
// cd source && rice embed-go
|
||||||
|
//
|
||||||
|
// Build Statup Binary
|
||||||
|
//
|
||||||
|
// To build the statup binary for your local environment, run the command below:
|
||||||
|
// go build -o statup ./cmd
|
||||||
|
//
|
||||||
|
// Build All Binary Arch's
|
||||||
|
//
|
||||||
|
// To build Statup for Mac, Windows, Linux, and ARM devices, you can run xgo to build for all. xgo is an awesome
|
||||||
|
// golang package that requires Docker. https://github.com/karalabe/xgo
|
||||||
|
// docker pull karalabe/xgo-latest
|
||||||
|
// build-all
|
||||||
//
|
//
|
||||||
// More info on: https://github.com/hunterlong/statup
|
// More info on: https://github.com/hunterlong/statup
|
||||||
package main
|
package main
|
||||||
|
|
|
@ -84,7 +84,7 @@ func UpdateCore(c *Core) (*Core, error) {
|
||||||
return c, db.Error
|
return c, db.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// UsingAssets will return true if /assets folder is present
|
// CurrentTime will return the current local time
|
||||||
func (c Core) CurrentTime() string {
|
func (c Core) CurrentTime() string {
|
||||||
t := time.Now().UTC()
|
t := time.Now().UTC()
|
||||||
current := utils.Timezoner(t, c.Timezone)
|
current := utils.Timezoner(t, c.Timezone)
|
||||||
|
@ -150,13 +150,13 @@ func SelectCore() (*Core, error) {
|
||||||
if os.Getenv("USE_CDN") == "true" {
|
if os.Getenv("USE_CDN") == "true" {
|
||||||
CoreApp.UseCdn = true
|
CoreApp.UseCdn = true
|
||||||
}
|
}
|
||||||
//store = sessions.NewCookieStore([]byte(core.ApiSecret))
|
|
||||||
return CoreApp, db.Error
|
return CoreApp, db.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceOrder will reorder the services based on 'order_id' (Order)
|
// ServiceOrder will reorder the services based on 'order_id' (Order)
|
||||||
type ServiceOrder []types.ServiceInterface
|
type ServiceOrder []types.ServiceInterface
|
||||||
|
|
||||||
|
// Sort interface for resroting the Services in order
|
||||||
func (c ServiceOrder) Len() int { return len(c) }
|
func (c ServiceOrder) Len() int { return len(c) }
|
||||||
func (c ServiceOrder) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
|
func (c ServiceOrder) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
|
||||||
func (c ServiceOrder) Less(i, j int) bool { return c[i].(*Service).Order < c[j].(*Service).Order }
|
func (c ServiceOrder) Less(i, j int) bool { return c[i].(*Service).Order < c[j].(*Service).Order }
|
||||||
|
|
|
@ -167,6 +167,8 @@ func (s *Service) lastFailure() *failure {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SmallText returns a short description about a services status
|
// SmallText returns a short description about a services status
|
||||||
|
// service.SmallText()
|
||||||
|
// // Online since Monday 3:04:05PM, Jan _2 2006
|
||||||
func (s *Service) SmallText() string {
|
func (s *Service) SmallText() string {
|
||||||
last := s.LimitedFailures()
|
last := s.LimitedFailures()
|
||||||
hits, _ := s.LimitedHits()
|
hits, _ := s.LimitedHits()
|
||||||
|
@ -188,6 +190,8 @@ func (s *Service) SmallText() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DowntimeText will return the amount of downtime for a service based on the duration
|
// DowntimeText will return the amount of downtime for a service based on the duration
|
||||||
|
// service.DowntimeText()
|
||||||
|
// // Service has been offline for 15 minutes
|
||||||
func (s *Service) DowntimeText() string {
|
func (s *Service) DowntimeText() string {
|
||||||
return fmt.Sprintf("%v has been offline for %v", s.Name, utils.DurationReadable(s.Downtime()))
|
return fmt.Sprintf("%v has been offline for %v", s.Name, utils.DurationReadable(s.Downtime()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ var (
|
||||||
func TestCreateCheckin(t *testing.T) {
|
func TestCreateCheckin(t *testing.T) {
|
||||||
service := SelectService(1)
|
service := SelectService(1)
|
||||||
testCheckin = ReturnCheckin(&types.Checkin{
|
testCheckin = ReturnCheckin(&types.Checkin{
|
||||||
Service: service.Id,
|
ServiceId: service.Id,
|
||||||
Interval: 10,
|
Interval: 10,
|
||||||
GracePeriod: 5,
|
GracePeriod: 5,
|
||||||
ApiKey: utils.RandomString(7),
|
ApiKey: utils.RandomString(7),
|
||||||
|
|
|
@ -68,6 +68,7 @@ func ToString(s interface{}) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Timezoner returns the time.Time with the user set timezone
|
||||||
func Timezoner(t time.Time, zone float32) time.Time {
|
func Timezoner(t time.Time, zone float32) time.Time {
|
||||||
zoneInt := float32(3600) * (zone + 1)
|
zoneInt := float32(3600) * (zone + 1)
|
||||||
loc := time.FixedZone("", int(zoneInt))
|
loc := time.FixedZone("", int(zoneInt))
|
||||||
|
@ -96,6 +97,8 @@ func (t Timestamp) Ago() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnderScoreString will return a string that replaces spaces and other characters to underscores
|
// UnderScoreString will return a string that replaces spaces and other characters to underscores
|
||||||
|
// UnderScoreString("Example String")
|
||||||
|
// // example_string
|
||||||
func UnderScoreString(str string) string {
|
func UnderScoreString(str string) string {
|
||||||
|
|
||||||
// convert every letter to lower case
|
// convert every letter to lower case
|
||||||
|
@ -120,6 +123,7 @@ func UnderScoreString(str string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileExists returns true if a file exists
|
// FileExists returns true if a file exists
|
||||||
|
// exists := FileExists("assets/css/base.css")
|
||||||
func FileExists(name string) bool {
|
func FileExists(name string) bool {
|
||||||
if _, err := os.Stat(name); err != nil {
|
if _, err := os.Stat(name); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
@ -130,6 +134,7 @@ func FileExists(name string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteFile will attempt to delete a file
|
// DeleteFile will attempt to delete a file
|
||||||
|
// DeleteFile("newfile.json")
|
||||||
func DeleteFile(file string) error {
|
func DeleteFile(file string) error {
|
||||||
Log(1, "deleting file: "+file)
|
Log(1, "deleting file: "+file)
|
||||||
err := os.Remove(file)
|
err := os.Remove(file)
|
||||||
|
@ -140,11 +145,13 @@ func DeleteFile(file string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteDirectory will attempt to delete a directory and all contents inside
|
// DeleteDirectory will attempt to delete a directory and all contents inside
|
||||||
|
// DeleteDirectory("assets")
|
||||||
func DeleteDirectory(directory string) error {
|
func DeleteDirectory(directory string) error {
|
||||||
return os.RemoveAll(directory)
|
return os.RemoveAll(directory)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command will run a terminal command with 'sh -c COMMAND' and return stdout and errOut as strings
|
// Command will run a terminal command with 'sh -c COMMAND' and return stdout and errOut as strings
|
||||||
|
// in, out, err := Command("sass assets/scss assets/css/base.css")
|
||||||
func Command(cmd string) (string, string, error) {
|
func Command(cmd string) (string, string, error) {
|
||||||
Log(1, "running command: "+cmd)
|
Log(1, "running command: "+cmd)
|
||||||
testCmd := exec.Command("sh", "-c", cmd)
|
testCmd := exec.Command("sh", "-c", cmd)
|
||||||
|
@ -199,6 +206,10 @@ 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
|
||||||
func DurationReadable(d time.Duration) string {
|
func DurationReadable(d time.Duration) string {
|
||||||
if d.Hours() >= 1 {
|
if d.Hours() >= 1 {
|
||||||
return fmt.Sprintf("%0.0f hours", d.Hours())
|
return fmt.Sprintf("%0.0f hours", d.Hours())
|
||||||
|
@ -210,7 +221,8 @@ func DurationReadable(d time.Duration) string {
|
||||||
return d.String()
|
return d.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveFile
|
// SaveFile will create a new file with data inside it
|
||||||
|
// SaveFile("newfile.json", []byte('{"data": "success"}')
|
||||||
func SaveFile(filename string, data []byte) error {
|
func SaveFile(filename string, data []byte) error {
|
||||||
err := ioutil.WriteFile(filename, data, 0644)
|
err := ioutil.WriteFile(filename, data, 0644)
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue