common

package
v0.0.0-...-f9c212a Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package common provides constants, variables and functions used throughout the application.

Index

Constants

View Source
const (
	Debug                    = true
	Version                  = "0.3.1"
	AppName                  = "uptimed"
	TimestampFormat          = "2006-01-02 15:04:05"
	TimestampFormatMinute    = "2006-01-02 15:04"
	TimestampFormatSubSecond = "2006-01-02 15:04:05.0000 MST"
	TimestampFormatDate      = "2006-01-02"
	HeartBeat                = time.Millisecond * 500
	RCTimeout                = time.Millisecond * 10
	Interval                 = time.Second * 120
)

Debug indicates whether to emit additional log messages and perform additional sanity checks. Version is the version number to display. AppName is the name of the application. TimestampFormat is the format string used to render datetime values. HeartBeat is the interval for worker goroutines to wake up and check their status.

View Source
const EncJSON = "application/json"

EncJSON is the MIME type used for JSON payloads.

View Source
const MinLogLevel = "INFO"

MinLogLevel is the mininum log level all loggers forward.

Variables

View Source
var (
	BaseDir          = filepath.Join(os.Getenv("HOME"), "uptimed.d")
	LogPath          = filepath.Join(BaseDir, "uptimed.log")
	DbPath           = filepath.Join(BaseDir, "uptimed.db")
	BufferPath       = filepath.Join(BaseDir, "offline")
	WebPort    int64 = 1337
)

BaseDir is the folder where all application-specific files (database, log files, etc) are stored. LogPath is the file to the log path. DbPath is the path of the main database. WebPort is the TCP port the server listens on.

View Source
var LogLevels = []logutils.LogLevel{
	"TRACE",
	"DEBUG",
	"INFO",
	"WARN",
	"ERROR",
	"CRITICAL",
	"CANTHAPPEN",
	"SILENT",
}

LogLevels are the names of the log levels supported by the logger.

View Source
var PackageLevels = make(map[logdomain.ID]logutils.LogLevel, len(LogLevels))

PackageLevels defines minimum log levels per package.

View Source
var SuffixPattern = regexp.MustCompile("([.][^.]+)$")

SuffixPattern is a regular expression that matches the suffix of a file name. For "text.txt", it should match ".txt" and capture "txt".

Functions

func GetChecksum

func GetChecksum(data []byte) (string, error)

GetChecksum computes the SHA512 checksum of the given data.

func GetLogger

func GetLogger(dom logdomain.ID) (*log.Logger, error)

GetLogger Tries to create a named logger instance and return it. If the directory to hold the log file does not exist, try to create it.

func GetUUID

func GetUUID() string

GetUUID returns a randomized UUID

func InitApp

func InitApp() error

InitApp performs some basic preparations for the application to run. Currently, this means creating the BASE_DIR folder.

func SetBaseDir

func SetBaseDir(path string) error

SetBaseDir sets the BaseDir and related variables.

func TimeEqual

func TimeEqual(t1, t2 time.Time) bool

TimeEqual returns true if the two timestamps are less than one second apart.

Types

type Host

type Host struct {
	ID   int64
	Name string
}

Host is a system - physical or virtual - that is connected to a network.

func (*Host) String

func (h *Host) String() string

type Record

type Record struct {
	ID        int64
	Hostname  string
	Timestamp time.Time
	Uptime    time.Duration
	Load      [3]float64
}

Record is a data record the client submits to the server.

func (*Record) Recent

func (r *Record) Recent() bool

Recent returns true of the Record was submitted recently (now - interval * 2)

func (*Record) String

func (r *Record) String() string

Jump to

Keyboard shortcuts

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