# core
`import "github.com/hunterlong/statup/core"`
* [Overview](#pkg-overview)
* [Index](#pkg-index)
* [Subdirectories](#pkg-subdirectories)
## Overview
Package core contains the main functionality of Statup. This includes everything for
Services, Hits, Failures, Users, service checking mechanisms, databases, and notifiers
in the notifier package
More info on: https://github.com/hunterlong/statup
## Index
* [Variables](#pkg-variables)
* [func AuthUser(username, password string) (*user, bool)](#AuthUser)
* [func CheckHash(password, hash string) bool](#CheckHash)
* [func CloseDB()](#CloseDB)
* [func CountFailures() uint64](#CountFailures)
* [func DatabaseMaintence()](#DatabaseMaintence)
* [func Dbtimestamp(group string, column string) string](#Dbtimestamp)
* [func DefaultPort(db string) int64](#DefaultPort)
* [func DeleteAllSince(table string, date time.Time)](#DeleteAllSince)
* [func DeleteConfig() error](#DeleteConfig)
* [func ExportChartsJs() string](#ExportChartsJs)
* [func ExportIndexHTML() string](#ExportIndexHTML)
* [func InitApp()](#InitApp)
* [func InsertLargeSampleData() error](#InsertLargeSampleData)
* [func InsertNotifierDB() error](#InsertNotifierDB)
* [func InsertSampleData() error](#InsertSampleData)
* [func InsertSampleHits() error](#InsertSampleHits)
* [func ReturnCheckinHit(c *types.CheckinHit) *checkinHit](#ReturnCheckinHit)
* [func ReturnUser(u *types.User) *user](#ReturnUser)
* [func SampleData() error](#SampleData)
* [func SelectAllUsers() ([]*user, error)](#SelectAllUsers)
* [func SelectUser(id int64) (*user, error)](#SelectUser)
* [func SelectUsername(username string) (*user, error)](#SelectUsername)
* [func Services() []types.ServiceInterface](#Services)
* [type Checkin](#Checkin)
* [func ReturnCheckin(c *types.Checkin) *Checkin](#ReturnCheckin)
* [func SelectCheckin(api string) *Checkin](#SelectCheckin)
* [func SelectCheckinId(id int64) *Checkin](#SelectCheckinId)
* [func (c *Checkin) AfterFind() (err error)](#Checkin.AfterFind)
* [func (c *Checkin) BeforeCreate() (err error)](#Checkin.BeforeCreate)
* [func (c *Checkin) Create() (int64, error)](#Checkin.Create)
* [func (c *Checkin) CreateFailure() (int64, error)](#Checkin.CreateFailure)
* [func (c *Checkin) Delete() error](#Checkin.Delete)
* [func (c *Checkin) Expected() time.Duration](#Checkin.Expected)
* [func (c *Checkin) Grace() time.Duration](#Checkin.Grace)
* [func (c *Checkin) Hits() []*checkinHit](#Checkin.Hits)
* [func (c *Checkin) Last() *checkinHit](#Checkin.Last)
* [func (c *Checkin) Link() string](#Checkin.Link)
* [func (c *Checkin) Period() time.Duration](#Checkin.Period)
* [func (c *Checkin) RecheckCheckinFailure(guard chan struct{})](#Checkin.RecheckCheckinFailure)
* [func (c *Checkin) Routine()](#Checkin.Routine)
* [func (c *Checkin) Service() *Service](#Checkin.Service)
* [func (c *Checkin) String() string](#Checkin.String)
* [func (c *Checkin) Update() (int64, error)](#Checkin.Update)
* [type Core](#Core)
* [func NewCore() *Core](#NewCore)
* [func SelectCore() (*Core, error)](#SelectCore)
* [func UpdateCore(c *Core) (*Core, error)](#UpdateCore)
* [func (c Core) AllOnline() bool](#Core.AllOnline)
* [func (c Core) BaseSASS() string](#Core.BaseSASS)
* [func (c *Core) Count24HFailures() uint64](#Core.Count24HFailures)
* [func (c *Core) CountOnline() int](#Core.CountOnline)
* [func (c Core) CurrentTime() string](#Core.CurrentTime)
* [func (c Core) MobileSASS() string](#Core.MobileSASS)
* [func (c Core) SassVars() string](#Core.SassVars)
* [func (c *Core) SelectAllServices(start bool) ([]*Service, error)](#Core.SelectAllServices)
* [func (c *Core) ServicesCount() int](#Core.ServicesCount)
* [func (c *Core) ToCore() *types.Core](#Core.ToCore)
* [func (c Core) UsingAssets() bool](#Core.UsingAssets)
* [type DateScan](#DateScan)
* [type DateScanObj](#DateScanObj)
* [func GraphDataRaw(service types.ServiceInterface, start, end time.Time, group string, column string) *DateScanObj](#GraphDataRaw)
* [func (d *DateScanObj) ToString() string](#DateScanObj.ToString)
* [type DbConfig](#DbConfig)
* [func EnvToConfig() *DbConfig](#EnvToConfig)
* [func LoadConfigFile(directory string) (*DbConfig, error)](#LoadConfigFile)
* [func LoadUsingEnv() (*DbConfig, error)](#LoadUsingEnv)
* [func (db *DbConfig) Close() error](#DbConfig.Close)
* [func (db *DbConfig) Connect(retry bool, location string) error](#DbConfig.Connect)
* [func (c *DbConfig) CreateCore() *Core](#DbConfig.CreateCore)
* [func (db *DbConfig) CreateDatabase() error](#DbConfig.CreateDatabase)
* [func (db *DbConfig) DropDatabase() error](#DbConfig.DropDatabase)
* [func (db *DbConfig) InsertCore() (*Core, error)](#DbConfig.InsertCore)
* [func (db *DbConfig) MigrateDatabase() error](#DbConfig.MigrateDatabase)
* [func (db *DbConfig) Save() (*DbConfig, error)](#DbConfig.Save)
* [func (db *DbConfig) Update() error](#DbConfig.Update)
* [type ErrorResponse](#ErrorResponse)
* [type Hit](#Hit)
* [func (h *Hit) BeforeCreate() (err error)](#Hit.BeforeCreate)
* [type Message](#Message)
* [func ReturnMessage(m *types.Message) *Message](#ReturnMessage)
* [func SelectMessage(id int64) (*Message, error)](#SelectMessage)
* [func SelectMessages() ([]*Message, error)](#SelectMessages)
* [func SelectServiceMessages(id int64) []*Message](#SelectServiceMessages)
* [func (m *Message) Create() (int64, error)](#Message.Create)
* [func (m *Message) Delete() error](#Message.Delete)
* [func (m *Message) Service() *Service](#Message.Service)
* [func (m *Message) Update() (*Message, error)](#Message.Update)
* [type PluginJSON](#PluginJSON)
* [type PluginRepos](#PluginRepos)
* [type Service](#Service)
* [func ReturnService(s *types.Service) *Service](#ReturnService)
* [func SelectService(id int64) *Service](#SelectService)
* [func (s *Service) ActiveMessages() []*Message](#Service.ActiveMessages)
* [func (s *Service) AfterFind() (err error)](#Service.AfterFind)
* [func (s *Service) AllFailures() []*failure](#Service.AllFailures)
* [func (s *Service) AvgTime() float64](#Service.AvgTime)
* [func (s *Service) AvgUptime(ago time.Time) string](#Service.AvgUptime)
* [func (s *Service) AvgUptime24() string](#Service.AvgUptime24)
* [func (s *Service) BeforeCreate() (err error)](#Service.BeforeCreate)
* [func (s *Service) Check(record bool)](#Service.Check)
* [func (s *Service) CheckQueue(record bool)](#Service.CheckQueue)
* [func (s *Service) CheckinProcess()](#Service.CheckinProcess)
* [func (s *Service) Checkins() []*Checkin](#Service.Checkins)
* [func (s *Service) CountHits() (int64, error)](#Service.CountHits)
* [func (s *Service) Create(check bool) (int64, error)](#Service.Create)
* [func (s *Service) CreateFailure(f *types.Failure) (int64, error)](#Service.CreateFailure)
* [func (s *Service) CreateHit(h *types.Hit) (int64, error)](#Service.CreateHit)
* [func (s *Service) Delete() error](#Service.Delete)
* [func (s *Service) DeleteFailures()](#Service.DeleteFailures)
* [func (s *Service) Downtime() time.Duration](#Service.Downtime)
* [func (s *Service) DowntimeText() string](#Service.DowntimeText)
* [func (s *Service) Hits() ([]*types.Hit, error)](#Service.Hits)
* [func (s *Service) HitsBetween(t1, t2 time.Time, group string, column string) *gorm.DB](#Service.HitsBetween)
* [func (s *Service) LimitedCheckins() []*Checkin](#Service.LimitedCheckins)
* [func (s *Service) LimitedFailures() []*failure](#Service.LimitedFailures)
* [func (s *Service) LimitedHits() ([]*types.Hit, error)](#Service.LimitedHits)
* [func (s *Service) Messages() []*Message](#Service.Messages)
* [func (s *Service) Online24() float32](#Service.Online24)
* [func (s *Service) OnlineSince(ago time.Time) float32](#Service.OnlineSince)
* [func (s *Service) Select() *types.Service](#Service.Select)
* [func (s *Service) SmallText() string](#Service.SmallText)
* [func (s *Service) Sum() (float64, error)](#Service.Sum)
* [func (s *Service) ToJSON() string](#Service.ToJSON)
* [func (s *Service) TotalFailures() (uint64, error)](#Service.TotalFailures)
* [func (s *Service) TotalFailures24() (uint64, error)](#Service.TotalFailures24)
* [func (s *Service) TotalFailuresSince(ago time.Time) (uint64, error)](#Service.TotalFailuresSince)
* [func (s *Service) TotalHits() (uint64, error)](#Service.TotalHits)
* [func (s *Service) TotalHitsSince(ago time.Time) (uint64, error)](#Service.TotalHitsSince)
* [func (s *Service) TotalUptime() string](#Service.TotalUptime)
* [func (s *Service) Update(restart bool) error](#Service.Update)
* [func (s *Service) UpdateSingle(attr ...interface{}) error](#Service.UpdateSingle)
* [type ServiceOrder](#ServiceOrder)
* [func (c ServiceOrder) Len() int](#ServiceOrder.Len)
* [func (c ServiceOrder) Less(i, j int) bool](#ServiceOrder.Less)
* [func (c ServiceOrder) Swap(i, j int)](#ServiceOrder.Swap)
#### Package files
[checker.go](https://github.com/hunterlong/statup/tree/master/core/checker.go) [checkin.go](https://github.com/hunterlong/statup/tree/master/core/checkin.go) [configs.go](https://github.com/hunterlong/statup/tree/master/core/configs.go) [core.go](https://github.com/hunterlong/statup/tree/master/core/core.go) [database.go](https://github.com/hunterlong/statup/tree/master/core/database.go) [doc.go](https://github.com/hunterlong/statup/tree/master/core/doc.go) [export.go](https://github.com/hunterlong/statup/tree/master/core/export.go) [failures.go](https://github.com/hunterlong/statup/tree/master/core/failures.go) [hits.go](https://github.com/hunterlong/statup/tree/master/core/hits.go) [messages.go](https://github.com/hunterlong/statup/tree/master/core/messages.go) [sample.go](https://github.com/hunterlong/statup/tree/master/core/sample.go) [services.go](https://github.com/hunterlong/statup/tree/master/core/services.go) [users.go](https://github.com/hunterlong/statup/tree/master/core/users.go)
## Variables
``` go
var (
Configs *DbConfig // Configs holds all of the config.yml and database info
CoreApp *Core // CoreApp is a global variable that contains many elements
SetupMode bool // SetupMode will be true if Statup does not have a database connection
VERSION string // VERSION is set on build automatically by setting a -ldflag
)
```
``` go
var (
// DbSession stores the Statup database session
DbSession *gorm.DB
)
```
## func [AuthUser](https://github.com/hunterlong/statup/tree/master/core/users.go?s=2572:2626#L92)
``` go
func AuthUser(username, password string) (*user, bool)
```
AuthUser will return the user and a boolean if authentication was correct.
AuthUser accepts username, and password as a string
## func [CheckHash](https://github.com/hunterlong/statup/tree/master/core/users.go?s=2894:2936#L105)
``` go
func CheckHash(password, hash string) bool
```
CheckHash returns true if the password matches with a hashed bcrypt password
## func [CloseDB](https://github.com/hunterlong/statup/tree/master/core/database.go?s=2713:2727#L88)
``` go
func CloseDB()
```
CloseDB will close the database connection if available
## func [CountFailures](https://github.com/hunterlong/statup/tree/master/core/failures.go?s=2845:2872#L99)
``` go
func CountFailures() uint64
```
CountFailures returns the total count of failures for all services
## func [DatabaseMaintence](https://github.com/hunterlong/statup/tree/master/core/database.go?s=7223:7247#L248)
``` go
func DatabaseMaintence()
```
DatabaseMaintence will automatically delete old records from 'failures' and 'hits'
this function is currently set to delete records 7+ days old every 60 minutes
## func [Dbtimestamp](https://github.com/hunterlong/statup/tree/master/core/services.go?s=5865:5917#L206)
``` go
func Dbtimestamp(group string, column string) string
```
Dbtimestamp will return a SQL query for grouping by date
## func [DefaultPort](https://github.com/hunterlong/statup/tree/master/core/configs.go?s=3167:3200#L107)
``` go
func DefaultPort(db string) int64
```
DefaultPort accepts a database type and returns its default port
## func [DeleteAllSince](https://github.com/hunterlong/statup/tree/master/core/database.go?s=7556:7605#L258)
``` go
func DeleteAllSince(table string, date time.Time)
```
DeleteAllSince will delete a specific table's records based on a time.
## func [DeleteConfig](https://github.com/hunterlong/statup/tree/master/core/configs.go?s=4390:4415#L162)
``` go
func DeleteConfig() error
```
DeleteConfig will delete the 'config.yml' file
## func [ExportChartsJs](https://github.com/hunterlong/statup/tree/master/core/export.go?s=2294:2322#L88)
``` go
func ExportChartsJs() string
```
ExportChartsJs renders the charts for the index page
## func [ExportIndexHTML](https://github.com/hunterlong/statup/tree/master/core/export.go?s=980:1009#L32)
``` go
func ExportIndexHTML() string
```
ExportIndexHTML returns the HTML of the index page as a string
## func [InitApp](https://github.com/hunterlong/statup/tree/master/core/core.go?s=1675:1689#L60)
``` go
func InitApp()
```
InitApp will initialize Statup
## func [InsertLargeSampleData](https://github.com/hunterlong/statup/tree/master/core/sample.go?s=5545:5579#L207)
``` go
func InsertLargeSampleData() error
```
InsertLargeSampleData will create the example/dummy services for testing the Statup server
## func [InsertNotifierDB](https://github.com/hunterlong/statup/tree/master/core/core.go?s=1924:1953#L70)
``` go
func InsertNotifierDB() error
```
InsertNotifierDB inject the Statup database instance to the Notifier package
## func [InsertSampleData](https://github.com/hunterlong/statup/tree/master/core/sample.go?s=897:926#L27)
``` go
func InsertSampleData() error
```
InsertSampleData will create the example/dummy services for a brand new Statup installation
## func [InsertSampleHits](https://github.com/hunterlong/statup/tree/master/core/sample.go?s=3374:3403#L126)
``` go
func InsertSampleHits() error
```
InsertSampleHits will create a couple new hits for the sample services
## func [ReturnCheckinHit](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=1942:1996#L71)
``` go
func ReturnCheckinHit(c *types.CheckinHit) *checkinHit
```
ReturnCheckinHit converts *types.checkinHit to *core.checkinHit
## func [ReturnUser](https://github.com/hunterlong/statup/tree/master/core/users.go?s=911:947#L31)
``` go
func ReturnUser(u *types.User) *user
```
ReturnUser returns *core.user based off a *types.user
## func [SampleData](https://github.com/hunterlong/statup/tree/master/core/configs.go?s=4179:4202#L151)
``` go
func SampleData() error
```
SampleData runs all the sample data for a new Statup installation
## func [SelectAllUsers](https://github.com/hunterlong/statup/tree/master/core/users.go?s=2204:2242#L80)
``` go
func SelectAllUsers() ([]*user, error)
```
SelectAllUsers returns all users
## func [SelectUser](https://github.com/hunterlong/statup/tree/master/core/users.go?s=1025:1065#L36)
``` go
func SelectUser(id int64) (*user, error)
```
SelectUser returns the user based on the user's ID.
## func [SelectUsername](https://github.com/hunterlong/statup/tree/master/core/users.go?s=1226:1277#L43)
``` go
func SelectUsername(username string) (*user, error)
```
SelectUsername returns the user based on the user's username
## func [Services](https://github.com/hunterlong/statup/tree/master/core/services.go?s=1199:1239#L44)
``` go
func Services() []types.ServiceInterface
```
## type [Checkin](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=818:857#L26)
``` go
type Checkin struct {
*types.Checkin
}
```
### func [ReturnCheckin](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=1795:1840#L66)
``` go
func ReturnCheckin(c *types.Checkin) *Checkin
```
ReturnCheckin converts *types.Checking to *core.Checkin
### func [SelectCheckin](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=2646:2685#L94)
``` go
func SelectCheckin(api string) *Checkin
```
SelectCheckin will find a Checkin based on the API supplied
### func [SelectCheckinId](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=2847:2886#L101)
``` go
func SelectCheckinId(id int64) *Checkin
```
SelectCheckin will find a Checkin based on the API supplied
### func (\*Checkin) [AfterFind](https://github.com/hunterlong/statup/tree/master/core/database.go?s=3594:3635#L124)
``` go
func (c *Checkin) AfterFind() (err error)
```
AfterFind for Checkin will set the timezone
### func (\*Checkin) [BeforeCreate](https://github.com/hunterlong/statup/tree/master/core/database.go?s=4621:4665#L168)
``` go
func (c *Checkin) BeforeCreate() (err error)
```
BeforeCreate for Checkin will set CreatedAt to UTC
### func (\*Checkin) [Create](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=4352:4393#L154)
``` go
func (c *Checkin) Create() (int64, error)
```
Create will create a new Checkin
### func (\*Checkin) [CreateFailure](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=2134:2182#L80)
``` go
func (c *Checkin) CreateFailure() (int64, error)
```
### func (\*Checkin) [Delete](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=4218:4250#L147)
``` go
func (c *Checkin) Delete() error
```
Create will create a new Checkin
### func (\*Checkin) [Expected](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=3500:3542#L120)
``` go
func (c *Checkin) Expected() time.Duration
```
Expected returns the duration of when the serviec should receive a Checkin
### func (\*Checkin) [Grace](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=3290:3329#L114)
``` go
func (c *Checkin) Grace() time.Duration
```
Grace will return the duration of the Checkin Grace Period (after service hasn't responded, wait a bit for a response)
### func (\*Checkin) [Hits](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=4016:4054#L140)
``` go
func (c *Checkin) Hits() []*checkinHit
```
Hits returns all of the CheckinHits for a given Checkin
### func (\*Checkin) [Last](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=3727:3763#L129)
``` go
func (c *Checkin) Last() *checkinHit
```
Last returns the last checkinHit for a Checkin
### func (\*Checkin) [Link](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=3857:3888#L135)
``` go
func (c *Checkin) Link() string
```
### func (\*Checkin) [Period](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=3038:3078#L108)
``` go
func (c *Checkin) Period() time.Duration
```
Period will return the duration of the Checkin interval
### func (\*Checkin) [RecheckCheckinFailure](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=5358:5418#L196)
``` go
func (c *Checkin) RecheckCheckinFailure(guard chan struct{})
```
RecheckCheckinFailure will check if a Service Checkin has been reported yet
### func (\*Checkin) [Routine](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=974:1001#L35)
``` go
func (c *Checkin) Routine()
```
Routine for checking if the last Checkin was within its interval
### func (\*Checkin) [Service](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=2037:2073#L75)
``` go
func (c *Checkin) Service() *Service
```
### func (\*Checkin) [String](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=1680:1713#L61)
``` go
func (c *Checkin) String() string
```
String will return a Checkin API string
### func (\*Checkin) [Update](https://github.com/hunterlong/statup/tree/master/core/checkin.go?s=4621:4662#L167)
``` go
func (c *Checkin) Update() (int64, error)
```
Update will update a Checkin
## type [Core](https://github.com/hunterlong/statup/tree/master/core/core.go?s=952:985#L31)
``` go
type Core struct {
*types.Core
}
```
### func [NewCore](https://github.com/hunterlong/statup/tree/master/core/core.go?s=1411:1431#L47)
``` go
func NewCore() *Core
```
NewCore return a new *core.Core struct
### func [SelectCore](https://github.com/hunterlong/statup/tree/master/core/core.go?s=3756:3788#L136)
``` go
func SelectCore() (*Core, error)
```
SelectCore will return the CoreApp global variable and the settings/configs for Statup
### func [UpdateCore](https://github.com/hunterlong/statup/tree/master/core/core.go?s=2246:2285#L82)
``` go
func UpdateCore(c *Core) (*Core, error)
```
UpdateCore will update the CoreApp variable inside of the 'core' table in database
### func (Core) [AllOnline](https://github.com/hunterlong/statup/tree/master/core/core.go?s=3530:3560#L126)
``` go
func (c Core) AllOnline() bool
```
AllOnline will be true if all services are online
### func (Core) [BaseSASS](https://github.com/hunterlong/statup/tree/master/core/core.go?s=3033:3064#L109)
``` go
func (c Core) BaseSASS() string
```
BaseSASS is the base design , this opens the file /assets/scss/base.scss to be edited in Theme
### func (\*Core) [Count24HFailures](https://github.com/hunterlong/statup/tree/master/core/failures.go?s=2573:2613#L88)
``` go
func (c *Core) Count24HFailures() uint64
```
Count24HFailures returns the amount of failures for a service within the last 24 hours
### func (\*Core) [CountOnline](https://github.com/hunterlong/statup/tree/master/core/services.go?s=11724:11756#L421)
``` go
func (c *Core) CountOnline() int
```
CountOnline
### func (Core) [CurrentTime](https://github.com/hunterlong/statup/tree/master/core/core.go?s=2388:2422#L88)
``` go
func (c Core) CurrentTime() string
```
CurrentTime will return the current local time
### func (Core) [MobileSASS](https://github.com/hunterlong/statup/tree/master/core/core.go?s=3318:3351#L118)
``` go
func (c Core) MobileSASS() string
```
MobileSASS is the -webkit responsive custom css designs. This opens the
file /assets/scss/mobile.scss to be edited in Theme
### func (Core) [SassVars](https://github.com/hunterlong/statup/tree/master/core/core.go?s=2775:2806#L101)
``` go
func (c Core) SassVars() string
```
SassVars opens the file /assets/scss/variables.scss to be edited in Theme
### func (\*Core) [SelectAllServices](https://github.com/hunterlong/statup/tree/master/core/services.go?s=2230:2294#L82)
``` go
func (c *Core) SelectAllServices(start bool) ([]*Service, error)
```
SelectAllServices returns a slice of *core.Service to be store on []*core.Services, should only be called once on startup.
### func (\*Core) [ServicesCount](https://github.com/hunterlong/statup/tree/master/core/services.go?s=11645:11679#L416)
``` go
func (c *Core) ServicesCount() int
```
ServicesCount returns the amount of services inside the []*core.Services slice
### func (\*Core) [ToCore](https://github.com/hunterlong/statup/tree/master/core/core.go?s=1585:1620#L55)
``` go
func (c *Core) ToCore() *types.Core
```
ToCore will convert *core.Core to *types.Core
### func (Core) [UsingAssets](https://github.com/hunterlong/statup/tree/master/core/core.go?s=2616:2648#L96)
``` go
func (c Core) UsingAssets() bool
```
UsingAssets will return true if /assets folder is present
## type [DateScan](https://github.com/hunterlong/statup/tree/master/core/services.go?s=4211:4303#L155)
``` go
type DateScan struct {
CreatedAt string `json:"x,omitempty"`
Value int64 `json:"y"`
}
```
DateScan struct is for creating the charts.js graph JSON array
## type [DateScanObj](https://github.com/hunterlong/statup/tree/master/core/services.go?s=4374:4433#L161)
``` go
type DateScanObj struct {
Array []DateScan `json:"data"`
}
```
DateScanObj struct is for creating the charts.js graph JSON array
### func [GraphDataRaw](https://github.com/hunterlong/statup/tree/master/core/services.go?s=6940:7053#L243)
``` go
func GraphDataRaw(service types.ServiceInterface, start, end time.Time, group string, column string) *DateScanObj
```
GraphDataRaw will return all the hits between 2 times for a Service
### func (\*DateScanObj) [ToString](https://github.com/hunterlong/statup/tree/master/core/services.go?s=7878:7917#L272)
``` go
func (d *DateScanObj) ToString() string
```
ToString will convert the DateScanObj into a JSON string for the charts to render
## type [DbConfig](https://github.com/hunterlong/statup/tree/master/core/database.go?s=1216:1244#L39)
``` go
type DbConfig types.DbConfig
```
DbConfig stores the config.yml file for the statup configuration
### func [EnvToConfig](https://github.com/hunterlong/statup/tree/master/core/configs.go?s=3402:3430#L121)
``` go
func EnvToConfig() *DbConfig
```
EnvToConfig converts environment variables to a DbConfig variable
### func [LoadConfigFile](https://github.com/hunterlong/statup/tree/master/core/configs.go?s=1024:1080#L34)
``` go
func LoadConfigFile(directory string) (*DbConfig, error)
```
LoadConfigFile will attempt to load the 'config.yml' file in a specific directory
### func [LoadUsingEnv](https://github.com/hunterlong/statup/tree/master/core/configs.go?s=1688:1726#L53)
``` go
func LoadUsingEnv() (*DbConfig, error)
```
LoadUsingEnv will attempt to load database configs based on environment variables. If DB_CONN is set if will force this function.
### func (\*DbConfig) [Close](https://github.com/hunterlong/statup/tree/master/core/database.go?s=2827:2860#L95)
``` go
func (db *DbConfig) Close() error
```
Close shutsdown the database connection
### func (\*DbConfig) [Connect](https://github.com/hunterlong/statup/tree/master/core/database.go?s=5483:5545#L200)
``` go
func (db *DbConfig) Connect(retry bool, location string) error
```
Connect will attempt to connect to the sqlite, postgres, or mysql database
### func (\*DbConfig) [CreateCore](https://github.com/hunterlong/statup/tree/master/core/database.go?s=8715:8752#L305)
``` go
func (c *DbConfig) CreateCore() *Core
```
CreateCore will initialize the global variable 'CoreApp". This global variable contains most of Statup app.
### func (\*DbConfig) [CreateDatabase](https://github.com/hunterlong/statup/tree/master/core/database.go?s=9812:9854#L342)
``` go
func (db *DbConfig) CreateDatabase() error
```
CreateDatabase will CREATE TABLES for each of the Statup elements
### func (\*DbConfig) [DropDatabase](https://github.com/hunterlong/statup/tree/master/core/database.go?s=9212:9252#L327)
``` go
func (db *DbConfig) DropDatabase() error
```
DropDatabase will DROP each table Statup created
### func (\*DbConfig) [InsertCore](https://github.com/hunterlong/statup/tree/master/core/database.go?s=4991:5038#L184)
``` go
func (db *DbConfig) InsertCore() (*Core, error)
```
InsertCore create the single row for the Core settings in Statup
### func (\*DbConfig) [MigrateDatabase](https://github.com/hunterlong/statup/tree/master/core/database.go?s=10640:10683#L360)
``` go
func (db *DbConfig) MigrateDatabase() error
```
MigrateDatabase will migrate the database structure to current version.
This function will NOT remove previous records, tables or columns from the database.
If this function has an issue, it will ROLLBACK to the previous state.
### func (\*DbConfig) [Save](https://github.com/hunterlong/statup/tree/master/core/database.go?s=8187:8232#L285)
``` go
func (db *DbConfig) Save() (*DbConfig, error)
```
Save will initially create the config.yml file
### func (\*DbConfig) [Update](https://github.com/hunterlong/statup/tree/master/core/database.go?s=7824:7858#L267)
``` go
func (db *DbConfig) Update() error
```
Update will save the config.yml file
## type [ErrorResponse](https://github.com/hunterlong/statup/tree/master/core/configs.go?s=894:937#L29)
``` go
type ErrorResponse struct {
Error string
}
```
ErrorResponse is used for HTTP errors to show to user
## type [Hit](https://github.com/hunterlong/statup/tree/master/core/hits.go?s=782:813#L24)
``` go
type Hit struct {
*types.Hit
}
```
### func (\*Hit) [BeforeCreate](https://github.com/hunterlong/statup/tree/master/core/database.go?s=3931:3971#L136)
``` go
func (h *Hit) BeforeCreate() (err error)
```
BeforeCreate for Hit will set CreatedAt to UTC
## type [Message](https://github.com/hunterlong/statup/tree/master/core/messages.go?s=789:828#L25)
``` go
type Message struct {
*types.Message
}
```
### func [ReturnMessage](https://github.com/hunterlong/statup/tree/master/core/messages.go?s=1109:1154#L37)
``` go
func ReturnMessage(m *types.Message) *Message
```
ReturnMessage will convert *types.Message to *core.Message
### func [SelectMessage](https://github.com/hunterlong/statup/tree/master/core/messages.go?s=1429:1475#L49)
``` go
func SelectMessage(id int64) (*Message, error)
```
SelectMessage returns a Message based on the ID passed
### func [SelectMessages](https://github.com/hunterlong/statup/tree/master/core/messages.go?s=1219:1260#L42)
``` go
func SelectMessages() ([]*Message, error)
```
SelectMessages returns all messages
### func [SelectServiceMessages](https://github.com/hunterlong/statup/tree/master/core/messages.go?s=890:937#L30)
``` go
func SelectServiceMessages(id int64) []*Message
```
SelectServiceMessages returns all messages for a service
### func (\*Message) [Create](https://github.com/hunterlong/statup/tree/master/core/messages.go?s=1764:1805#L63)
``` go
func (m *Message) Create() (int64, error)
```
Create will create a Message and insert it into the database
### func (\*Message) [Delete](https://github.com/hunterlong/statup/tree/master/core/messages.go?s=2075:2107#L74)
``` go
func (m *Message) Delete() error
```
Delete will delete a Message from database
### func (\*Message) [Service](https://github.com/hunterlong/statup/tree/master/core/messages.go?s=1584:1620#L55)
``` go
func (m *Message) Service() *Service
```
### func (\*Message) [Update](https://github.com/hunterlong/statup/tree/master/core/messages.go?s=2208:2252#L80)
``` go
func (m *Message) Update() (*Message, error)
```
Update will update a Message in the database
## type [PluginJSON](https://github.com/hunterlong/statup/tree/master/core/core.go?s=883:915#L28)
``` go
type PluginJSON types.PluginJSON
```
## type [PluginRepos](https://github.com/hunterlong/statup/tree/master/core/core.go?s=916:950#L29)
``` go
type PluginRepos types.PluginRepos
```
## type [Service](https://github.com/hunterlong/statup/tree/master/core/services.go?s=900:939#L30)
``` go
type Service struct {
*types.Service
}
```
### func [ReturnService](https://github.com/hunterlong/statup/tree/master/core/services.go?s=1128:1173#L40)
``` go
func ReturnService(s *types.Service) *Service
```
ReturnService will convert *types.Service to *core.Service
### func [SelectService](https://github.com/hunterlong/statup/tree/master/core/services.go?s=1326:1363#L49)
``` go
func SelectService(id int64) *Service
```
SelectService returns a *core.Service from in memory
### func (\*Service) [ActiveMessages](https://github.com/hunterlong/statup/tree/master/core/services.go?s=11319:11364#L404)
``` go
func (s *Service) ActiveMessages() []*Message
```
ActiveMessages returns all Messages for a Service
### func (\*Service) [AfterFind](https://github.com/hunterlong/statup/tree/master/core/database.go?s=2944:2985#L100)
``` go
func (s *Service) AfterFind() (err error)
```
AfterFind for Service will set the timezone
### func (\*Service) [AllFailures](https://github.com/hunterlong/statup/tree/master/core/failures.go?s=1249:1291#L44)
``` go
func (s *Service) AllFailures() []*failure
```
AllFailures will return all failures attached to a service
### func (\*Service) [AvgTime](https://github.com/hunterlong/statup/tree/master/core/services.go?s=3132:3167#L114)
``` go
func (s *Service) AvgTime() float64
```
AvgTime will return the average amount of time for a service to response back successfully
### func (\*Service) [AvgUptime](https://github.com/hunterlong/statup/tree/master/core/services.go?s=8279:8328#L288)
``` go
func (s *Service) AvgUptime(ago time.Time) string
```
AvgUptime returns average online status for last 24 hours
### func (\*Service) [AvgUptime24](https://github.com/hunterlong/statup/tree/master/core/services.go?s=8109:8147#L282)
``` go
func (s *Service) AvgUptime24() string
```
AvgUptime24 returns a service's average online status for last 24 hours
### func (\*Service) [BeforeCreate](https://github.com/hunterlong/statup/tree/master/core/database.go?s=4446:4490#L160)
``` go
func (s *Service) BeforeCreate() (err error)
```
BeforeCreate for Service will set CreatedAt to UTC
### func (\*Service) [Check](https://github.com/hunterlong/statup/tree/master/core/checker.go?s=5586:5622#L222)
``` go
func (s *Service) Check(record bool)
```
Check will run checkHttp for HTTP services and checkTcp for TCP services
### func (\*Service) [CheckQueue](https://github.com/hunterlong/statup/tree/master/core/checker.go?s=1256:1297#L43)
``` go
func (s *Service) CheckQueue(record bool)
```
CheckQueue is the main go routine for checking a service
### func (\*Service) [CheckinProcess](https://github.com/hunterlong/statup/tree/master/core/services.go?s=1556:1590#L59)
``` go
func (s *Service) CheckinProcess()
```
CheckinProcess runs the checkin routine for each checkin attached to service
### func (\*Service) [Checkins](https://github.com/hunterlong/statup/tree/master/core/services.go?s=1742:1781#L68)
``` go
func (s *Service) Checkins() []*Checkin
```
Checkins will return a slice of Checkins for a Service
### func (\*Service) [CountHits](https://github.com/hunterlong/statup/tree/master/core/hits.go?s=1209:1253#L42)
``` go
func (s *Service) CountHits() (int64, error)
```
CountHits returns a int64 for all hits for a service
### func (\*Service) [Create](https://github.com/hunterlong/statup/tree/master/core/services.go?s=10712:10763#L382)
``` go
func (s *Service) Create(check bool) (int64, error)
```
Create will create a service and insert it into the database
### func (\*Service) [CreateFailure](https://github.com/hunterlong/statup/tree/master/core/failures.go?s=934:998#L32)
``` go
func (s *Service) CreateFailure(f *types.Failure) (int64, error)
```
CreateFailure will create a new failure record for a service
### func (\*Service) [CreateHit](https://github.com/hunterlong/statup/tree/master/core/hits.go?s=907:963#L29)
``` go
func (s *Service) CreateHit(h *types.Hit) (int64, error)
```
CreateHit will create a new 'hit' record in the database for a successful/online service
### func (\*Service) [Delete](https://github.com/hunterlong/statup/tree/master/core/services.go?s=9566:9598#L342)
``` go
func (s *Service) Delete() error
```
Delete will remove a service from the database, it will also end the service checking go routine
### func (\*Service) [DeleteFailures](https://github.com/hunterlong/statup/tree/master/core/failures.go?s=1698:1732#L59)
``` go
func (s *Service) DeleteFailures()
```
DeleteFailures will delete all failures for a service
### func (\*Service) [Downtime](https://github.com/hunterlong/statup/tree/master/core/services.go?s=6581:6623#L229)
``` go
func (s *Service) Downtime() time.Duration
```
Downtime returns the amount of time of a offline service
### func (\*Service) [DowntimeText](https://github.com/hunterlong/statup/tree/master/core/services.go?s=5664:5703#L201)
``` go
func (s *Service) DowntimeText() string
```
DowntimeText will return the amount of downtime for a service based on the duration
service.DowntimeText()
// Service has been offline for 15 minutes
### func (\*Service) [Hits](https://github.com/hunterlong/statup/tree/master/core/hits.go?s=1418:1464#L50)
``` go
func (s *Service) Hits() ([]*types.Hit, error)
```
Hits returns all successful hits for a service
### func (\*Service) [HitsBetween](https://github.com/hunterlong/statup/tree/master/core/database.go?s=2344:2429#L82)
``` go
func (s *Service) HitsBetween(t1, t2 time.Time, group string, column string) *gorm.DB
```
HitsBetween returns the gorm database query for a collection of service hits between a time range
### func (\*Service) [LimitedCheckins](https://github.com/hunterlong/statup/tree/master/core/services.go?s=1947:1993#L75)
``` go
func (s *Service) LimitedCheckins() []*Checkin
```
LimitedCheckins will return a slice of Checkins for a Service
### func (\*Service) [LimitedFailures](https://github.com/hunterlong/statup/tree/master/core/failures.go?s=1990:2036#L68)
``` go
func (s *Service) LimitedFailures() []*failure
```
LimitedFailures will return the last 10 failures from a service
### func (\*Service) [LimitedHits](https://github.com/hunterlong/statup/tree/master/core/hits.go?s=1685:1738#L58)
``` go
func (s *Service) LimitedHits() ([]*types.Hit, error)
```
LimitedHits returns the last 1024 successful/online 'hit' records for a service
### func (\*Service) [Messages](https://github.com/hunterlong/statup/tree/master/core/services.go?s=11163:11202#L398)
``` go
func (s *Service) Messages() []*Message
```
Messages returns all Messages for a Service
### func (\*Service) [Online24](https://github.com/hunterlong/statup/tree/master/core/services.go?s=3458:3494#L127)
``` go
func (s *Service) Online24() float32
```
Online24 returns the service's uptime percent within last 24 hours
### func (\*Service) [OnlineSince](https://github.com/hunterlong/statup/tree/master/core/services.go?s=3658:3710#L133)
``` go
func (s *Service) OnlineSince(ago time.Time) float32
```
OnlineSince accepts a time since parameter to return the percent of a service's uptime.
### func (\*Service) [Select](https://github.com/hunterlong/statup/tree/master/core/services.go?s=1001:1042#L35)
``` go
func (s *Service) Select() *types.Service
```
Select will return the *types.Service struct for Service
### func (\*Service) [SmallText](https://github.com/hunterlong/statup/tree/master/core/services.go?s=4792:4828#L178)
``` go
func (s *Service) SmallText() string
```
SmallText returns a short description about a services status
service.SmallText()
// Online since Monday 3:04:05PM, Jan _2 2006
### func (\*Service) [Sum](https://github.com/hunterlong/statup/tree/master/core/hits.go?s=2737:2777#L90)
``` go
func (s *Service) Sum() (float64, error)
```
Sum returns the added value Latency for all of the services successful hits.
### func (\*Service) [ToJSON](https://github.com/hunterlong/statup/tree/master/core/services.go?s=2950:2983#L108)
``` go
func (s *Service) ToJSON() string
```
ToJSON will convert a service to a JSON string
### func (\*Service) [TotalFailures](https://github.com/hunterlong/statup/tree/master/core/failures.go?s=3296:3345#L116)
``` go
func (s *Service) TotalFailures() (uint64, error)
```
TotalFailures returns the total amount of failures for a service
### func (\*Service) [TotalFailures24](https://github.com/hunterlong/statup/tree/master/core/failures.go?s=3097:3148#L110)
``` go
func (s *Service) TotalFailures24() (uint64, error)
```
TotalFailures24 returns the amount of failures for a service within the last 24 hours
### func (\*Service) [TotalFailuresSince](https://github.com/hunterlong/statup/tree/master/core/failures.go?s=3570:3637#L124)
``` go
func (s *Service) TotalFailuresSince(ago time.Time) (uint64, error)
```
TotalFailuresSince returns the total amount of failures for a service since a specific time/date
### func (\*Service) [TotalHits](https://github.com/hunterlong/statup/tree/master/core/hits.go?s=2168:2213#L74)
``` go
func (s *Service) TotalHits() (uint64, error)
```
TotalHits returns the total amount of successful hits a service has
### func (\*Service) [TotalHitsSince](https://github.com/hunterlong/statup/tree/master/core/hits.go?s=2413:2476#L82)
``` go
func (s *Service) TotalHitsSince(ago time.Time) (uint64, error)
```
TotalHitsSince returns the total amount of hits based on a specific time/date
### func (\*Service) [TotalUptime](https://github.com/hunterlong/statup/tree/master/core/services.go?s=8754:8792#L310)
``` go
func (s *Service) TotalUptime() string
```
TotalUptime returns the total uptime percent of a service
### func (\*Service) [Update](https://github.com/hunterlong/statup/tree/master/core/services.go?s=10228:10272#L363)
``` go
func (s *Service) Update(restart bool) error
```
Update will update a service in the database, the service's checking routine can be restarted by passing true
### func (\*Service) [UpdateSingle](https://github.com/hunterlong/statup/tree/master/core/services.go?s=10003:10060#L358)
``` go
func (s *Service) UpdateSingle(attr ...interface{}) error
```
UpdateSingle will update a single column for a service
## type [ServiceOrder](https://github.com/hunterlong/statup/tree/master/core/core.go?s=4316:4358#L155)
``` go
type ServiceOrder []types.ServiceInterface
```
ServiceOrder will reorder the services based on 'order_id' (Order)
### func (ServiceOrder) [Len](https://github.com/hunterlong/statup/tree/master/core/core.go?s=4414:4445#L158)
``` go
func (c ServiceOrder) Len() int
```
Sort interface for resroting the Services in order
### func (ServiceOrder) [Less](https://github.com/hunterlong/statup/tree/master/core/core.go?s=4544:4585#L160)
``` go
func (c ServiceOrder) Less(i, j int) bool
```
### func (ServiceOrder) [Swap](https://github.com/hunterlong/statup/tree/master/core/core.go?s=4474:4510#L159)
``` go
func (c ServiceOrder) Swap(i, j int)
```
# handlers
`import "github.com/hunterlong/statup/handlers"`
* [Overview](#pkg-overview)
* [Index](#pkg-index)
## Overview
Package handlers contains the HTTP server along with the requests and routes. All HTTP related
functions are in this package.
More info on: https://github.com/hunterlong/statup
## Index
* [func DesktopInit(ip string, port int)](#DesktopInit)
* [func IsAuthenticated(r *http.Request) bool](#IsAuthenticated)
* [func Router() *mux.Router](#Router)
* [func RunHTTPServer(ip string, port int) error](#RunHTTPServer)
* [type Cacher](#Cacher)
* [type Item](#Item)
* [func (item Item) Expired() bool](#Item.Expired)
* [type PluginSelect](#PluginSelect)
* [type Storage](#Storage)
* [func NewStorage() *Storage](#NewStorage)
* [func (s Storage) Delete(key string)](#Storage.Delete)
* [func (s Storage) Get(key string) []byte](#Storage.Get)
* [func (s Storage) Set(key string, content []byte, duration time.Duration)](#Storage.Set)
#### Package files
[api.go](https://github.com/hunterlong/statup/tree/master/handlers/api.go) [cache.go](https://github.com/hunterlong/statup/tree/master/handlers/cache.go) [dashboard.go](https://github.com/hunterlong/statup/tree/master/handlers/dashboard.go) [doc.go](https://github.com/hunterlong/statup/tree/master/handlers/doc.go) [handlers.go](https://github.com/hunterlong/statup/tree/master/handlers/handlers.go) [index.go](https://github.com/hunterlong/statup/tree/master/handlers/index.go) [messages.go](https://github.com/hunterlong/statup/tree/master/handlers/messages.go) [plugins.go](https://github.com/hunterlong/statup/tree/master/handlers/plugins.go) [prometheus.go](https://github.com/hunterlong/statup/tree/master/handlers/prometheus.go) [routes.go](https://github.com/hunterlong/statup/tree/master/handlers/routes.go) [services.go](https://github.com/hunterlong/statup/tree/master/handlers/services.go) [settings.go](https://github.com/hunterlong/statup/tree/master/handlers/settings.go) [setup.go](https://github.com/hunterlong/statup/tree/master/handlers/setup.go) [users.go](https://github.com/hunterlong/statup/tree/master/handlers/users.go)
## func [DesktopInit](https://github.com/hunterlong/statup/tree/master/handlers/index.go?s=1526:1563#L48)
``` go
func DesktopInit(ip string, port int)
```
DesktopInit will run the Statup server on a specific IP and port using SQLite database
## func [IsAuthenticated](https://github.com/hunterlong/statup/tree/master/handlers/handlers.go?s=2049:2091#L68)
``` go
func IsAuthenticated(r *http.Request) bool
```
IsAuthenticated returns true if the HTTP request is authenticated. You can set the environment variable GO_ENV=test
to bypass the admin authenticate to the dashboard features.
## func [Router](https://github.com/hunterlong/statup/tree/master/handlers/routes.go?s=980:1005#L34)
``` go
func Router() *mux.Router
```
Router returns all of the routes used in Statup
## func [RunHTTPServer](https://github.com/hunterlong/statup/tree/master/handlers/handlers.go?s=1141:1186#L43)
``` go
func RunHTTPServer(ip string, port int) error
```
RunHTTPServer will start a HTTP server on a specific IP and port
## type [Cacher](https://github.com/hunterlong/statup/tree/master/handlers/cache.go?s=141:267#L13)
``` go
type Cacher interface {
Get(key string) []byte
Delete(key string)
Set(key string, content []byte, duration time.Duration)
}
```
``` go
var CacheStorage Cacher
```
## type [Item](https://github.com/hunterlong/statup/tree/master/handlers/cache.go?s=299:356#L20)
``` go
type Item struct {
Content []byte
Expiration int64
}
```
Item is a cached reference
### func (Item) [Expired](https://github.com/hunterlong/statup/tree/master/handlers/cache.go?s=407:438#L26)
``` go
func (item Item) Expired() bool
```
Expired returns true if the item has expired.
## type [PluginSelect](https://github.com/hunterlong/statup/tree/master/handlers/plugins.go?s=725:814#L23)
``` go
type PluginSelect struct {
Plugin string
Form string
Params map[string]interface{}
}
```
## type [Storage](https://github.com/hunterlong/statup/tree/master/handlers/cache.go?s=586:653#L34)
``` go
type Storage struct {
// contains filtered or unexported fields
}
```
Storage mecanism for caching strings in memory
### func [NewStorage](https://github.com/hunterlong/statup/tree/master/handlers/cache.go?s=705:731#L40)
``` go
func NewStorage() *Storage
```
NewStorage creates a new in memory CacheStorage
### func (Storage) [Delete](https://github.com/hunterlong/statup/tree/master/handlers/cache.go?s=1031:1066#L60)
``` go
func (s Storage) Delete(key string)
```
### func (Storage) [Get](https://github.com/hunterlong/statup/tree/master/handlers/cache.go?s=846:885#L48)
``` go
func (s Storage) Get(key string) []byte
```
Get a cached content by key
### func (Storage) [Set](https://github.com/hunterlong/statup/tree/master/handlers/cache.go?s=1160:1232#L67)
``` go
func (s Storage) Set(key string, content []byte, duration time.Duration)
```
Set a cached content by key
# notifiers
`import "github.com/hunterlong/statup/notifiers"`
* [Overview](#pkg-overview)
* [Index](#pkg-index)
## Overview
Package notifiers holds all the notifiers for Statup, which also includes
user created notifiers that have been accepted in a Push Request. Read the wiki
to see a full example of a notifier with all events, visit Statup's
notifier example code: https://github.com/hunterlong/statup/wiki/Notifier-Example
This package shouldn't contain any exports, to see how notifiers work
visit the core/notifier package at: https://godoc.org/github.com/hunterlong/statup/core/notifier
and learn how to create your own custom notifier.
## Index
#### Package files
[command.go](https://github.com/hunterlong/statup/tree/master/notifiers/command.go) [discord.go](https://github.com/hunterlong/statup/tree/master/notifiers/discord.go) [doc.go](https://github.com/hunterlong/statup/tree/master/notifiers/doc.go) [email.go](https://github.com/hunterlong/statup/tree/master/notifiers/email.go) [line_notify.go](https://github.com/hunterlong/statup/tree/master/notifiers/line_notify.go) [mobile.go](https://github.com/hunterlong/statup/tree/master/notifiers/mobile.go) [slack.go](https://github.com/hunterlong/statup/tree/master/notifiers/slack.go) [twilio.go](https://github.com/hunterlong/statup/tree/master/notifiers/twilio.go) [webhook.go](https://github.com/hunterlong/statup/tree/master/notifiers/webhook.go)
# plugin
`import "github.com/hunterlong/statup/plugin"`
* [Overview](#pkg-overview)
* [Index](#pkg-index)
## Overview
Package plugin contains the interfaces to build your own Golang Plugin that will receive triggers on Statup events.
## Index
* [Variables](#pkg-variables)
* [func LoadPlugin(file string) error](#LoadPlugin)
* [func LoadPlugins()](#LoadPlugins)
#### Package files
[doc.go](https://github.com/hunterlong/statup/tree/master/plugin/doc.go) [plugin.go](https://github.com/hunterlong/statup/tree/master/plugin/plugin.go)
## Variables
``` go
var (
AllPlugins []*types.PluginObject
)
```
## func [LoadPlugin](https://github.com/hunterlong/statup/tree/master/plugin/plugin.go?s=1173:1207#L51)
``` go
func LoadPlugin(file string) error
```
## func [LoadPlugins](https://github.com/hunterlong/statup/tree/master/plugin/plugin.go?s=2670:2688#L96)
``` go
func LoadPlugins()
```
# source
`import "github.com/hunterlong/statup/source"`
* [Overview](#pkg-overview)
* [Index](#pkg-index)
* [Examples](#pkg-examples)
* [Subdirectories](#pkg-subdirectories)
## Overview
Package source holds all the assets for Statup. This includes
CSS, JS, SCSS, HTML and other website related content.
This package uses Rice to compile all assets into a single 'rice-box.go' file.
### Required Dependencies
- rice -> https://github.com/GeertJohan/go.rice
- sass -> https://sass-lang.com/install
### Compile Assets
To compile all the HTML, JS, SCSS, CSS and image assets you'll need to have rice and sass installed on your local system.
sass source/scss/base.scss source/css/base.css
cd source && rice embed-go
More info on: https://github.com/hunterlong/statup
## Index
* [Variables](#pkg-variables)
* [func Assets()](#Assets)
* [func CompileSASS(folder string) error](#CompileSASS)
* [func CopyAllToPublic(box *rice.Box, folder string) error](#CopyAllToPublic)
* [func CopyToPublic(box *rice.Box, folder, file string) error](#CopyToPublic)
* [func CreateAllAssets(folder string) error](#CreateAllAssets)
* [func DeleteAllAssets(folder string) error](#DeleteAllAssets)
* [func HelpMarkdown() string](#HelpMarkdown)
* [func MakePublicFolder(folder string) error](#MakePublicFolder)
* [func OpenAsset(folder, file string) string](#OpenAsset)
* [func SaveAsset(data []byte, folder, file string) error](#SaveAsset)
* [func UsingAssets(folder string) bool](#UsingAssets)
#### Examples
* [OpenAsset](#example_OpenAsset)
* [SaveAsset](#example_SaveAsset)
#### Package files
[doc.go](https://github.com/hunterlong/statup/tree/master/source/doc.go) [rice-box.go](https://github.com/hunterlong/statup/tree/master/source/rice-box.go) [source.go](https://github.com/hunterlong/statup/tree/master/source/source.go)
## Variables
``` go
var (
CssBox *rice.Box // CSS files from the 'source/css' directory, this will be loaded into '/assets/css'
ScssBox *rice.Box // SCSS files from the 'source/scss' directory, this will be loaded into '/assets/scss'
JsBox *rice.Box // JS files from the 'source/js' directory, this will be loaded into '/assets/js'
TmplBox *rice.Box // HTML and other small files from the 'source/tmpl' directory, this will be loaded into '/assets'
FontBox *rice.Box // HTML and other small files from the 'source/tmpl' directory, this will be loaded into '/assets'
)
```
## func [Assets](https://github.com/hunterlong/statup/tree/master/source/source.go?s=1498:1511#L39)
``` go
func Assets()
```
Assets will load the Rice boxes containing the CSS, SCSS, JS, and HTML files.
## func [CompileSASS](https://github.com/hunterlong/statup/tree/master/source/source.go?s=2026:2063#L59)
``` go
func CompileSASS(folder string) error
```
CompileSASS will attempt to compile the SASS files into CSS
## func [CopyAllToPublic](https://github.com/hunterlong/statup/tree/master/source/source.go?s=6048:6104#L188)
``` go
func CopyAllToPublic(box *rice.Box, folder string) error
```
CopyAllToPublic will copy all the files in a rice box into a local folder
## func [CopyToPublic](https://github.com/hunterlong/statup/tree/master/source/source.go?s=6645:6704#L210)
``` go
func CopyToPublic(box *rice.Box, folder, file string) error
```
CopyToPublic will create a file from a rice Box to the '/assets' directory
## func [CreateAllAssets](https://github.com/hunterlong/statup/tree/master/source/source.go?s=4749:4790#L154)
``` go
func CreateAllAssets(folder string) error
```
CreateAllAssets will dump HTML, CSS, SCSS, and JS assets into the '/assets' directory
## func [DeleteAllAssets](https://github.com/hunterlong/statup/tree/master/source/source.go?s=5707:5748#L177)
``` go
func DeleteAllAssets(folder string) error
```
DeleteAllAssets will delete the '/assets' folder
## func [HelpMarkdown](https://github.com/hunterlong/statup/tree/master/source/source.go?s=1753:1779#L48)
``` go
func HelpMarkdown() string
```
HelpMarkdown will return the Markdown of help.md into HTML
## func [MakePublicFolder](https://github.com/hunterlong/statup/tree/master/source/source.go?s=7212:7254#L227)
``` go
func MakePublicFolder(folder string) error
```
MakePublicFolder will create a new folder
## func [OpenAsset](https://github.com/hunterlong/statup/tree/master/source/source.go?s=4439:4481#L144)
``` go
func OpenAsset(folder, file string) string
```
OpenAsset returns a file's contents as a string
#### Example
Code:
``` go
OpenAsset("js", "main.js")
```
## func [SaveAsset](https://github.com/hunterlong/statup/tree/master/source/source.go?s=4064:4118#L133)
``` go
func SaveAsset(data []byte, folder, file string) error
```
SaveAsset will save an asset to the '/assets/' folder.
#### Example
Code:
``` go
data := []byte("alert('helloooo')")
SaveAsset(data, "js", "test.js")
```
## func [UsingAssets](https://github.com/hunterlong/statup/tree/master/source/source.go?s=3519:3555#L113)
``` go
func UsingAssets(folder string) bool
```
UsingAssets returns true if the '/assets' folder is found in the directory
# types
`import "github.com/hunterlong/statup/types"`
* [Overview](#pkg-overview)
* [Index](#pkg-index)
## Overview
Package types contains all of the structs for objects in Statup including services, hits, failures, Core, and others.
More info on: https://github.com/hunterlong/statup
## Index
* [Constants](#pkg-constants)
* [Variables](#pkg-variables)
* [type AllNotifiers](#AllNotifiers)
* [type Asseter](#Asseter)
* [type Checkin](#Checkin)
* [func (s *Checkin) Close()](#Checkin.Close)
* [func (s *Checkin) IsRunning() bool](#Checkin.IsRunning)
* [func (s *Checkin) Start()](#Checkin.Start)
* [type CheckinHit](#CheckinHit)
* [type Core](#Core)
* [type Databaser](#Databaser)
* [type DbConfig](#DbConfig)
* [type Failure](#Failure)
* [type FailureInterface](#FailureInterface)
* [type Hit](#Hit)
* [type Info](#Info)
* [type Message](#Message)
* [type NullBool](#NullBool)
* [func NewNullBool(s bool) NullBool](#NewNullBool)
* [func (nb *NullBool) MarshalJSON() ([]byte, error)](#NullBool.MarshalJSON)
* [func (nf *NullBool) UnmarshalJSON(b []byte) error](#NullBool.UnmarshalJSON)
* [type NullFloat64](#NullFloat64)
* [func NewNullFloat64(s float64) NullFloat64](#NewNullFloat64)
* [func (ni *NullFloat64) MarshalJSON() ([]byte, error)](#NullFloat64.MarshalJSON)
* [func (nf *NullFloat64) UnmarshalJSON(b []byte) error](#NullFloat64.UnmarshalJSON)
* [type NullInt64](#NullInt64)
* [func NewNullInt64(s int64) NullInt64](#NewNullInt64)
* [func (ni *NullInt64) MarshalJSON() ([]byte, error)](#NullInt64.MarshalJSON)
* [func (nf *NullInt64) UnmarshalJSON(b []byte) error](#NullInt64.UnmarshalJSON)
* [type NullString](#NullString)
* [func NewNullString(s string) NullString](#NewNullString)
* [func (ns *NullString) MarshalJSON() ([]byte, error)](#NullString.MarshalJSON)
* [func (nf *NullString) UnmarshalJSON(b []byte) error](#NullString.UnmarshalJSON)
* [type Plugin](#Plugin)
* [type PluginActions](#PluginActions)
* [type PluginInfo](#PluginInfo)
* [type PluginJSON](#PluginJSON)
* [type PluginObject](#PluginObject)
* [type PluginRepos](#PluginRepos)
* [type PluginRoute](#PluginRoute)
* [type PluginRouting](#PluginRouting)
* [type Pluginer](#Pluginer)
* [type Router](#Router)
* [type Service](#Service)
* [func (s *Service) Close()](#Service.Close)
* [func (s *Service) IsRunning() bool](#Service.IsRunning)
* [func (s *Service) Start()](#Service.Start)
* [type ServiceInterface](#ServiceInterface)
* [type User](#User)
* [type UserInterface](#UserInterface)
#### Package files
[checkin.go](https://github.com/hunterlong/statup/tree/master/types/checkin.go) [core.go](https://github.com/hunterlong/statup/tree/master/types/core.go) [doc.go](https://github.com/hunterlong/statup/tree/master/types/doc.go) [failure.go](https://github.com/hunterlong/statup/tree/master/types/failure.go) [message.go](https://github.com/hunterlong/statup/tree/master/types/message.go) [null.go](https://github.com/hunterlong/statup/tree/master/types/null.go) [plugin.go](https://github.com/hunterlong/statup/tree/master/types/plugin.go) [service.go](https://github.com/hunterlong/statup/tree/master/types/service.go) [time.go](https://github.com/hunterlong/statup/tree/master/types/time.go) [types.go](https://github.com/hunterlong/statup/tree/master/types/types.go) [user.go](https://github.com/hunterlong/statup/tree/master/types/user.go)
## Constants
``` go
const (
TIME_NANO = "2006-01-02T15:04:05Z"
TIME = "2006-01-02 15:04:05"
TIME_DAY = "2006-01-02"
)
```
## Variables
``` go
var (
NOW = func() time.Time { return time.Now() }()
)
```
## type [AllNotifiers](https://github.com/hunterlong/statup/tree/master/types/core.go?s=757:786#L23)
``` go
type AllNotifiers interface{}
```
AllNotifiers contains all the Notifiers loaded
## type [Asseter](https://github.com/hunterlong/statup/tree/master/types/plugin.go?s=964:1021#L64)
``` go
type Asseter interface {
Asset(string) ([]byte, error)
}
```
## type [Checkin](https://github.com/hunterlong/statup/tree/master/types/checkin.go?s=811:1317#L23)
``` go
type Checkin struct {
Id int64 `gorm:"primary_key;column:id"`
ServiceId int64 `gorm:"index;column:service"`
Name string `gorm:"column:name"`
Interval int64 `gorm:"column:check_interval"`
GracePeriod int64 `gorm:"column:grace_period"`
ApiKey string `gorm:"column:api_key"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
Running chan bool `gorm:"-" json:"-"`
}
```
Checkin struct will allow an application to send a recurring HTTP GET to confirm a service is online
### func (\*Checkin) [Close](https://github.com/hunterlong/statup/tree/master/types/checkin.go?s=1787:1812#L49)
``` go
func (s *Checkin) Close()
```
Close will stop the checkin routine
### func (\*Checkin) [IsRunning](https://github.com/hunterlong/statup/tree/master/types/checkin.go?s=1923:1957#L56)
``` go
func (s *Checkin) IsRunning() bool
```
IsRunning returns true if the checkin go routine is running
### func (\*Checkin) [Start](https://github.com/hunterlong/statup/tree/master/types/checkin.go?s=1688:1713#L44)
``` go
func (s *Checkin) Start()
```
Start will create a channel for the checkin checking go routine
## type [CheckinHit](https://github.com/hunterlong/statup/tree/master/types/checkin.go?s=1373:1619#L36)
``` go
type CheckinHit struct {
Id int64 `gorm:"primary_key;column:id"`
Checkin int64 `gorm:"index;column:checkin"`
From string `gorm:"column:from_location"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
}
```
CheckinHit is a successful response from a Checkin
## type [Core](https://github.com/hunterlong/statup/tree/master/types/core.go?s=1040:2610#L28)
``` go
type Core struct {
Name string `gorm:"not null;column:name" json:"name"`
Description string `gorm:"not null;column:description" json:"description,omitempty"`
Config string `gorm:"column:config" json:"-"`
ApiKey string `gorm:"column:api_key" json:"-"`
ApiSecret string `gorm:"column:api_secret" json:"-"`
Style string `gorm:"not null;column:style" json:"style,omitempty"`
Footer NullString `gorm:"column:footer" json:"footer"`
Domain string `gorm:"not null;column:domain" json:"domain"`
Version string `gorm:"column:version" json:"version"`
MigrationId int64 `gorm:"column:migration_id" json:"migration_id,omitempty"`
UseCdn NullBool `gorm:"column:use_cdn;default:false" json:"using_cdn,omitempty"`
Timezone float32 `gorm:"column:timezone;default:-8.0" json:"timezone,omitempty"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
DbConnection string `gorm:"-" json:"database"`
Started time.Time `gorm:"-" json:"started_on"`
Services []ServiceInterface `gorm:"-" json:"services,omitempty"`
Plugins []*Info `gorm:"-" json:"-"`
Repos []PluginJSON `gorm:"-" json:"-"`
AllPlugins []PluginActions `gorm:"-" json:"-"`
Notifications []AllNotifiers `gorm:"-" json:"-"`
}
```
Core struct contains all the required fields for Statup. All application settings
will be saved into 1 row in the 'core' table. You can use the core.CoreApp
global variable to interact with the attributes to the application, such as services.
## type [Databaser](https://github.com/hunterlong/statup/tree/master/types/plugin.go?s=806:860#L55)
``` go
type Databaser interface {
StatupDatabase(*gorm.DB)
}
```
## type [DbConfig](https://github.com/hunterlong/statup/tree/master/types/types.go?s=1128:1702#L32)
``` go
type DbConfig struct {
DbConn string `yaml:"connection"`
DbHost string `yaml:"host"`
DbUser string `yaml:"user"`
DbPass string `yaml:"password"`
DbData string `yaml:"database"`
DbPort int64 `yaml:"port"`
ApiKey string `yaml:"api_key"`
ApiSecret string `yaml:"api_secret"`
Project string `yaml:"-"`
Description string `yaml:"-"`
Domain string `yaml:"-"`
Username string `yaml:"-"`
Password string `yaml:"-"`
Email string `yaml:"-"`
Error error `yaml:"-"`
Location string `yaml:"location"`
}
```
DbConfig struct is used for the database connection and creates the 'config.yml' file
## type [Failure](https://github.com/hunterlong/statup/tree/master/types/failure.go?s=862:1405#L24)
``` go
type Failure struct {
Id int64 `gorm:"primary_key;column:id" json:"id"`
Issue string `gorm:"column:issue" json:"issue"`
Method string `gorm:"column:method" json:"method,omitempty"`
MethodId int64 `gorm:"column:method_id" json:"method_id,omitempty"`
Service int64 `gorm:"index;column:service" json:"-"`
PingTime float64 `gorm:"column:ping_time"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
FailureInterface `gorm:"-" json:"-"`
}
```
Failure is a failed attempt to check a service. Any a service does not meet the expected requirements,
a new Failure will be inserted into database.
## type [FailureInterface](https://github.com/hunterlong/statup/tree/master/types/failure.go?s=1407:1593#L35)
``` go
type FailureInterface interface {
Ago() string // Ago returns a human readable timestamp
ParseError() string // ParseError returns a human readable error for a service failure
}
```
## type [Hit](https://github.com/hunterlong/statup/tree/master/types/types.go?s=781:1037#L23)
``` go
type Hit struct {
Id int64 `gorm:"primary_key;column:id"`
Service int64 `gorm:"column:service"`
Latency float64 `gorm:"column:latency"`
PingTime float64 `gorm:"column:ping_time"`
CreatedAt time.Time `gorm:"column:created_at"`
}
```
Hit struct is a 'successful' ping or web response entry for a service.
## type [Info](https://github.com/hunterlong/statup/tree/master/types/plugin.go?s=499:579#L34)
``` go
type Info struct {
Name string
Description string
Form string
}
```
## type [Message](https://github.com/hunterlong/statup/tree/master/types/message.go?s=793:1647#L23)
``` go
type Message struct {
Id int64 `gorm:"primary_key;column:id" json:"id"`
Title string `gorm:"column:title" json:"title"`
Description string `gorm:"column:description" json:"description"`
StartOn time.Time `gorm:"column:start_on" json:"start_on"`
EndOn time.Time `gorm:"column:end_on" json:"end_on"`
ServiceId int64 `gorm:"index;column:service" json:"service"`
NotifyUsers NullBool `gorm:"column:notify_users" json:"notify_users"`
NotifyMethod string `gorm:"column:notify_method" json:"notify_method"`
NotifyBefore time.Duration `gorm:"column:notify_before" json:"notify_before"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at" json:"updated_at"`
}
```
Message is for creating Announcements, Alerts and other messages for the end users
## type [NullBool](https://github.com/hunterlong/statup/tree/master/types/null.go?s=1456:1494#L49)
``` go
type NullBool struct {
sql.NullBool
}
```
NullBool is an alias for sql.NullBool data type
### func [NewNullBool](https://github.com/hunterlong/statup/tree/master/types/null.go?s=935:968#L29)
``` go
func NewNullBool(s bool) NullBool
```
NewNullBool returns a sql.NullBool for JSON parsing
### func (\*NullBool) [MarshalJSON](https://github.com/hunterlong/statup/tree/master/types/null.go?s=2060:2109#L80)
``` go
func (nb *NullBool) MarshalJSON() ([]byte, error)
```
MarshalJSON for NullBool
### func (\*NullBool) [UnmarshalJSON](https://github.com/hunterlong/statup/tree/master/types/null.go?s=2712:2761#L110)
``` go
func (nf *NullBool) UnmarshalJSON(b []byte) error
```
Unmarshaler for NullBool
## type [NullFloat64](https://github.com/hunterlong/statup/tree/master/types/null.go?s=1652:1696#L59)
``` go
type NullFloat64 struct {
sql.NullFloat64
}
```
NullFloat64 is an alias for sql.NullFloat64 data type
### func [NewNullFloat64](https://github.com/hunterlong/statup/tree/master/types/null.go?s=1216:1258#L39)
``` go
func NewNullFloat64(s float64) NullFloat64
```
NewNullFloat64 returns a sql.NullFloat64 for JSON parsing
### func (\*NullFloat64) [MarshalJSON](https://github.com/hunterlong/statup/tree/master/types/null.go?s=1893:1945#L72)
``` go
func (ni *NullFloat64) MarshalJSON() ([]byte, error)
```
MarshalJSON for NullFloat64
### func (\*NullFloat64) [UnmarshalJSON](https://github.com/hunterlong/statup/tree/master/types/null.go?s=2550:2602#L103)
``` go
func (nf *NullFloat64) UnmarshalJSON(b []byte) error
```
Unmarshaler for NullFloat64
## type [NullInt64](https://github.com/hunterlong/statup/tree/master/types/null.go?s=1363:1403#L44)
``` go
type NullInt64 struct {
sql.NullInt64
}
```
NullInt64 is an alias for sql.NullInt64 data type
### func [NewNullInt64](https://github.com/hunterlong/statup/tree/master/types/null.go?s=1071:1107#L34)
``` go
func NewNullInt64(s int64) NullInt64
```
NewNullInt64 returns a sql.NullInt64 for JSON parsing
### func (\*NullInt64) [MarshalJSON](https://github.com/hunterlong/statup/tree/master/types/null.go?s=1727:1777#L64)
``` go
func (ni *NullInt64) MarshalJSON() ([]byte, error)
```
MarshalJSON for NullInt64
### func (\*NullInt64) [UnmarshalJSON](https://github.com/hunterlong/statup/tree/master/types/null.go?s=2389:2439#L96)
``` go
func (nf *NullInt64) UnmarshalJSON(b []byte) error
```
Unmarshaler for NullInt64
## type [NullString](https://github.com/hunterlong/statup/tree/master/types/null.go?s=1551:1593#L54)
``` go
type NullString struct {
sql.NullString
}
```
NullString is an alias for sql.NullString data type
### func [NewNullString](https://github.com/hunterlong/statup/tree/master/types/null.go?s=791:830#L24)
``` go
func NewNullString(s string) NullString
```
NewNullString returns a sql.NullString for JSON parsing
### func (\*NullString) [MarshalJSON](https://github.com/hunterlong/statup/tree/master/types/null.go?s=2223:2274#L88)
``` go
func (ns *NullString) MarshalJSON() ([]byte, error)
```
MarshalJSON for NullString
### func (\*NullString) [UnmarshalJSON](https://github.com/hunterlong/statup/tree/master/types/null.go?s=2870:2921#L117)
``` go
func (nf *NullString) UnmarshalJSON(b []byte) error
```
Unmarshaler for NullString
## type [Plugin](https://github.com/hunterlong/statup/tree/master/types/plugin.go?s=65:127#L8)
``` go
type Plugin struct {
Name string
Description string
}
```
## type [PluginActions](https://github.com/hunterlong/statup/tree/master/types/plugin.go?s=169:234#L17)
``` go
type PluginActions interface {
GetInfo() *Info
OnLoad() error
}
```
## type [PluginInfo](https://github.com/hunterlong/statup/tree/master/types/plugin.go?s=581:644#L40)
``` go
type PluginInfo struct {
Info *Info
Routes []*PluginRoute
}
```
## type [PluginJSON](https://github.com/hunterlong/statup/tree/master/types/plugin.go?s=287:497#L26)
``` go
type PluginJSON struct {
Name string `json:"name"`
Description string `json:"description"`
Repo string `json:"repo"`
Author string `json:"author"`
Namespace string `json:"namespace"`
}
```
## type [PluginObject](https://github.com/hunterlong/statup/tree/master/types/plugin.go?s=129:167#L13)
``` go
type PluginObject struct {
Pluginer
}
```
## type [PluginRepos](https://github.com/hunterlong/statup/tree/master/types/plugin.go?s=236:285#L22)
``` go
type PluginRepos struct {
Plugins []PluginJSON
}
```
## type [PluginRoute](https://github.com/hunterlong/statup/tree/master/types/plugin.go?s=1023:1105#L68)
``` go
type PluginRoute struct {
Url string
Method string
Func http.HandlerFunc
}
```
## type [PluginRouting](https://github.com/hunterlong/statup/tree/master/types/plugin.go?s=646:757#L45)
``` go
type PluginRouting struct {
URL string
Method string
Handler func(http.ResponseWriter, *http.Request)
}
```
## type [Pluginer](https://github.com/hunterlong/statup/tree/master/types/plugin.go?s=759:804#L51)
``` go
type Pluginer interface {
Select() *Plugin
}
```
## type [Router](https://github.com/hunterlong/statup/tree/master/types/plugin.go?s=862:962#L59)
``` go
type Router interface {
Routes() []*PluginRoute
AddRoute(string, string, http.HandlerFunc) error
}
```
## type [Service](https://github.com/hunterlong/statup/tree/master/types/service.go?s=750:2724#L23)
``` go
type Service struct {
Id int64 `gorm:"primary_key;column:id" json:"id"`
Name string `gorm:"column:name" json:"name"`
Domain string `gorm:"column:domain" json:"domain"`
Expected NullString `gorm:"column:expected" json:"expected"`
ExpectedStatus int `gorm:"default:200;column:expected_status" json:"expected_status"`
Interval int `gorm:"default:30;column:check_interval" json:"check_interval"`
Type string `gorm:"column:check_type" json:"type"`
Method string `gorm:"column:method" json:"method"`
PostData NullString `gorm:"column:post_data" json:"post_data"`
Port int `gorm:"not null;column:port" json:"port"`
Timeout int `gorm:"default:30;column:timeout" json:"timeout"`
Order int `gorm:"default:0;column:order_id" json:"order_id"`
AllowNotifications NullBool `gorm:"default:false;column:allow_notifications" json:"allow_notifications"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
Online bool `gorm:"-" json:"online"`
Latency float64 `gorm:"-" json:"latency"`
PingTime float64 `gorm:"-" json:"ping_time"`
Online24Hours float32 `gorm:"-" json:"online_24_hours"`
AvgResponse string `gorm:"-" json:"avg_response"`
Running chan bool `gorm:"-" json:"-"`
Checkpoint time.Time `gorm:"-" json:"-"`
SleepDuration time.Duration `gorm:"-" json:"-"`
LastResponse string `gorm:"-" json:"-"`
LastStatusCode int `gorm:"-" json:"status_code"`
LastOnline time.Time `gorm:"-" json:"last_online"`
Failures []interface{} `gorm:"-" json:"failures,omitempty"`
}
```
Service is the main struct for Services
### func (\*Service) [Close](https://github.com/hunterlong/statup/tree/master/types/service.go?s=3084:3109#L68)
``` go
func (s *Service) Close()
```
Close will stop the go routine that is checking if service is online or not
### func (\*Service) [IsRunning](https://github.com/hunterlong/statup/tree/master/types/service.go?s=3220:3254#L75)
``` go
func (s *Service) IsRunning() bool
```
IsRunning returns true if the service go routine is running
### func (\*Service) [Start](https://github.com/hunterlong/statup/tree/master/types/service.go?s=2945:2970#L63)
``` go
func (s *Service) Start()
```
Start will create a channel for the service checking go routine
## type [ServiceInterface](https://github.com/hunterlong/statup/tree/master/types/service.go?s=2726:2876#L53)
``` go
type ServiceInterface interface {
Select() *Service
CheckQueue(bool)
Check(bool)
Create(bool) (int64, error)
Update(bool) error
Delete() error
}
```
## type [User](https://github.com/hunterlong/statup/tree/master/types/user.go?s=744:1430#L23)
``` go
type User struct {
Id int64 `gorm:"primary_key;column:id" json:"id"`
Username string `gorm:"type:varchar(100);unique;column:username;" json:"username"`
Password string `gorm:"column:password" json:"-"`
Email string `gorm:"type:varchar(100);unique;column:email" json:"-"`
ApiKey string `gorm:"column:api_key" json:"api_key"`
ApiSecret string `gorm:"column:api_secret" json:"-"`
Admin NullBool `gorm:"column:administrator" json:"admin"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
UserInterface `gorm:"-" json:"-"`
}
```
User is the main struct for Users
## type [UserInterface](https://github.com/hunterlong/statup/tree/master/types/user.go?s=1483:1572#L37)
``` go
type UserInterface interface {
Create() (int64, error)
Update() error
Delete() error
}
```
UserInterface interfaces the database functions
# utils
`import "github.com/hunterlong/statup/utils"`
* [Overview](#pkg-overview)
* [Index](#pkg-index)
* [Examples](#pkg-examples)
## Overview
Package utils contains common methods used in most packages in Statup.
This package contains multiple function like:
Logging, encryption, type conversions, setting utils.Directory as the current directory,
running local CMD commands, and creating/deleting files/folder.
You can overwrite the utils.Directory global variable by including
STATUP_DIR environment variable to be an absolute path.
More info on: https://github.com/hunterlong/statup
## Index
* [Constants](#pkg-constants)
* [Variables](#pkg-variables)
* [func Command(cmd string) (string, string, error)](#Command)
* [func DeleteDirectory(directory string) error](#DeleteDirectory)
* [func DeleteFile(file string) error](#DeleteFile)
* [func DurationReadable(d time.Duration) string](#DurationReadable)
* [func FileExists(name string) bool](#FileExists)
* [func FormatDuration(d time.Duration) string](#FormatDuration)
* [func HashPassword(password string) string](#HashPassword)
* [func Http(r *http.Request) string](#Http)
* [func InitLogs() error](#InitLogs)
* [func Log(level int, err interface{}) error](#Log)
* [func NewSHA1Hash(n ...int) string](#NewSHA1Hash)
* [func RandomString(n int) string](#RandomString)
* [func SaveFile(filename string, data []byte) error](#SaveFile)
* [func StringInt(s string) int64](#StringInt)
* [func Timezoner(t time.Time, zone float32) time.Time](#Timezoner)
* [func ToString(s interface{}) string](#ToString)
* [func UnderScoreString(str string) string](#UnderScoreString)
* [type LogRow](#LogRow)
* [func GetLastLine() *LogRow](#GetLastLine)
* [func (o *LogRow) FormatForHtml() string](#LogRow.FormatForHtml)
* [type Timestamp](#Timestamp)
* [func (t Timestamp) Ago() string](#Timestamp.Ago)
* [type Timestamper](#Timestamper)
#### Examples
* [DurationReadable](#example_DurationReadable)
* [StringInt](#example_StringInt)
* [ToString](#example_ToString)
#### Package files
[doc.go](https://github.com/hunterlong/statup/tree/master/utils/doc.go) [encryption.go](https://github.com/hunterlong/statup/tree/master/utils/encryption.go) [log.go](https://github.com/hunterlong/statup/tree/master/utils/log.go) [time.go](https://github.com/hunterlong/statup/tree/master/utils/time.go) [utils.go](https://github.com/hunterlong/statup/tree/master/utils/utils.go)
## Constants
``` go
const (
FlatpickrTime = "2006-01-02 15:04"
FlatpickrDay = "2006-01-02"
FlatpickrReadable = "Mon, 02 Jan 2006"
)
```
## Variables
``` go
var (
LastLines []*LogRow
LockLines sync.Mutex
)
```
``` go
var (
// Directory returns the current path or the STATUP_DIR environment variable
Directory string
)
```
## func [Command](https://github.com/hunterlong/statup/tree/master/utils/utils.go?s=3868:3916#L155)
``` go
func Command(cmd string) (string, string, error)
```
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 [DeleteDirectory](https://github.com/hunterlong/statup/tree/master/utils/utils.go?s=3618:3662#L149)
``` go
func DeleteDirectory(directory string) error
```
DeleteDirectory will attempt to delete a directory and all contents inside
DeleteDirectory("assets")
## func [DeleteFile](https://github.com/hunterlong/statup/tree/master/utils/utils.go?s=3369:3403#L138)
``` go
func DeleteFile(file string) error
```
DeleteFile will attempt to delete a file
DeleteFile("newfile.json")
## func [DurationReadable](https://github.com/hunterlong/statup/tree/master/utils/utils.go?s=5212:5257#L213)
``` go
func DurationReadable(d time.Duration) string
```
DurationReadable will return a time.Duration into a human readable string
t := time.Duration(5 * time.Minute)
DurationReadable(t)
// 5 minutes
#### Example
Code:
``` go
dur, _ := time.ParseDuration("25m")
readable := DurationReadable(dur)
fmt.Print(readable)
```
Output:
25 minutes
## func [FileExists](https://github.com/hunterlong/statup/tree/master/utils/utils.go?s=3151:3184#L127)
``` go
func FileExists(name string) bool
```
FileExists returns true if a file exists
exists := FileExists("assets/css/base.css")
## func [FormatDuration](https://github.com/hunterlong/statup/tree/master/utils/time.go?s=896:939#L30)
``` go
func FormatDuration(d time.Duration) string
```
FormatDuration converts a time.Duration into a string
## func [HashPassword](https://github.com/hunterlong/statup/tree/master/utils/encryption.go?s=833:874#L27)
``` go
func HashPassword(password string) string
```
HashPassword returns the bcrypt hash of a password string
## func [Http](https://github.com/hunterlong/statup/tree/master/utils/log.go?s=3070:3103#L126)
``` go
func Http(r *http.Request) string
```
Http returns a log for a HTTP request
## func [InitLogs](https://github.com/hunterlong/statup/tree/master/utils/log.go?s=1415:1436#L58)
``` go
func InitLogs() error
```
InitLogs will create the '/logs' directory and creates a file '/logs/statup.log' for application logging
## func [Log](https://github.com/hunterlong/statup/tree/master/utils/log.go?s=2191:2233#L93)
``` go
func Log(level int, err interface{}) error
```
Log creates a new entry in the Logger. Log has 1-5 levels depending on how critical the log/error is
## func [NewSHA1Hash](https://github.com/hunterlong/statup/tree/master/utils/encryption.go?s=1034:1067#L33)
``` go
func NewSHA1Hash(n ...int) string
```
NewSHA1Hash returns a random SHA1 hash based on a specific length
## func [RandomString](https://github.com/hunterlong/statup/tree/master/utils/encryption.go?s=1447:1478#L48)
``` go
func RandomString(n int) string
```
RandomString generates a random string of n length
## func [SaveFile](https://github.com/hunterlong/statup/tree/master/utils/utils.go?s=5629:5678#L226)
``` go
func SaveFile(filename string, data []byte) error
```
SaveFile will create a new file with data inside it
SaveFile("newfile.json", []byte('{"data": "success"}')
## func [StringInt](https://github.com/hunterlong/statup/tree/master/utils/utils.go?s=1191:1221#L47)
``` go
func StringInt(s string) int64
```
StringInt converts a string to an int64
#### Example
Code:
``` go
amount := "42"
fmt.Print(StringInt(amount))
```
Output:
42
## func [Timezoner](https://github.com/hunterlong/statup/tree/master/utils/utils.go?s=1683:1734#L72)
``` go
func Timezoner(t time.Time, zone float32) time.Time
```
Timezoner returns the time.Time with the user set timezone
## func [ToString](https://github.com/hunterlong/statup/tree/master/utils/utils.go?s=1312:1347#L53)
``` go
func ToString(s interface{}) string
```
ToString converts a int to a string
#### Example
Code:
``` go
amount := 42
fmt.Print(ToString(amount))
```
Output:
42
## func [UnderScoreString](https://github.com/hunterlong/statup/tree/master/utils/utils.go?s=2418:2458#L102)
``` go
func UnderScoreString(str string) string
```
UnderScoreString will return a string that replaces spaces and other characters to underscores
UnderScoreString("Example String")
// example_string
## type [LogRow](https://github.com/hunterlong/statup/tree/master/utils/log.go?s=3705:3761#L153)
``` go
type LogRow struct {
Date time.Time
Line interface{}
}
```
### func [GetLastLine](https://github.com/hunterlong/statup/tree/master/utils/log.go?s=3552:3578#L144)
``` go
func GetLastLine() *LogRow
```
GetLastLine returns 1 line for a recent log entry
### func (\*LogRow) [FormatForHtml](https://github.com/hunterlong/statup/tree/master/utils/log.go?s=4071:4110#L177)
``` go
func (o *LogRow) FormatForHtml() string
```
## type [Timestamp](https://github.com/hunterlong/statup/tree/master/utils/utils.go?s=1991:2015#L88)
``` go
type Timestamp time.Time
```
### func (Timestamp) [Ago](https://github.com/hunterlong/statup/tree/master/utils/utils.go?s=2149:2180#L94)
``` go
func (t Timestamp) Ago() string
```
Ago returns a human readable timestamp based on the Timestamp (time.Time) interface
## type [Timestamper](https://github.com/hunterlong/statup/tree/master/utils/utils.go?s=2016:2060#L89)
``` go
type Timestamper interface {
Ago() string
}
```