2016-03-27 02:58:57 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"github.com/appleboy/gopush/gopush"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
version := flag.Bool("v", false, "gopush version")
|
|
|
|
confPath := flag.String("c", "", "yaml configuration file path for gopush")
|
2016-03-27 04:55:31 +00:00
|
|
|
certificateKeyPath := flag.String("i", "", "iOS certificate key file path for gopush")
|
|
|
|
apiKey := flag.String("k", "", "Android api key configuration for gopush")
|
2016-03-27 02:58:57 +00:00
|
|
|
port := flag.String("p", "", "port number for gopush")
|
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-03-27 02:58:57 +00:00
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *version {
|
|
|
|
gopush.PrintGoPushVersion()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// set default parameters.
|
|
|
|
gopush.PushConf = gopush.BuildDefaultPushConf()
|
|
|
|
|
|
|
|
// load user define config.
|
|
|
|
if *confPath != "" {
|
|
|
|
gopush.PushConf, err = gopush.LoadConfYaml(*confPath)
|
|
|
|
|
|
|
|
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 != "" {
|
|
|
|
gopush.PushConf.Ios.PemKeyPath = *certificateKeyPath
|
2016-03-27 02:58:57 +00:00
|
|
|
}
|
|
|
|
|
2016-04-02 15:51:42 +00:00
|
|
|
if *apiKey != "" {
|
|
|
|
gopush.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 != "" {
|
|
|
|
gopush.PushConf.Core.Port = *port
|
|
|
|
}
|
|
|
|
|
2016-04-05 06:50:08 +00:00
|
|
|
if err = gopush.InitLog(); err != nil {
|
|
|
|
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 {
|
|
|
|
if len(*token) == 0 {
|
|
|
|
gopush.LogError.Fatal("Missing token flag (-t)")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(*message) == 0 {
|
|
|
|
gopush.LogError.Fatal("Missing message flag (-m)")
|
|
|
|
}
|
|
|
|
|
|
|
|
gopush.PushConf.Android.Enabled = true
|
|
|
|
req := gopush.PushNotification{
|
|
|
|
Tokens: []string{*token},
|
|
|
|
Platform: gopush.PlatFormAndroid,
|
|
|
|
Message: *message,
|
|
|
|
}
|
|
|
|
|
|
|
|
gopush.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 len(*token) == 0 {
|
|
|
|
gopush.LogError.Fatal("Missing token flag (-t)")
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(*message) == 0 {
|
|
|
|
gopush.LogError.Fatal("Missing message flag (-m)")
|
|
|
|
}
|
|
|
|
|
|
|
|
if *production {
|
|
|
|
gopush.PushConf.Ios.Production = true
|
|
|
|
}
|
|
|
|
|
|
|
|
gopush.PushConf.Ios.Enabled = true
|
|
|
|
req := gopush.PushNotification{
|
|
|
|
Tokens: []string{*token},
|
|
|
|
Platform: gopush.PlatFormIos,
|
|
|
|
Message: *message,
|
|
|
|
}
|
|
|
|
|
|
|
|
gopush.InitAPNSClient()
|
|
|
|
gopush.PushToIOS(req)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if err = gopush.CheckPushConf(); err != nil {
|
|
|
|
gopush.LogError.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-03-27 05:08:31 +00:00
|
|
|
gopush.InitAPNSClient()
|
2016-03-27 02:58:57 +00:00
|
|
|
gopush.RunHTTPServer()
|
|
|
|
}
|