config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecBoolScript

func ExecBoolScript(script string, val Any) (bool, error)

Types

type Any

type Any map[string]interface{}

type Config

type Config struct {
	Server *ConfigServer `yaml:"server"`
	Tasks  []*Task       `yaml:"tasks"`
}

func LoadConfig

func LoadConfig(file string) (*Config, error)

type ConfigServer

type ConfigServer struct {
	User              string `yaml:"user"`
	Host              string `yaml:"host"`
	SSHPrivateKeyPath string `yaml:"ssh_private_key_path"`
}

func (*ConfigServer) ServerHost

func (r *ConfigServer) ServerHost() string

type ConfigTaskCmd

type ConfigTaskCmd struct {
	Commands []string
}

func (ConfigTaskCmd) MarshalYAML

func (r ConfigTaskCmd) MarshalYAML() (interface{}, error)

func (*ConfigTaskCmd) UnmarshalYAML

func (r *ConfigTaskCmd) UnmarshalYAML(unmarshal func(interface{}) error) error

type ConfigTaskDownload

type ConfigTaskDownload struct {
	Src  string `yaml:"src"`
	Dest string `yaml:"dest"`
}

type ConfigTaskUpload

type ConfigTaskUpload struct {
	Src       string `yaml:"src"`
	Dest      string `yaml:"dest"`
	ExpendEnv bool   `yaml:"expend_env"`
}

type IfExpr

type IfExpr string

IfExpr 是 if 表达式,输入: string,输出: bool

IfExpr 支持下面几个函数和操作符

函数:exist
操作符:&& || !

示例 if: exist("/path") if: exist(/path) if: !exist(/path) if: exist(/path1) && !exist(/path2) if: (exist(/path1) || !exist(/path2)) && exist(/path3)

func (IfExpr) IsTrue

func (r IfExpr) IsTrue(vals Any) (bool, error)

type Task

type Task struct {
	// 公用 task 参数
	ID   string `yaml:"id"`   // 唯一性 ID,不允许重复,可以通过 $tasks.<id>.outputs.<name> 取数据
	Name string `yaml:"name"` // 名称,打印用
	If   IfExpr `yaml:"if"`   // 一个 expr 表达式,为真,则这个 task 才可以运行
	Dir  string `yaml:"dir"`  // 执行 command 的目录

	// 下面是 task 的具体实现
	Upload   *ConfigTaskUpload   `yaml:"upload"`
	Download *ConfigTaskDownload `yaml:"download"`
	Cmd      *ConfigTaskCmd      `yaml:"cmd"`
	LocalCmd *ConfigTaskCmd      `yaml:"local_cmd"`
}

func (*Task) ShouldRun

func (r *Task) ShouldRun(vals Any) (string, bool, error)

是否可以运行

func (*Task) TaskName

func (r *Task) TaskName(idx int) string

任务名称

func (*Task) TaskType

func (r *Task) TaskType() TaskType

type TaskType

type TaskType string
const (
	TaskTypeUpload   TaskType = "upload"
	TaskTypeCmd      TaskType = "cmd"
	TaskTypeLocalCmd TaskType = "local_cmd"
	TaskTypeDownload TaskType = "download"
)

Jump to

Keyboard shortcuts

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