internal

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2025 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const Version string = "0.9.1"

Version of the program

Variables

This section is empty.

Functions

func CreateHTTPClient

func CreateHTTPClient(CAFile string) (*http.Client, error)

CreateHTTPClient returns a http.Client

func ExtractSizeFromLog added in v0.5.1

func ExtractSizeFromLog(logFile string, re *regexp.Regexp) string

ExtractSizeFromLog uses a regexp to extract the size from log files

func ExtractSizeFromRsyncLog added in v0.3.4

func ExtractSizeFromRsyncLog(logFile string) string

ExtractSizeFromRsyncLog extracts the size from rsync logs

func FindAllSubmatchInFile added in v0.5.1

func FindAllSubmatchInFile(fileName string, re *regexp.Regexp) (matches [][][]byte, err error)

FindAllSubmatchInFile calls re.FindAllSubmatch to find matches in given file

func GetJSON

func GetJSON(url string, obj interface{}, client *http.Client) (*http.Response, error)

GetJSON gets a json response from url

func GetTLSConfig

func GetTLSConfig(CAFile string) (*tls.Config, error)

GetTLSConfig generate tls.Config from CAFile

func InitLogger

func InitLogger(verbose, debug, withSystemd bool)

InitLogger initilizes logging format and level

func PostJSON

func PostJSON(url string, obj interface{}, client *http.Client) (*http.Response, error)

PostJSON posts json object to url

func TranslateRsyncErrorCode added in v0.6.0

func TranslateRsyncErrorCode(cmdErr error) (exitCode int, msg string)

TranslateRsyncErrorCode translates the exit code of rsync to a message

Types

type ClientCmd

type ClientCmd struct {
	Cmd      CmdVerb         `json:"cmd"`
	MirrorID string          `json:"mirror_id"`
	WorkerID string          `json:"worker_id"`
	Args     []string        `json:"args"`
	Options  map[string]bool `json:"options"`
}

A ClientCmd is the command message send from client to the manager

type CmdVerb

type CmdVerb uint8

A CmdVerb is an action to a job or worker

const (
	// CmdStart start a job
	CmdStart CmdVerb = iota
	// CmdStop stop syncing, but keep the job
	CmdStop
	// CmdDisable disable the job (stops goroutine)
	CmdDisable
	// CmdRestart restart a syncing job
	CmdRestart
	// CmdPing ensures the goroutine is alive
	CmdPing

	// CmdReload tells a worker to reload mirror config
	CmdReload
)

func NewCmdVerbFromString added in v0.6.8

func NewCmdVerbFromString(s string) CmdVerb

func (CmdVerb) MarshalJSON added in v0.6.8

func (s CmdVerb) MarshalJSON() ([]byte, error)

Marshal and Unmarshal for CmdVerb

func (CmdVerb) String

func (c CmdVerb) String() string

func (*CmdVerb) UnmarshalJSON added in v0.6.8

func (s *CmdVerb) UnmarshalJSON(b []byte) error

type MirrorSchedule added in v0.3.4

type MirrorSchedule struct {
	MirrorName   string    `json:"name"`
	NextSchedule time.Time `json:"next_schedule"`
}

type MirrorSchedules added in v0.3.4

type MirrorSchedules struct {
	Schedules []MirrorSchedule `json:"schedules"`
}

type MirrorStatus

type MirrorStatus struct {
	Name        string     `json:"name"`
	Worker      string     `json:"worker"`
	IsMaster    bool       `json:"is_master"`
	Status      SyncStatus `json:"status"`
	LastUpdate  time.Time  `json:"last_update"`
	LastStarted time.Time  `json:"last_started"`
	LastEnded   time.Time  `json:"last_ended"`
	Scheduled   time.Time  `json:"next_schedule"`
	Upstream    string     `json:"upstream"`
	Size        string     `json:"size"`
	ErrorMsg    string     `json:"error_msg"`
}

A MirrorStatus represents a msg when a worker has done syncing

type SyncStatus

type SyncStatus uint8
const (
	None SyncStatus = iota
	Failed
	Success
	Syncing
	PreSyncing
	Paused
	Disabled
)

func (SyncStatus) MarshalJSON

func (s SyncStatus) MarshalJSON() ([]byte, error)

func (SyncStatus) String

func (s SyncStatus) String() string

func (*SyncStatus) UnmarshalJSON

func (s *SyncStatus) UnmarshalJSON(v []byte) error

type WebMirrorStatus added in v0.3.2

type WebMirrorStatus struct {
	Name          string     `json:"name"`
	IsMaster      bool       `json:"is_master"`
	Status        SyncStatus `json:"status"`
	LastUpdate    textTime   `json:"last_update"`
	LastUpdateTs  stampTime  `json:"last_update_ts"`
	LastStarted   textTime   `json:"last_started"`
	LastStartedTs stampTime  `json:"last_started_ts"`
	LastEnded     textTime   `json:"last_ended"`
	LastEndedTs   stampTime  `json:"last_ended_ts"`
	Scheduled     textTime   `json:"next_schedule"`
	ScheduledTs   stampTime  `json:"next_schedule_ts"`
	Upstream      string     `json:"upstream"`
	Size          string     `json:"size"` // approximate size
}

WebMirrorStatus is the mirror status to be shown in the web page

func BuildWebMirrorStatus added in v0.3.2

func BuildWebMirrorStatus(m MirrorStatus) WebMirrorStatus

type WorkerCmd

type WorkerCmd struct {
	Cmd      CmdVerb         `json:"cmd"`
	MirrorID string          `json:"mirror_id"`
	Args     []string        `json:"args"`
	Options  map[string]bool `json:"options"`
}

A WorkerCmd is the command message send from the manager to a worker

func (WorkerCmd) String

func (c WorkerCmd) String() string

type WorkerStatus

type WorkerStatus struct {
	ID           string    `json:"id"`
	URL          string    `json:"url"`           // worker url
	Token        string    `json:"token"`         // session token
	LastOnline   time.Time `json:"last_online"`   // last seen
	LastRegister time.Time `json:"last_register"` // last register time
}

A WorkerStatus is the information struct that describe a worker, and sent from the manager to clients.

Jump to

Keyboard shortcuts

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