mirror of
https://github.com/songquanpeng/message-pusher.git
synced 2025-10-03 15:26:29 +08:00
45 lines
797 B
Go
45 lines
797 B
Go
package common
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
var (
|
|
Port = flag.Int("port", 3000, "the listening port")
|
|
PrintVersion = flag.Bool("version", false, "print version and exit")
|
|
LogDir = flag.String("log-dir", "", "specify the log directory")
|
|
)
|
|
|
|
func init() {
|
|
flag.Parse()
|
|
|
|
if *PrintVersion {
|
|
fmt.Println(Version)
|
|
os.Exit(0)
|
|
}
|
|
|
|
if os.Getenv("SESSION_SECRET") != "" {
|
|
SessionSecret = os.Getenv("SESSION_SECRET")
|
|
}
|
|
if os.Getenv("SQLITE_PATH") != "" {
|
|
SQLitePath = os.Getenv("SQLITE_PATH")
|
|
}
|
|
if *LogDir != "" {
|
|
var err error
|
|
*LogDir, err = filepath.Abs(*LogDir)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
if _, err := os.Stat(*LogDir); os.IsNotExist(err) {
|
|
err = os.Mkdir(*LogDir, 0777)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
}
|
|
}
|