core

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 28, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

@Description: just go @Author: skipper @Date: 2020/1/13 @Time: 3:50 PM @ProjectName fileUpdater

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BackupFile

func BackupFile(filePath string) (newPath string, err error)

func BashExec

func BashExec(cmd string) (output string, err error)

func FindOldFiles

func FindOldFiles(Paths []string, n int) (oldFiles []string)

return the most older files in given files

func KeepBackup

func KeepBackup(path string, num int)

func RestoreFile

func RestoreFile(filePath, BackupPath string) error

Types

type CommandHook

type CommandHook struct {
	Commands []string `json:"commands"`
	Mode     string   `json:"mode"`
}

func (CommandHook) Do

func (c CommandHook) Do() error

type FileUpdater

type FileUpdater struct {
	Name     string      `json:"name" yaml:"name"`
	FilePath string      `json:"path" yaml:"path"`
	Backup   bool        `json:"backup" yaml:"backup"`
	PreHook  CommandHook `json:"pre_hook" yaml:"pre_hook"`
	PostHook CommandHook `json:"post_hook" yaml:"post_hook"`
}

func (FileUpdater) GetFile

func (u FileUpdater) GetFile() (reader *os.File, err error)

should close reader

func (FileUpdater) GetFileContent

func (u FileUpdater) GetFileContent() ([]byte, error)

func (FileUpdater) GetFileContentAsString

func (u FileUpdater) GetFileContentAsString() (string, error)

func (FileUpdater) UpdateFile

func (u FileUpdater) UpdateFile(date io.Reader) error

when preHook Not nil should execute pre hook when preHook executed and exit not 0 return copy origin file for backup and update file when file update succeeded execute the post hook pre->write->post

type FilesAtime

type FilesAtime []fileAtime

func (FilesAtime) Len

func (f FilesAtime) Len() int

func (FilesAtime) Less

func (f FilesAtime) Less(i, j int) bool

func (FilesAtime) Swap

func (f FilesAtime) Swap(i, j int)

type Hook

type Hook interface {
	Do() error
}

type ServerConfigs

type ServerConfigs struct {
	ServerHost   string            `json:"server_host" yaml:"server_host"`
	ServerPort   string            `json:"server_port" yaml:"server_port"`
	FileUpdaters []FileUpdater     `json:"updaters" yaml:"updaters"`
	Processes    []process.Process `json:"processes" yaml:"processes"`
	IncludeSelf  bool              `json:"include_self"`
}

server configFiles struct

func (ServerConfigs) GetUpdaterByName

func (s ServerConfigs) GetUpdaterByName(name string) *FileUpdater

func (ServerConfigs) RunProcess

func (s ServerConfigs) RunProcess()

type Updater

type Updater interface {
	GetFileContent() (io.Reader, error)
}

Jump to

Keyboard shortcuts

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