From ad42f1fc39ada8b50a810a6e4edf28885e97388a Mon Sep 17 00:00:00 2001 From: 0ceanSlim Date: Wed, 31 Jul 2024 14:41:48 -0400 Subject: [PATCH] config generation refactor cleanup --- app/app.go | 4 ++-- {config => app/static/examples}/config.example.yml | 0 app/{ => static/examples}/relay_metadata.example.json | 0 main.go | 9 +++++---- app/relay_metadata.go => server/nip/11RelayMetadata.go | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) rename {config => app/static/examples}/config.example.yml (100%) rename app/{ => static/examples}/relay_metadata.example.json (100%) rename app/relay_metadata.go => server/nip/11RelayMetadata.go (94%) diff --git a/app/app.go b/app/app.go index 228ca41..3a54b2c 100644 --- a/app/app.go +++ b/app/app.go @@ -2,8 +2,8 @@ package app import ( "context" - "grain/relay/db" - relay "grain/relay/types" + "grain/server/db" + relay "grain/server/types" "html/template" "net/http" diff --git a/config/config.example.yml b/app/static/examples/config.example.yml similarity index 100% rename from config/config.example.yml rename to app/static/examples/config.example.yml diff --git a/app/relay_metadata.example.json b/app/static/examples/relay_metadata.example.json similarity index 100% rename from app/relay_metadata.example.json rename to app/static/examples/relay_metadata.example.json diff --git a/main.go b/main.go index 461012b..be599df 100644 --- a/main.go +++ b/main.go @@ -7,6 +7,7 @@ import ( configTypes "grain/config/types" relay "grain/server" "grain/server/db" + "grain/server/nip" "grain/server/utils" "log" @@ -16,8 +17,8 @@ import ( ) func main() { - utils.EnsureFileExists("config.yml", "config/config.example.yml") - utils.EnsureFileExists("app/relay_metadata.json", "app/relay_metadata.example.json") + utils.EnsureFileExists("config.yml", "app/static/examples/config.example.yml") + utils.EnsureFileExists("relay_metadata.json", "app/static/examples/relay_metadata.example.json") cfg, err := config.LoadConfig("config.yml") if err != nil { @@ -33,7 +34,7 @@ func main() { config.SetupRateLimiter(cfg) config.SetupSizeLimiter(cfg) - err = app.LoadRelayMetadataJSON() + err = nip.LoadRelayMetadataJSON() if err != nil { log.Fatal("Failed to load relay metadata: ", err) } @@ -67,7 +68,7 @@ func ListenAndServe(w http.ResponseWriter, r *http.Request) { relay.WebSocketHandler(ws) }).ServeHTTP(w, r) } else if r.Header.Get("Accept") == "application/nostr+json" { - app.RelayInfoHandler(w, r) + nip.RelayInfoHandler(w, r) } else { app.RootHandler(w, r) } diff --git a/app/relay_metadata.go b/server/nip/11RelayMetadata.go similarity index 94% rename from app/relay_metadata.go rename to server/nip/11RelayMetadata.go index 1366dbd..925bec8 100644 --- a/app/relay_metadata.go +++ b/server/nip/11RelayMetadata.go @@ -1,4 +1,4 @@ -package app +package nip import ( "encoding/json" @@ -19,7 +19,7 @@ type RelayMetadata struct { var relayMetadata RelayMetadata func LoadRelayMetadataJSON() error { - return LoadRelayMetadata("app/relay_metadata.json") + return LoadRelayMetadata("relay_metadata.json") } func LoadRelayMetadata(filename string) error {