Categorygithub.com/bergusman/apnsmock-go
modulepackage
0.1.0
Repository: https://github.com/bergusman/apnsmock-go.git
Documentation: pkg.go.dev

# README

APNs Mock Server

Server example:

key, err := mock.AuthKeyFromFile("AuthKey_XXXXXXXXXX.p8")
if err != nil {
	log.Fatal(err)
}

handler := &mock.Handler{}
handler.TokenPublicKey = func(keyID, teamID string) *ecdsa.PublicKey {
	if keyID == "XXXXXXXXXX" && teamID == "XXXXXXXXXX" {
		return &key.PublicKey
	}
	return nil
}
handler.DeviceToken = func(token string) *mock.DeviceToken {
	if token == "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" {
		return &mock.DeviceToken{
			Token:        token,
			Topic:        "com.example.app",
			Unregistered: 1625475525573,
		}
	}
	return &mock.DeviceToken{
		Token: token,
		Topic: "com.example.app",
	}
}
handler.Push = func(push *mock.Push) {
	fmt.Println(push.Status, push.Reason)
}

http.ListenAndServe(":80", handler)

Client example with apns-go:

key, err := apns.AuthKeyFromFile("AuthKey_XXXXXXXXXX.p8")
if err != nil {
	log.Fatal(err)
}

token := apns.NewToken(key, "XXXXXXXXXX", "XXXXXXXXXX")
client := apns.NewClient(token, nil)

n := &apns.Notification{
	DeviceToken: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
	Host:        "http://localhost",
	Topic:       "com.example.app",
	Payload: apns.BuildPayload(&apns.APS{
		Alert: "Hi",
	}, nil),
}

fmt.Println(client.Push(n))

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author