@@ -16,34 +16,36 @@ var clientV2 *apns2.Client
1616
1717func init () {
1818 // init apns for DanXi v1
19- initAPNS (config .Config .APNSKeyPath , & client )
19+ client = newAPNSClient (config .Config .APNSKeyPath , config . Config . APNSKeyPassword )
2020
2121 // init apns for DanXi v2
22- initAPNS (config .Config .APNSKeyPathV2 , & clientV2 )
22+ clientV2 = newAPNSClient (config .Config .APNSKeyPathV2 , config . Config . APNSKeyPasswordV2 )
2323}
2424
25- // initAPNS init apns
26- func initAPNS (path string , client * * apns2.Client ) {
25+ // newAPNSClient create apns client from cert file and password
26+ func newAPNSClient (path string , password string ) ( client * apns2.Client ) {
2727 var (
2828 err error
2929 cert tls.Certificate
3030 )
3131
3232 if strings .HasSuffix (path , ".p12" ) {
33- cert , err = certificate .FromP12File (path , "" )
33+ cert , err = certificate .FromP12File (path , password )
3434 } else {
35- cert , err = certificate .FromPemFile (path , "" )
35+ cert , err = certificate .FromPemFile (path , password )
3636 }
3737
3838 if err != nil {
3939 log .Warn ().Err (err ).Str ("scope" , "init APNs" ).Msg ("APNs cert error" )
40- return
40+ return nil
4141 }
4242 if config .Config .Mode == "dev" {
43- * client = apns2 .NewClient (cert ).Development ()
43+ client = apns2 .NewClient (cert ).Development ()
4444 log .Debug ().Msg ("init apns; use development mode" )
4545 } else {
46- * client = apns2 .NewClient (cert ).Production ()
46+ client = apns2 .NewClient (cert ).Production ()
4747 log .Debug ().Msg ("init apns; use production mode" )
4848 }
49+
50+ return
4951}
0 commit comments