filetemplate

package module
v0.0.0-...-6bd56bc Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2020 License: MIT Imports: 10 Imported by: 0

README

file-template

provide http and cli api for config file overwrite and reload

usage

$ curl -H "Content-type: application/json" "http://localhost:3003/file" -d '{"filename": "/tmp/my.cnf","content": "this is bingoohuang"}'
{"code":0,"message":"OK"}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindPid

func FindPid(v string) string

FindPid finds pid as possible as it can 1. direct pid value(all digits) 2. pid file (file exists) 3. pid finder shell(like pgrep goland, ps -ef|grep goland|grep -v grep|awk '{print $2}', and etc.

Types

type File

type File struct {
	// ID
	// 当ID不为空时,表示使用指定ID的内容为模板,填充ZERO部分字段
	// 当ID为空时,表示直接操作
	ID string `json:"id,omitempty"`
	// 当前结构体的描述/备注信息
	Desc string `json:"desc"`

	// 配置总文件名(带路径,全路径或者相对路径,支持~开头的相对路径)
	Filename string `json:"filename"`
	// 配置总文件名内容
	// 当为空时,表示不进行配置总文件名的替换
	Content string `json:"content,omitempty"`

	// 子配置文件所在目录
	// 场景:当总配置文件中,以形如include {sub_conf_dir}/*.conf包含子配置文件
	SubDir string `json:"sub_dir,omitempty"`

	// 子配置使用方式
	// 当为空时,采用全量写入的方式(软删除子配置所在目录所有文件)
	// 当为overwrite时,仅仅写入指定的子配置文件
	SubMode string `json:"sub_mode,omitempty"`

	// 子配置内容 文件名(不包含路径)->文件内容
	Subs map[string]string `json:"subs,omitempty"`

	// 重新加载的命令,例如Nginx的 nginx -s reload
	// 或者 kill -s HUP ${pid},中间的参数可以采用${pid}替换的形式
	Reload string `json:"reload,omitempty"`
	// pid号(整数),或者pid文件(文件路径),或者找到pid的命令,比如pgrep goland
	// 或者 ps -ef|grep goland|grep -v grep|awk '{print $2}'
	PID string `json:"pid,omitempty"`
}

File is the structure for config file

func (File) Execute

func (f File) Execute() (interface{}, error)

Execute executes the file request.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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