Skip to content
This repository has been archived by the owner on Jan 7, 2021. It is now read-only.

lryong/golang-pushnotifications-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

golang-push-notifications-demo

This is a Demo for cross browsers push notifications, implemented message push using webpush-go

1. Generate VAPID Keys

There are many ways to generate a pair of VAPID keys. You can use GenerateVAPIDKeys() providing from webpush-go to create a private and public VAPID key pair:

package main

import (
	"fmt"

	"github.com/SherClockHolmes/webpush-go"
)

func main() {
	vapidPrivateKey, vapidPublicKey, err := webpush.GenerateVAPIDKeys()
	if err != nil {
		fmt.Println("Generate VAPID Keys error: ", err)
		return
	}
	fmt.Println("vapid_private_key: ", vapidPrivateKey)
	fmt.Println("vapid_public_key: ", vapidPublicKey)
}

2. Access index.html

Replace the public VAPID key in index.js.

Use a tool such as SimpleHTTPServer to run a web server:

python -m SimpleHTTPServer 8000

Go to http://localhost:8000 and copy the logged subsciption from the console.

3. Test sending a notification

Replace the public/private VAPID keys and detail subscription info. Use the subscription you had from the first section.

go run main.go

About

Demo for cross browsers push notifications

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published