add userdata path to envconfig and expand example.env

This commit is contained in:
github-tijlxyz 2024-02-12 18:40:52 +01:00
parent ac6ae108e7
commit b6ebdb9e5b
No known key found for this signature in database
GPG Key ID: 2EB6AC84AFE26CD6
3 changed files with 19 additions and 8 deletions

View File

@ -1,5 +1,17 @@
RELAY_NAME="Name of the Relay"
RELAY_DESCRIPTION="Description of the relay"
RELAY_PUBKEY="07adfda9c5adc80881bb2a5220f6e3181e0c043b90fa115c4f183464022968e6"
RELAY_CONTACT="email@example.com"
# Server Settings
DOMAIN="example.com"
PORT="3334" # optional
DATABASE_PATH="./db" # optional
USERDATA_PATH="./users.json" # optional
# Hierarchy Settings
MAX_INVITES_PER_PERSON="3" # optional
# Relay Settings
RELAY_NAME="Name of the Relay"
RELAY_PUBKEY="07adfda9c5adc80881bb2a5220f6e3181e0c043b90fa115c4f183464022968e6"
RELAY_DESCRIPTION="Description of the relay" # optional
RELAY_CONTACT="email@example.com" # optional
RELAY_ICON="https://example.com/icon.png" # optional

View File

@ -28,6 +28,7 @@ type Settings struct {
RelayContact string `envconfig:"RELAY_CONTACT"`
RelayIcon string `envconfig:"RELAY_ICON"`
DatabasePath string `envconfig:"DATABASE_PATH" default:"./db"`
UserdataPath string `envconfig:"USERDATA_PATH" default:"./users.json"`
MaxInvitesPerPerson int `envconfig:"MAX_INVITES_PER_PERSON" default:"3"`
}

View File

@ -8,8 +8,6 @@ import (
"github.com/nbd-wtf/go-nostr"
)
const WHITELIST_FILE = "users.json"
type Whitelist map[string]string // { [user_pubkey]: [invited_by] }
func addToWhitelist(pubkey string, inviter string) error {
@ -89,7 +87,7 @@ func removeDescendantsFromWhitelist(ancestor string) {
}
func loadWhitelist() error {
b, err := os.ReadFile(WHITELIST_FILE)
b, err := os.ReadFile(s.UserdataPath)
if err != nil {
return err
}
@ -107,7 +105,7 @@ func saveWhitelist() error {
return err
}
if err := os.WriteFile(WHITELIST_FILE, jsonBytes, 0644); err != nil {
if err := os.WriteFile(s.UserdataPath, jsonBytes, 0644); err != nil {
return err
}