db

package
v0.0.0-...-c083feb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StatusUnknown indicates that the status of the site is not yet known.
	StatusUnknown = 0
	// StatusUp indicates that the website is responding to requests.
	StatusUp = 1
	// StatusDown indicates that the website is not responding to requests.
	StatusDown = 2
)

Variables

This section is empty.

Functions

func FilteredError

func FilteredError(db *gorm.DB) error

FilteredError filters the Error value by ignoring RecordNotFound errors.

Types

type Config

type Config struct {
	Host     string
	Port     int
	Name     string
	User     string
	Password string
}

Config stores the database connection information.

type Conn

type Conn struct {
	*gorm.DB
	// contains filtered or unexported fields
}

Conn represents a connection to the database.

func New

func New(cfg *Config) (*Conn, error)

New creates a new database connection and initializes it.

func (*Conn) Migrate

func (c *Conn) Migrate() error

Migrate performs all database migrations.

func (*Conn) Transaction

func (c *Conn) Transaction(fn func(*Conn) error) error

Transaction wraps the function in a database transaction.

type Outage

type Outage struct {
	ID int64 `json:"id"`

	// Start and ending time of the outage (may be 0 if ongoing)
	StartTime time.Time  `gorm:"not null" json:"start-time"`
	EndTime   *time.Time `json:"end-time"`

	// Whether the two notifications have been sent yet or not
	StartNotificationSent bool `gorm:"not null" json:"-"`
	EndNotificationSent   bool `gorm:"not null" json:"-"`

	// Information about the error
	Description string `gorm:"not null" json:"description"`

	// Site that is experiencing the outage
	Site   *Site `gorm:"ForeignKey:SiteID" json:"-"`
	SiteID int64 `sql:"type:int REFERENCES sites(id) ON DELETE CASCADE" json:"site-id"`
}

Outage represents a period of time during which a site was inaccessible.

func (*Outage) GetID

func (o *Outage) GetID() string

GetID returns the unique identifier for the outage.

func (*Outage) GetName

func (o *Outage) GetName() string

GetName retrieves a descriptive name for groups of outages

func (*Outage) SetID

func (o *Outage) SetID(id string) error

SetID sets the unique identifier for the outage.

type Site

type Site struct {
	ID int64 `json:"id"`

	// URL to poll and a descriptive name for the site
	URL  string `gorm:"not null" json:"url"`
	Name string `gorm:"not null" json:"name"`

	// Poll interval and the time of last and next poll
	PollInterval int64      `gorm:"not null" json:"poll-interval"`
	LastPoll     *time.Time `json:"last-poll"`
	NextPoll     *time.Time `json:"next-poll"`

	// Current status of the site and the time since it last changed
	Status     int        `gorm:"not null" json:"status"`
	StatusTime *time.Time `json:"status-time"`

	// User that created the site
	User   *User `gorm:"ForeignKey:UserID" json:"-"`
	UserID int64 `sql:"type:int REFERENCES users(id) ON DELETE CASCADE" json:"user-id"`
}

Site represents a website being monitored.

func (*Site) GetID

func (s *Site) GetID() string

GetID returns the unique identifier for the site.

func (*Site) GetName

func (s *Site) GetName() string

GetName retrieves a descriptive name for groups of sites.

func (*Site) SetID

func (s *Site) SetID(id string) error

SetID sets the unique identifier for the site.

type User

type User struct {
	ID       int64  `json:"id"`
	Username string `gorm:"not null" json:"username"`
	Password string `gorm:"not null" json:"-"`
	IsAdmin  bool   `gorm:"not null" json:"is-admin"`
}

User represents a user that can login and make changes to the site configuration. Administrators can also manage users.

func (*User) Authenticate

func (u *User) Authenticate(password string) error

Authenticate hashes the password and compares it to the value stored in the database. An error is returned if the values do not match.

func (*User) GetID

func (u *User) GetID() string

GetID returns the unique identifier for the user.

func (*User) GetName

func (u *User) GetName() string

GetName retrieves a descriptive name for groups of users.

func (*User) SetID

func (u *User) SetID(id string) error

SetID sets the unique identifier for the user.

func (*User) SetPassword

func (u *User) SetPassword(password string) error

SetPassword salts and hashes the user's password. It does not store the new value in the database.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL