support command line.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2016-03-27 10:58:57 +08:00
parent 81826ac10c
commit bf703d3e20
7 changed files with 71 additions and 42 deletions

View File

@@ -1,4 +1,4 @@
package main
package gopush
import (
"gopkg.in/yaml.v2"
@@ -52,8 +52,8 @@ func BuildDefaultPushConf() ConfYaml {
// iOS
conf.Ios.Enabled = true
conf.Ios.PemCertPath = ""
conf.Ios.PemKeyPath = ""
conf.Ios.PemCertPath = "cert.pem"
conf.Ios.PemKeyPath = "key.pem"
conf.Ios.Production = false
return conf

View File

@@ -1,4 +1,4 @@
package main
package gopush
const (
Version = "0.0.1"

View File

@@ -1,4 +1,4 @@
package main
package gopush
import (
"crypto/tls"

View File

@@ -1,4 +1,4 @@
package main
package gopush
import (
"github.com/google/go-gcm"

View File

@@ -1,11 +1,9 @@
package main
package gopush
import (
api "github.com/appleboy/gin-status-api"
"github.com/fvbock/endless"
"github.com/gin-gonic/gin"
apns "github.com/sideshow/apns2"
"github.com/sideshow/apns2/certificate"
"log"
"net/http"
)
@@ -56,36 +54,6 @@ func GetMainEngine() *gin.Engine {
return r
}
func main() {
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()
}
}
func RunHTTPServer() {
endless.ListenAndServe(":"+PushConf.Core.Port, GetMainEngine())
}

View File

@@ -1,4 +1,4 @@
package main
package gopush
import (
"fmt"
@@ -7,7 +7,7 @@ import (
)
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,
runtime.Compiler,
runtime.Version())