config generation refactor cleanup

This commit is contained in:
0ceanSlim 2024-07-31 14:41:48 -04:00
parent 5eb6fd961e
commit ad42f1fc39
5 changed files with 9 additions and 8 deletions

View File

@ -2,8 +2,8 @@ package app
import ( import (
"context" "context"
"grain/relay/db" "grain/server/db"
relay "grain/relay/types" relay "grain/server/types"
"html/template" "html/template"
"net/http" "net/http"

View File

@ -7,6 +7,7 @@ import (
configTypes "grain/config/types" configTypes "grain/config/types"
relay "grain/server" relay "grain/server"
"grain/server/db" "grain/server/db"
"grain/server/nip"
"grain/server/utils" "grain/server/utils"
"log" "log"
@ -16,8 +17,8 @@ import (
) )
func main() { func main() {
utils.EnsureFileExists("config.yml", "config/config.example.yml") utils.EnsureFileExists("config.yml", "app/static/examples/config.example.yml")
utils.EnsureFileExists("app/relay_metadata.json", "app/relay_metadata.example.json") utils.EnsureFileExists("relay_metadata.json", "app/static/examples/relay_metadata.example.json")
cfg, err := config.LoadConfig("config.yml") cfg, err := config.LoadConfig("config.yml")
if err != nil { if err != nil {
@ -33,7 +34,7 @@ func main() {
config.SetupRateLimiter(cfg) config.SetupRateLimiter(cfg)
config.SetupSizeLimiter(cfg) config.SetupSizeLimiter(cfg)
err = app.LoadRelayMetadataJSON() err = nip.LoadRelayMetadataJSON()
if err != nil { if err != nil {
log.Fatal("Failed to load relay metadata: ", err) log.Fatal("Failed to load relay metadata: ", err)
} }
@ -67,7 +68,7 @@ func ListenAndServe(w http.ResponseWriter, r *http.Request) {
relay.WebSocketHandler(ws) relay.WebSocketHandler(ws)
}).ServeHTTP(w, r) }).ServeHTTP(w, r)
} else if r.Header.Get("Accept") == "application/nostr+json" { } else if r.Header.Get("Accept") == "application/nostr+json" {
app.RelayInfoHandler(w, r) nip.RelayInfoHandler(w, r)
} else { } else {
app.RootHandler(w, r) app.RootHandler(w, r)
} }

View File

@ -1,4 +1,4 @@
package app package nip
import ( import (
"encoding/json" "encoding/json"
@ -19,7 +19,7 @@ type RelayMetadata struct {
var relayMetadata RelayMetadata var relayMetadata RelayMetadata
func LoadRelayMetadataJSON() error { func LoadRelayMetadataJSON() error {
return LoadRelayMetadata("app/relay_metadata.json") return LoadRelayMetadata("relay_metadata.json")
} }
func LoadRelayMetadata(filename string) error { func LoadRelayMetadata(filename string) error {