()
| 16 | ) |
| 17 | |
| 18 | func main() { |
| 19 | certPath := flag.String("cert", "", "Path to .p12 certificate file (Required)") |
| 20 | token := flag.String("token", "", "Push token (Required)") |
| 21 | topic := flag.String("topic", "", "Topic (Required)") |
| 22 | proxy := flag.String("proxy", "", "Proxy URL (Required)") |
| 23 | flag.Parse() |
| 24 | |
| 25 | if *certPath == "" || *token == "" || *topic == "" { |
| 26 | flag.PrintDefaults() |
| 27 | os.Exit(1) |
| 28 | } |
| 29 | |
| 30 | certificate, certErr := certificate.FromP12File(*certPath, "") |
| 31 | if certErr != nil { |
| 32 | log.Fatal("Cert Error:", certErr) |
| 33 | } |
| 34 | |
| 35 | tlsConfig := &tls.Config{ |
| 36 | Certificates: []tls.Certificate{certificate}, |
| 37 | } |
| 38 | |
| 39 | if len(certificate.Certificate) > 0 { |
| 40 | tlsConfig.BuildNameToCertificate() |
| 41 | } |
| 42 | |
| 43 | transport := &http.Transport{ |
| 44 | TLSClientConfig: tlsConfig, |
| 45 | Proxy: func(request *http.Request) (*url.URL, error) { |
| 46 | return url.Parse(*proxy) |
| 47 | }, |
| 48 | IdleConnTimeout: 60 * time.Second, |
| 49 | } |
| 50 | |
| 51 | transportErr := http2.ConfigureTransport(transport) |
| 52 | if transportErr != nil { |
| 53 | log.Fatal("Transport Error:", transportErr) |
| 54 | } |
| 55 | |
| 56 | client := &apns2.Client{ |
| 57 | HTTPClient: &http.Client{ |
| 58 | Transport: transport, |
| 59 | Timeout: apns2.HTTPClientTimeout, |
| 60 | }, |
| 61 | Certificate: certificate, |
| 62 | Host: apns2.DefaultHost, |
| 63 | } |
| 64 | |
| 65 | notification := &apns2.Notification{} |
| 66 | notification.DeviceToken = *token |
| 67 | notification.Topic = *topic |
| 68 | notification.Payload = []byte(`{ |
| 69 | "aps" : { |
| 70 | "alert" : "Hello!" |
| 71 | } |
| 72 | } |
| 73 | `) |
| 74 | |
| 75 | res, err := client.Push(notification) |
nothing calls this directly
no test coverage detected