config

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultNUTPort    = 3493
	DefaultWoLPort    = 9
	DefaultConfigName = "config"
	DefaultConfigExt  = "yaml"
)

Variables

View Source
var (
	DefaultConfigFile = fmt.Sprintf("%s.%s", DefaultConfigName, DefaultConfigExt)
)

Functions

func CheckCreateConfigFile

func CheckCreateConfigFile(fs hackpadfs.FS, configFile string) error

func Duration

func Duration(fl validator.FieldLevel) bool

func IsRegoFile

func IsRegoFile(fl validator.FieldLevel) bool

Types

type Config

type Config struct {
	NutServers []NutServer `yaml:"nut_servers"`
}

func CreateDefaultConfig

func CreateDefaultConfig() Config

func (*Config) FindTarget

func (c *Config) FindTarget(mac string) (*TargetServer, *NutServer, error)

func (*Config) Validate

func (c *Config) Validate() error

Validate Validation of the config ensure all 'NutServers' are valid and have a corresponding 'NutServers' that is valid 'NutServers' that are not used are not used by a 'NutServers' are not validated

type NutCredentials

type NutCredentials struct {
	Username string `yaml:"username" validate:"required"`
	Password string `yaml:"password" validate:"required"`
}

func (*NutCredentials) Validate

func (cred *NutCredentials) Validate() error

type NutServer

type NutServer struct {
	Name        string         `yaml:"name" validate:"required"`
	Host        string         `yaml:"host" validate:"required,ip|hostname"`
	Port        int            `yaml:"port" validate:"omitempty,gte=1,lte=65535"`
	Credentials NutCredentials `yaml:"credentials" validate:"required"`
	Targets     []TargetServer `yaml:"targets" validate:"omitempty"`
}

func (*NutServer) GetPort

func (ns *NutServer) GetPort() int

func (*NutServer) Validate

func (ns *NutServer) Validate() error

type TargetServer

type TargetServer struct {
	Name      string   `yaml:"name" validate:"required"`
	Mac       string   `yaml:"mac" validate:"required,mac"`
	Broadcast string   `yaml:"broadcast" validate:"required,ip"`
	Port      int      `yaml:"port" validate:"omitempty,gte=1,lte=65535" default:"9"`
	Interval  string   `yaml:"interval" validate:"required,duration" default:"15m"`
	Rules     []string `yaml:"rules" validate:"omitempty,dive,regofile"`
}

func (*TargetServer) Validate

func (ts *TargetServer) Validate() error

Jump to

Keyboard shortcuts

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