Putting main() first makes reading the file a lot more easier.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2017-08-02 22:31:31 +08:00
parent 83d155bade
commit 6864ffe9f0
1 changed files with 71 additions and 71 deletions

142
main.go
View File

@ -24,77 +24,6 @@ func checkInput(token, message string) {
}
}
// Version control for gorush.
var Version = "No Version Provided"
var usageStr = `
________ .__
/ _____/ ____ _______ __ __ ______| |__
/ \ ___ / _ \\_ __ \| | \/ ___/| | \
\ \_\ \( <_> )| | \/| | /\___ \ | Y \
\______ / \____/ |__| |____//____ >|___| /
\/ \/ \/
Usage: gorush [options]
Server Options:
-A, --address <address> Address to bind (default: any)
-p, --port <port> Use port for clients (default: 8088)
-c, --config <file> Configuration file path
-m, --message <message> Notification message
-t, --token <token> Notification token
-e, --engine <engine> Storage engine (memory, redis ...)
--title <title> Notification title
--proxy <proxy> Proxy URL (only for GCM)
--pid <pid path> Process identifier path
--redis-addr <redis addr> Redis addr (default: localhost:6379)
iOS Options:
-i, --key <file> certificate key file path
-P, --password <password> certificate key password
--topic <topic> iOS topic
--ios enabled iOS (default: false)
--production iOS production mode (default: false)
Android Options:
-k, --apikey <api_key> Android API Key
--android enabled android (default: false)
Common Options:
-h, --help Show this message
-v, --version Show version
`
// usage will print out the flag options for the server.
func usage() {
fmt.Printf("%s\n", usageStr)
os.Exit(0)
}
func createPIDFile() error {
if !gorush.PushConf.Core.PID.Enabled {
return nil
}
pidPath := gorush.PushConf.Core.PID.Path
_, err := os.Stat(pidPath)
if os.IsNotExist(err) || gorush.PushConf.Core.PID.Override {
currentPid := os.Getpid()
if err := os.MkdirAll(filepath.Dir(pidPath), os.ModePerm); err != nil {
return fmt.Errorf("Can't create PID folder on %v", err)
}
file, err := os.Create(pidPath)
if err != nil {
return fmt.Errorf("Can't create PID file: %v", err)
}
defer file.Close()
if _, err := file.WriteString(strconv.FormatInt(int64(currentPid), 10)); err != nil {
return fmt.Errorf("Can'write PID information on %s: %v", pidPath, err)
}
} else {
return fmt.Errorf("%s already exists", pidPath)
}
return nil
}
func main() {
opts := config.ConfYaml{}
@ -321,3 +250,74 @@ func main() {
gorush.LogError.Fatal(err)
}
}
// Version control for gorush.
var Version = "No Version Provided"
var usageStr = `
________ .__
/ _____/ ____ _______ __ __ ______| |__
/ \ ___ / _ \\_ __ \| | \/ ___/| | \
\ \_\ \( <_> )| | \/| | /\___ \ | Y \
\______ / \____/ |__| |____//____ >|___| /
\/ \/ \/
Usage: gorush [options]
Server Options:
-A, --address <address> Address to bind (default: any)
-p, --port <port> Use port for clients (default: 8088)
-c, --config <file> Configuration file path
-m, --message <message> Notification message
-t, --token <token> Notification token
-e, --engine <engine> Storage engine (memory, redis ...)
--title <title> Notification title
--proxy <proxy> Proxy URL (only for GCM)
--pid <pid path> Process identifier path
--redis-addr <redis addr> Redis addr (default: localhost:6379)
iOS Options:
-i, --key <file> certificate key file path
-P, --password <password> certificate key password
--topic <topic> iOS topic
--ios enabled iOS (default: false)
--production iOS production mode (default: false)
Android Options:
-k, --apikey <api_key> Android API Key
--android enabled android (default: false)
Common Options:
-h, --help Show this message
-v, --version Show version
`
// usage will print out the flag options for the server.
func usage() {
fmt.Printf("%s\n", usageStr)
os.Exit(0)
}
func createPIDFile() error {
if !gorush.PushConf.Core.PID.Enabled {
return nil
}
pidPath := gorush.PushConf.Core.PID.Path
_, err := os.Stat(pidPath)
if os.IsNotExist(err) || gorush.PushConf.Core.PID.Override {
currentPid := os.Getpid()
if err := os.MkdirAll(filepath.Dir(pidPath), os.ModePerm); err != nil {
return fmt.Errorf("Can't create PID folder on %v", err)
}
file, err := os.Create(pidPath)
if err != nil {
return fmt.Errorf("Can't create PID file: %v", err)
}
defer file.Close()
if _, err := file.WriteString(strconv.FormatInt(int64(currentPid), 10)); err != nil {
return fmt.Errorf("Can'write PID information on %s: %v", pidPath, err)
}
} else {
return fmt.Errorf("%s already exists", pidPath)
}
return nil
}