Keys
#struct KeysThe VAPID keys of the server.
| Name | Type | Description |
|---|---|---|
public_key | str = "" | The public key as url safe base64; this is what you give to applicationServerKey in the page JavaScript. |
private_key | str = "" | The private key; keep it secret. |
ok | bool = false | The keys are valid. |
import webpush
import str
func main:
fresh := webpush.GenerateKeys()
println fresh.ok, fresh.public_key.Len(), fresh.private_key.Len()
k := webpush.KeysFrom(
"BLmOwafYGSjiuCX_1RSCO_n0YmacxYMDqitMydKE4A1Wp2qmUuMXg2IM_hzcrmZLun4jEu_lKfVdtnAp0LMK4NE",
"Nhh4m4Va4yhL-53i302044iqeAeMtnOEYlIT2KWRJmg"
)
println k.ok, webpush.KeysFrom("", "").ok
at := webpush.VapidHeaderAt(
k, "https://fcm.googleapis.com", "mailto:ali@example.com", 1700000000
)
println at
now := webpush.VapidHeader(k, "https://fcm.googleapis.com", "mailto:ali@example.com")
println str.StartsWith(now, "vapid t="), str.Contains(now, ", k=" + k.public_key)
mut o := webpush.NewOptions("mailto:ali@example.com")
println o.subject, o.ttl == webpush.DEFAULT_TTL, o.ttl / 86400
o.urgency = "high"
o.topic = "news"
o.ttl = 3600
println o.urgency, o.topic, o.ttl
endtrue 87 43 true false vapid t=eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9.eyJhdWQiOiJodHRwczovL2ZjbS5nb29nbGVhcGlzLmNvbSIsImV4cCI6MTcwMDA0MzIwMCwic3ViIjoibWFpbHRvOmFsaUBleGFtcGxlLmNvbSJ9.8Sx-V8MK5NDw923EAMtv8NSCJzQMdhQx8E_ItZUuaMU_VVCv0NzyPG0vZ6JfRsu-S6h99PJJFB6_vgd3NGT_Lw, k=BLmOwafYGSjiuCX_1RSCO_n0YmacxYMDqitMydKE4A1Wp2qmUuMXg2IM_hzcrmZLun4jEu_lKfVdtnAp0LMK4NE true true mailto:ali@example.com true 28 high news 3600