2016-03-27 02:58:57 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2016-05-03 02:07:50 +00:00
|
|
|
"github.com/appleboy/gorush/config"
|
2016-04-13 07:22:04 +00:00
|
|
|
"github.com/appleboy/gorush/gorush"
|
2016-03-27 02:58:57 +00:00
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
2016-04-16 09:11:31 +00:00
|
|
|
func checkInput(token, message string) {
|
|
|
|
if len(token) == 0 {
|
|
|
|
gorush.LogError.Fatal("Missing token flag (-t)")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(message) == 0 {
|
|
|
|
gorush.LogError.Fatal("Missing message flag (-m)")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-09 06:48:07 +00:00
|
|
|
var Version = "No Version Provided"
|
|
|
|
|
2016-03-27 02:58:57 +00:00
|
|
|
func main() {
|
2016-04-13 07:22:04 +00:00
|
|
|
version := flag.Bool("v", false, "gorush version")
|
|
|
|
confPath := flag.String("c", "", "yaml configuration file path for gorush")
|
|
|
|
certificateKeyPath := flag.String("i", "", "iOS certificate key file path for gorush")
|
|
|
|
apiKey := flag.String("k", "", "Android api key configuration for gorush")
|
|
|
|
port := flag.String("p", "", "port number for gorush")
|
2016-04-10 08:00:17 +00:00
|
|
|
token := flag.String("t", "", "token string")
|
|
|
|
message := flag.String("m", "", "notification message")
|
|
|
|
android := flag.Bool("android", false, "send android notification")
|
|
|
|
ios := flag.Bool("ios", false, "send ios notification")
|
|
|
|
production := flag.Bool("production", false, "production mode in iOS")
|
2016-04-28 06:39:34 +00:00
|
|
|
topic := flag.String("topic", "", "apns topic in iOS")
|
2016-03-27 02:58:57 +00:00
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
2016-05-09 06:48:07 +00:00
|
|
|
gorush.SetVersion(Version)
|
|
|
|
|
2016-03-27 02:58:57 +00:00
|
|
|
if *version {
|
2016-04-13 07:22:04 +00:00
|
|
|
gorush.PrintGoRushVersion()
|
2016-03-27 02:58:57 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// set default parameters.
|
2016-05-02 13:13:25 +00:00
|
|
|
gorush.PushConf = config.BuildDefaultPushConf()
|
2016-03-27 02:58:57 +00:00
|
|
|
|
|
|
|
// load user define config.
|
|
|
|
if *confPath != "" {
|
2016-05-02 13:13:25 +00:00
|
|
|
gorush.PushConf, err = config.LoadConfYaml(*confPath)
|
2016-03-27 02:58:57 +00:00
|
|
|
|
|
|
|
if err != nil {
|
2016-04-11 06:54:37 +00:00
|
|
|
log.Printf("Load yaml config file error: '%v'", err)
|
2016-03-27 02:58:57 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-02 15:51:42 +00:00
|
|
|
if *certificateKeyPath != "" {
|
2016-05-27 06:53:54 +00:00
|
|
|
gorush.PushConf.Ios.PemPath = *certificateKeyPath
|
2016-03-27 02:58:57 +00:00
|
|
|
}
|
|
|
|
|
2016-04-02 15:51:42 +00:00
|
|
|
if *apiKey != "" {
|
2016-04-13 07:22:04 +00:00
|
|
|
gorush.PushConf.Android.APIKey = *apiKey
|
2016-03-27 04:55:31 +00:00
|
|
|
}
|
|
|
|
|
2016-03-27 02:58:57 +00:00
|
|
|
// overwrite server port
|
|
|
|
if *port != "" {
|
2016-04-13 07:22:04 +00:00
|
|
|
gorush.PushConf.Core.Port = *port
|
2016-03-27 02:58:57 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 07:22:04 +00:00
|
|
|
if err = gorush.InitLog(); err != nil {
|
2016-04-05 06:50:08 +00:00
|
|
|
log.Println(err)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2016-04-05 05:15:47 +00:00
|
|
|
|
2016-04-10 08:00:17 +00:00
|
|
|
// send android notification
|
|
|
|
if *android {
|
2016-04-13 07:22:04 +00:00
|
|
|
gorush.PushConf.Android.Enabled = true
|
|
|
|
req := gorush.PushNotification{
|
2016-04-10 08:00:17 +00:00
|
|
|
Tokens: []string{*token},
|
2016-04-13 07:22:04 +00:00
|
|
|
Platform: gorush.PlatFormAndroid,
|
2016-04-10 08:00:17 +00:00
|
|
|
Message: *message,
|
|
|
|
}
|
|
|
|
|
2016-04-24 07:54:41 +00:00
|
|
|
err := gorush.CheckMessage(req)
|
2016-04-24 06:30:17 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
gorush.LogError.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-04-15 01:41:10 +00:00
|
|
|
gorush.InitAppStatus()
|
2016-04-13 07:22:04 +00:00
|
|
|
gorush.PushToAndroid(req)
|
2016-04-02 15:51:42 +00:00
|
|
|
|
2016-04-02 23:27:10 +00:00
|
|
|
return
|
2016-04-02 15:51:42 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 08:00:17 +00:00
|
|
|
// send android notification
|
|
|
|
if *ios {
|
|
|
|
if *production {
|
2016-04-13 07:22:04 +00:00
|
|
|
gorush.PushConf.Ios.Production = true
|
2016-04-10 08:00:17 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 07:22:04 +00:00
|
|
|
gorush.PushConf.Ios.Enabled = true
|
|
|
|
req := gorush.PushNotification{
|
2016-04-10 08:00:17 +00:00
|
|
|
Tokens: []string{*token},
|
2016-04-13 07:22:04 +00:00
|
|
|
Platform: gorush.PlatFormIos,
|
2016-04-10 08:00:17 +00:00
|
|
|
Message: *message,
|
|
|
|
}
|
|
|
|
|
2016-04-28 06:39:34 +00:00
|
|
|
if *topic != "" {
|
|
|
|
req.Topic = *topic
|
|
|
|
}
|
|
|
|
|
2016-04-24 07:54:41 +00:00
|
|
|
err := gorush.CheckMessage(req)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
gorush.LogError.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-04-15 01:41:10 +00:00
|
|
|
gorush.InitAppStatus()
|
2016-04-13 07:22:04 +00:00
|
|
|
gorush.InitAPNSClient()
|
|
|
|
gorush.PushToIOS(req)
|
2016-04-10 08:00:17 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-04-13 07:22:04 +00:00
|
|
|
if err = gorush.CheckPushConf(); err != nil {
|
|
|
|
gorush.LogError.Fatal(err)
|
2016-04-10 08:00:17 +00:00
|
|
|
}
|
|
|
|
|
2016-04-15 01:41:10 +00:00
|
|
|
gorush.InitAppStatus()
|
2016-04-13 07:22:04 +00:00
|
|
|
gorush.InitAPNSClient()
|
2016-04-14 12:34:23 +00:00
|
|
|
gorush.InitWorkers(gorush.PushConf.Core.WorkerNum, gorush.PushConf.Core.QueueNum)
|
2016-04-13 07:22:04 +00:00
|
|
|
gorush.RunHTTPServer()
|
2016-03-27 02:58:57 +00:00
|
|
|
}
|