NewClient returns a new Client with an underlying http.Client configured with the correct APNs HTTP/2 transport settings. It does not connect to the APNs until the first Notification is sent via the Push method. As per the Apple APNs Provider API, you should keep a handle on this client so that you
(certificate tls.Certificate)
| 89 | // If your use case involves multiple long-lived connections, consider using |
| 90 | // the ClientManager, which manages clients for you. |
| 91 | func NewClient(certificate tls.Certificate) *Client { |
| 92 | tlsConfig := &tls.Config{ |
| 93 | Certificates: []tls.Certificate{certificate}, |
| 94 | } |
| 95 | if len(certificate.Certificate) > 0 { |
| 96 | tlsConfig.BuildNameToCertificate() |
| 97 | } |
| 98 | transport := &http2.Transport{ |
| 99 | TLSClientConfig: tlsConfig, |
| 100 | DialTLS: DialTLS, |
| 101 | ReadIdleTimeout: ReadIdleTimeout, |
| 102 | } |
| 103 | return &Client{ |
| 104 | HTTPClient: &http.Client{ |
| 105 | Transport: transport, |
| 106 | Timeout: HTTPClientTimeout, |
| 107 | }, |
| 108 | Certificate: certificate, |
| 109 | Host: DefaultHost, |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // NewTokenClient returns a new Client with an underlying http.Client configured |
| 114 | // with the correct APNs HTTP/2 transport settings. It does not connect to the APNs |
no outgoing calls