mci

package module
v0.0.0-...-5158a1d Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: MIT Imports: 15 Imported by: 0

README

mci(mysqlclusterinit)

a tool to modify HAConfig conf file and restart HAConfig.

Build

env GOOS=linux GOARCH=amd64 go install ./...

Usage

➜  haconf haconf -h
Usage of haconf:
      --BackAddrs string             BackAddrs
      --Debug                        Debug
      --HAProxyCfg string            HAProxyCfg
      --HAProxyRestartShell string   HAProxyRestartShell
      --ListenName string            ListenName
      --Port int                     Port
      --check                        check HAConf
  -c, --config string                config file path (default "./config.toml")
  -v, --version                      show version
pflag: help requested

Demo

➜  haconf --ListenName yc --Port 1990 --BackAddrs 127.0.0.1:8888,127.0.0.2:8888 --Debug --HAProxyCfg testdata//test.cfg
INFO[0000] HAProxy:
listen yc
  bind 127.0.0.1:1990
  mode tcp
  option tcpka
  server s-1 127.0.0.1:8888 check inter 1s
  server s-2 127.0.0.2:8888 check inter 1s
➜  more testdata/test.cfg
#ycStart
#ycEnd
➜  haconf --ListenName yc --Port 1990 --BackAddrs 127.0.0.1:8888,127.0.0.2:8888  --HAProxyCfg testdata//test.cfg
INFO[0000] prepare to overwriteHAProxyCnf
listen yc
  bind 127.0.0.1:1990
  mode tcp
  option tcpka
  server s-1 127.0.0.1:8888 check inter 1s
  server s-2 127.0.0.2:8888 check inter 1s
INFO[0000] overwriteHAProxyCnf completed
ERRO[0000] error error exiting code 127, stdout:[], stderr:[]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeclarePflagsByStruct

func DeclarePflagsByStruct(structVar interface{})

DeclarePflagsByStruct declares flags from struct fields'name and type

func FileExists

func FileExists(filename string) error

FileExists 检查文件是否存在,并且不是目录

func FindRegexGroup1

func FindRegexGroup1(str, regexStr string) ([]string, error)

FindRegexGroup1 使用正则表达式regexStr在str中查找内容

func ReplaceFileContent

func ReplaceFileContent(filename, regexStr, repl string) error

ReplaceFileContent 使用正则表达式查找模式,并且替换正则1号捕获分组为指定的内容

func ReplaceRegexGroup1

func ReplaceRegexGroup1(str, regexStr, repl string) (string, error)

ReplaceRegexGroup1 使用正则表达式regexStr在str中查找内容,并且替换正则1号捕获分组为指定的内容

func SearchPatternLines

func SearchPatternLines(str, boundaryRegexStr, captureGroup1Regex string) ([]string, error)

SearchPatternLines 使用正则表达式boundaryRegexStr在str中查找大块,然后在大块中用captureGroup1Regex中的每行寻找匹配

func SearchPatternLinesInFile

func SearchPatternLinesInFile(filename, boundaryRegexStr, captureGroup1Regex string) ([]string, error)

SearchPatternLinesInFile 使用正则表达式boundaryRegexStr查找大块,然后在大块中用captureGroup1Regex中的每行寻找匹配

func ViperToStruct

func ViperToStruct(structVar interface{})

ViperToStruct read viper value to struct

Types

type Result

type Result struct {
	HAProxy string
}

Result 表示初始化结果

type Settings

type Settings struct {
	ListenName          string   `validate:"empty=false"`              // HAProxy配置文件中listen名称
	Port                int      `validate:"gte=0"`                    // HAProxy前端端口号
	BackAddrs           []string `validate:"empty=false"`              // 后端地址
	HAProxyCfg          string   `default:"/etc/haproxy.cfg"`          // HAProxy配置文件地址
	HAProxyRestartShell string   `default:"systemctl restart haproxy"` // HAProxy重启命令

	Debug bool // 测试模式,只打印HAProxy配置, 不实际执行
}

Settings 表示初始化化MySQL集群所需要的参数结构

func (Settings) CheckHAProxyServers

func (s Settings) CheckHAProxyServers()

CheckHAProxyServers 检查

func (Settings) Exec

func (s Settings) Exec() (r Result, err error)

Exec 执行HAProxy配置更新

func (Settings) GetAnchorEnd

func (s Settings) GetAnchorEnd() string

func (Settings) GetAnchorStart

func (s Settings) GetAnchorStart() string

func (*Settings) ValidateAndSetDefault

func (s *Settings) ValidateAndSetDefault(options ...SettingsOption) error

type SettingsOption

type SettingsOption int
const (
	Validate SettingsOption = iota
	SetDefault
)

Directories

Path Synopsis
cmd
haconf command

Jump to

Keyboard shortcuts

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