put vapid keygen behind a flag
This commit is contained in:
3
.idea/runConfigurations/Generate_VAPID.xml
generated
3
.idea/runConfigurations/Generate_VAPID.xml
generated
@@ -2,7 +2,8 @@
|
|||||||
<configuration default="false" name="Generate VAPID" type="GoApplicationRunConfiguration" factoryName="Go Application">
|
<configuration default="false" name="Generate VAPID" type="GoApplicationRunConfiguration" factoryName="Go Application">
|
||||||
<module name="7am" />
|
<module name="7am" />
|
||||||
<working_directory value="$PROJECT_DIR$" />
|
<working_directory value="$PROJECT_DIR$" />
|
||||||
<kind value="FILE" />
|
<parameters value="--generate-vapid-keys" />
|
||||||
|
<kind value="PACKAGE" />
|
||||||
<package value="code.nym.sh/7am" />
|
<package value="code.nym.sh/7am" />
|
||||||
<directory value="$PROJECT_DIR$" />
|
<directory value="$PROJECT_DIR$" />
|
||||||
<filePath value="$PROJECT_DIR$/generate_vapid.go" />
|
<filePath value="$PROJECT_DIR$/generate_vapid.go" />
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<component name="ProjectRunConfigurationManager">
|
<component name="ProjectRunConfigurationManager">
|
||||||
<configuration default="false" name="go build code.nym.sh/7am" type="GoApplicationRunConfiguration" factoryName="Go Application" nameIsGenerated="true">
|
<configuration default="false" name="Start server on 8080" type="GoApplicationRunConfiguration" factoryName="Go Application">
|
||||||
<module name="7am" />
|
<module name="7am" />
|
||||||
<working_directory value="$PROJECT_DIR$" />
|
<working_directory value="$PROJECT_DIR$" />
|
||||||
<kind value="FILE" />
|
<kind value="FILE" />
|
@@ -1,30 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/SherClockHolmes/webpush-go"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
pub, priv, err := webpush.GenerateVAPIDKeys()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := os.OpenFile("vapid_public_key", os.O_CREATE|os.O_WRONLY, 0644)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
f.Write([]byte(pub))
|
|
||||||
|
|
||||||
f, err = os.OpenFile("vapid_private_key", os.O_CREATE|os.O_WRONLY, 0644)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
f.Write([]byte(priv))
|
|
||||||
}
|
|
19
main.go
19
main.go
@@ -102,6 +102,14 @@ var supportedLocations = map[string]location{
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
port := flag.Int("port", 8080, "the port that the server should listen on")
|
port := flag.Int("port", 8080, "the port that the server should listen on")
|
||||||
|
genKeys := flag.Bool("generate-vapid-keys", false, "generate a new vapid key pair, which will be outputted to stdout.")
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if *genKeys {
|
||||||
|
generateKeys()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
err := godotenv.Load()
|
err := godotenv.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -201,6 +209,17 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateKeys() {
|
||||||
|
priv, pub, err := webpush.GenerateVAPIDKeys()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("all keys are base64 url encoded.")
|
||||||
|
fmt.Printf("public key: %v\n", pub)
|
||||||
|
fmt.Printf("private key: %v\n", priv)
|
||||||
|
}
|
||||||
|
|
||||||
func handleHTTPRequest(state *state) http.HandlerFunc {
|
func handleHTTPRequest(state *state) http.HandlerFunc {
|
||||||
return func(writer http.ResponseWriter, request *http.Request) {
|
return func(writer http.ResponseWriter, request *http.Request) {
|
||||||
path := strings.TrimPrefix(request.URL.Path, "/")
|
path := strings.TrimPrefix(request.URL.Path, "/")
|
||||||
|
Reference in New Issue
Block a user