db

package
v0.0.0-...-2bc2836 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusUnknown = "unknown"
	StatusOnline  = "online"
	StatusError   = "error"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	*gorm.DB
}

Conn maintains a connection to the database.

func New

func New(dataDir string) (*Conn, error)

New attempts to connect to or create the database.

func (*Conn) Close

func (c *Conn) Close()

Close closes the database connection.

func (*Conn) Transaction

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

Transaction starts a new transaction.

type Event

type Event struct {
	ID        int64      `gorm:"primaryKey" json:"id"`
	Time      *time.Time `gorm:"not null" json:"time"`
	SiteID    int64      `gorm:"not null" json:"site_id"`
	Site      Site       `gorm:"constraint:OnDelete:CASCADE;" json:"-"`
	OldStatus string     `gorm:"not null" json:"old_status"`
	NewStatus string     `gorm:"not null" json:"new_status"`
	Details   string     `gorm:"not null" json:"details"`
}

Event represents an error that occurs

type Site

type Site struct {
	SiteWritable
	ID        int64      `gorm:"primaryKey" json:"id"`
	LastCheck *time.Time `json:"last_check"`
	Status    string     `gorm:"index;not null" json:"status"`
	Details   string     `gorm:"not null" json:"details"`
}

Site is a URL that needs to be monitored.

func (*Site) Interval

func (s *Site) Interval() time.Duration

Interval returns an interval based on the current status.

type SiteWritable

type SiteWritable struct {
	Name             string `gorm:"not null" json:"name"`
	URL              string `gorm:"not null" json:"url"`
	Public           bool   `gorm:"not null" json:"public"`
	Enabled          bool   `gorm:"not null" json:"enabled"`
	Timeout          int    `gorm:"not null" json:"timeout"`
	IgnoreHTTPErrors bool   `gorm:"not null" json:"ignore_http_errors"`
	OnlineInterval   int    `gorm:"not null" json:"online_interval"`
	OfflineInterval  int    `gorm:"not null" json:"offline_interval"`
}

SiteWritable represents the writable fields of a site.

type User

type User struct {
	ID       int64  `gorm:"primaryKey" json:"id"`
	Email    string `gorm:"not null;uniqueIndex" json:"email"`
	Password string `gorm:"not null" json:"-"`
}

User is a user that can login.

func (*User) Authenticate

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

Authenticate compares the provided password to the one stored in the database. An error is returned if the values do not match.

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