diff --git a/gorush/notification.go b/gorush/notification.go index 2671ae0..7bea866 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -3,6 +3,7 @@ package gopush import ( "github.com/google/go-gcm" apns "github.com/sideshow/apns2" + "github.com/sideshow/apns2/certificate" "github.com/sideshow/apns2/payload" "log" ) @@ -58,6 +59,26 @@ type RequestPushNotification struct { IDs []uint64 `json:"seq_id,omitempty"` } +func InitAPNSClient() { + if PushConf.Ios.Enabled { + var err error + + 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 pushNotification(notification RequestPushNotification) bool { var ( success bool diff --git a/main.go b/main.go index 52f8a1a..c185909 100644 --- a/main.go +++ b/main.go @@ -3,8 +3,6 @@ package main import ( "flag" "github.com/appleboy/gopush/gopush" - "github.com/sideshow/apns2/certificate" - apns "github.com/sideshow/apns2" "log" ) @@ -49,20 +47,6 @@ func main() { return } - - 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() - } } // check andorid api key exist @@ -84,5 +68,6 @@ func main() { gopush.PushConf.Core.Port = *port } + gopush.InitAPNSClient() gopush.RunHTTPServer() }