Skip to content

Commit

Permalink
auto create users.json if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
github-tijlxyz committed Feb 28, 2024
1 parent 7e6a3f0 commit 415cf46
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"errors"
"fmt"
"os"

Expand Down Expand Up @@ -89,7 +90,20 @@ func removeDescendantsFromWhitelist(ancestor string) {
func loadWhitelist() error {
b, err := os.ReadFile(s.UserdataPath)
if err != nil {
return err
// If the whitelist file does not exist, with RELAY_PUBKEY
if errors.Is(err, os.ErrNotExist) {
whitelist[s.RelayPubkey] = ""
jsonBytes, err := json.Marshal(&whitelist)
if err != nil {
return err
}
if err := os.WriteFile(s.UserdataPath, jsonBytes, 0644); err != nil {
return err
}
return nil
} else {
return err
}
}

if err := json.Unmarshal(b, &whitelist); err != nil {
Expand Down

0 comments on commit 415cf46

Please sign in to comment.