update ios cert config.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-03-26 14:26:07 +08:00
parent 76c71b5c9f
commit 5ce2a8e2ca
3 changed files with 18 additions and 10 deletions

View File

@ -1,5 +1,10 @@
package main package main
import (
"crypto/tls"
)
var ( var (
PushConf ConfYaml PushConf ConfYaml
CertificatePemIos tls.Certificate
) )

15
main.go
View File

@ -6,6 +6,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"log" "log"
"net/http" "net/http"
"github.com/sideshow/apns2/certificate"
) )
func AbortWithError(c *gin.Context, code int, message string) { func AbortWithError(c *gin.Context, code int, message string) {
@ -55,11 +56,13 @@ func GetMainEngine() *gin.Engine {
} }
func main() { func main() {
var err error
// set default parameters // set default parameters.
PushConf = BuildDefaultPushConf() PushConf = BuildDefaultPushConf()
config, err := LoadConfYaml("config.yaml") // load user define config.
PushConf, err = LoadConfYaml("config.yaml")
if err != nil { if err != nil {
log.Printf("Unable to load config file: '%v'", err) log.Printf("Unable to load config file: '%v'", err)
@ -67,7 +70,13 @@ func main() {
return return
} }
PushConf = config CertificatePemIos, err = certificate.FromPemFile(PushConf.Ios.PemKeyPath, "")
if err != nil {
log.Println("Cert Error:", err)
return
}
endless.ListenAndServe(":"+PushConf.Core.Port, GetMainEngine()) endless.ListenAndServe(":"+PushConf.Core.Port, GetMainEngine())
} }

View File

@ -3,7 +3,6 @@ package main
import ( import (
"github.com/google/go-gcm" "github.com/google/go-gcm"
apns "github.com/sideshow/apns2" apns "github.com/sideshow/apns2"
"github.com/sideshow/apns2/certificate"
"github.com/sideshow/apns2/payload" "github.com/sideshow/apns2/payload"
"log" "log"
) )
@ -64,12 +63,7 @@ func pushNotification(notification RequestPushNotification) bool {
success bool success bool
) )
cert, err := certificate.FromPemFile("./key.pem", "") apnsClient := apns.NewClient(CertificatePemIos).Development()
if err != nil {
log.Println("Cert Error:", err)
}
apnsClient := apns.NewClient(cert).Development()
switch notification.Platform { switch notification.Platform {
case PlatFormIos: case PlatFormIos: