From 6864ffe9f05020671251de683d84b27e863053f7 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Wed, 2 Aug 2017 22:31:31 +0800 Subject: [PATCH] Putting main() first makes reading the file a lot more easier. Signed-off-by: Bo-Yi Wu --- main.go | 142 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/main.go b/main.go index 3c80f6e..a715767 100644 --- a/main.go +++ b/main.go @@ -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 to bind (default: any) - -p, --port Use port for clients (default: 8088) - -c, --config Configuration file path - -m, --message Notification message - -t, --token Notification token - -e, --engine Storage engine (memory, redis ...) - --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 +}