support command line.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
81826ac10c
commit
bf703d3e20
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package gopush
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
@ -52,8 +52,8 @@ func BuildDefaultPushConf() ConfYaml {
|
||||||
|
|
||||||
// iOS
|
// iOS
|
||||||
conf.Ios.Enabled = true
|
conf.Ios.Enabled = true
|
||||||
conf.Ios.PemCertPath = ""
|
conf.Ios.PemCertPath = "cert.pem"
|
||||||
conf.Ios.PemKeyPath = ""
|
conf.Ios.PemKeyPath = "key.pem"
|
||||||
conf.Ios.Production = false
|
conf.Ios.Production = false
|
||||||
|
|
||||||
return conf
|
return conf
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package gopush
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "0.0.1"
|
Version = "0.0.1"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package gopush
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package gopush
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/go-gcm"
|
"github.com/google/go-gcm"
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package main
|
package gopush
|
||||||
|
|
||||||
import (
|
import (
|
||||||
api "github.com/appleboy/gin-status-api"
|
api "github.com/appleboy/gin-status-api"
|
||||||
"github.com/fvbock/endless"
|
"github.com/fvbock/endless"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
apns "github.com/sideshow/apns2"
|
|
||||||
"github.com/sideshow/apns2/certificate"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
@ -56,36 +54,6 @@ func GetMainEngine() *gin.Engine {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func RunHTTPServer() {
|
||||||
var err error
|
|
||||||
|
|
||||||
// set default parameters.
|
|
||||||
PushConf = BuildDefaultPushConf()
|
|
||||||
|
|
||||||
// load user define config.
|
|
||||||
PushConf, err = LoadConfYaml("config.yaml")
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Unable to load config file: '%v'", err)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if PushConf.Ios.Enabled {
|
|
||||||
CertificatePemIos, err = certificate.FromPemFile(PushConf.Ios.PemKeyPath, "")
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Cert Error:", err)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if PushConf.Ios.Production {
|
|
||||||
ApnsClient = apns.NewClient(CertificatePemIos).Production()
|
|
||||||
} else {
|
|
||||||
ApnsClient = apns.NewClient(CertificatePemIos).Development()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
endless.ListenAndServe(":"+PushConf.Core.Port, GetMainEngine())
|
endless.ListenAndServe(":"+PushConf.Core.Port, GetMainEngine())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package main
|
package gopush
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func PrintGoPushVersion() {
|
func PrintGoPushVersion() {
|
||||||
fmt.Printf(`GoPush %s Compiler: %s %s Copyright (C) 2016 Bo-Yi Wu, Inc.`,
|
fmt.Printf(`GoPush %s, Compiler: %s %s, Copyright (C) 2016 Bo-Yi Wu, Inc.`,
|
||||||
Version,
|
Version,
|
||||||
runtime.Compiler,
|
runtime.Compiler,
|
||||||
runtime.Version())
|
runtime.Version())
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"github.com/appleboy/gopush/gopush"
|
||||||
|
"github.com/sideshow/apns2/certificate"
|
||||||
|
apns "github.com/sideshow/apns2"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
version := flag.Bool("v", false, "gopush version")
|
||||||
|
confPath := flag.String("c", "", "yaml configuration file path for gopush")
|
||||||
|
port := flag.String("p", "", "port number for gopush")
|
||||||
|
|
||||||
|
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 {
|
||||||
|
log.Printf("Unable to load yaml config file: '%v'", err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if gopush.PushConf.Ios.Enabled {
|
||||||
|
gopush.CertificatePemIos, err = certificate.FromPemFile(gopush.PushConf.Ios.PemKeyPath, "")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Cert Error:", err)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if gopush.PushConf.Ios.Production {
|
||||||
|
gopush.ApnsClient = apns.NewClient(gopush.CertificatePemIos).Production()
|
||||||
|
} else {
|
||||||
|
gopush.ApnsClient = apns.NewClient(gopush.CertificatePemIos).Development()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// overwrite server port
|
||||||
|
if *port != "" {
|
||||||
|
gopush.PushConf.Core.Port = *port
|
||||||
|
}
|
||||||
|
|
||||||
|
gopush.RunHTTPServer()
|
||||||
|
}
|
Loading…
Reference in New Issue