Add InitAPNSClient func.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
8623a92d50
commit
5812bd30d5
|
@ -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
|
||||
|
|
17
main.go
17
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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue