mirror of
https://github.com/woodchen-ink/webp_server_go.git
synced 2025-07-18 13:42:02 +08:00
dump systemd and config.json
Param: dump-config dump-systemd
This commit is contained in:
parent
102cba7f4f
commit
c0f5368319
@ -35,8 +35,43 @@ type Config struct {
|
||||
ExhaustPath string `json:"EXHAUST_PATH"`
|
||||
}
|
||||
|
||||
const version = "0.0.3"
|
||||
|
||||
var configPath string
|
||||
var prefetch bool
|
||||
var dumpConfig bool
|
||||
var dumpSystemd bool
|
||||
|
||||
const sampleConfig = `
|
||||
{
|
||||
"HOST": "127.0.0.1",
|
||||
"PORT": "3333",
|
||||
"QUALITY": "80",
|
||||
"IMG_PATH": "/Users/benny/goLandProject/webp_server_go/pics",
|
||||
"EXHAUST_PATH": "",
|
||||
"ALLOWED_TYPES": ["jpg", "png", "jpeg", "bmp", "gif"]
|
||||
}
|
||||
`
|
||||
const sampleSystemd = `
|
||||
[Unit]
|
||||
Description=WebP Server
|
||||
Documentation=https://github.com/n0vad3v/webp_server_go
|
||||
After=nginx.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
StandardError=journal
|
||||
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||
WorkingDirectory=/opt/webps
|
||||
ExecStart=/opt/webps/webp-server --config /opt/webps/config.json
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
Restart=always
|
||||
RestartSec=3s
|
||||
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
`
|
||||
|
||||
func loadConfig(path string) Config {
|
||||
var config Config
|
||||
@ -124,6 +159,8 @@ func webpEncoder(p1, p2 string, quality float32, Log bool, c chan int) (err erro
|
||||
func init() {
|
||||
flag.StringVar(&configPath, "config", "config.json", "/path/to/config.json. (Default: ./config.json)")
|
||||
flag.BoolVar(&prefetch, "prefetch", false, "Prefetch and convert image to webp")
|
||||
flag.BoolVar(&dumpConfig, "dump-config", false, "Print sample config.json")
|
||||
flag.BoolVar(&dumpSystemd, "dump-systemd", false, "Print sample systemd service file.")
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
@ -289,6 +326,18 @@ func main() {
|
||||
ExhaustPath = config.ExhaustPath
|
||||
}
|
||||
|
||||
// process cli params
|
||||
if dumpConfig {
|
||||
fmt.Println(sampleConfig)
|
||||
os.Exit(0)
|
||||
}
|
||||
if dumpSystemd {
|
||||
fmt.Println(sampleSystemd)
|
||||
|
||||
os.Exit(0)
|
||||
|
||||
}
|
||||
|
||||
if prefetch {
|
||||
prefetchImages(confImgPath, ExhaustPath, QUALITY)
|
||||
}
|
||||
@ -300,7 +349,7 @@ func main() {
|
||||
ListenAddress := HOST + ":" + PORT
|
||||
|
||||
// Server Info
|
||||
ServerInfo := "WebP Server is running at " + ListenAddress
|
||||
ServerInfo := "WebP Server " + version + " is running at " + ListenAddress
|
||||
fmt.Println(ServerInfo)
|
||||
|
||||
app.Get("/*", Convert(confImgPath, ExhaustPath, AllowedTypes, QUALITY))
|
||||
|
Loading…
x
Reference in New Issue
Block a user