mirror of
https://github.com/0ceanSlim/grain.git
synced 2024-11-22 00:27:14 +00:00
config generation refactor cleanup
This commit is contained in:
parent
5eb6fd961e
commit
ad42f1fc39
@ -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"
|
||||||
|
|
||||||
|
9
main.go
9
main.go
@ -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)
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
Loading…
Reference in New Issue
Block a user