Files
orly/main.go
mleku 5c129e078e Refactor server interface, add public-readable support, and update versioning
- **app/realy/handleWebsocket.go**:
  - Modified `Server` struct initialization to use `server.I` instead of `server.S`.

- **protocol/socketapi/handleEvent.go**:
  - Updated `HandleEvent` method to accept `server.I` for improved interface consistency.

- **app/realy/server-impl.go**:
  - Added the `PublicReadable` method to the `Server` struct.
  - Replaced `server.S` references with `server.I` to align with updated interface.

- **protocol/relayinfo/types.go**:
  - Fixed typo in error message from "realy" to "relay".

- **protocol/socketapi/handleMessage.go**:
  - Replaced `server.S` references with `server.I` in event handling methods.

- **protocol/socketapi/handleClose.go**:
  - Updated `HandleClose` method to use `server.I`.

- **protocol/socketapi/handleReq.go**:
  - Updated `HandleReq` method signature to accept `server.I`.

- **app/realy/server.go**:
  - Introduced `publicReadable` field in the `Server` struct.
  - Updated `NewServer` to handle `PublicReadable` parameter from `ServerParams`.

- **protocol/socketapi/socketapi.go**:
  - Changed `server.S` to `server.I` across the WebSocket logic for consistency.

- **version/version**:
  - Downgraded version file from `v1.14.3` to `v0.1.1`.

- **version/version.go**:
  - Corrected `URL` constant from `https://orly` to `https://orly.dev`.

- **interfaces/server/server.go**:
  - Renamed interface `S` to `I`.
  - Added `PublicReadable` to the renamed `I` interface.

- **main.go**:
  - Introduced logging of `PublicReadable` support when starting the server.
  - Updated imports and initialization to align with added features.

- **app/config/config.go**:
  - Added `PublicReadable` flag in configuration struct and environment settings.

- **protocol/socketapi/pinger.go**:
  - Modified `Pinger` method to use `server.I`.

- **protocol/socketapi/handleAuth.go**:
  - Adjusted `HandleAuth` logic to utilize `server.I`.

- **app/resources.go**:
  - Introduced a new initialization flow reflecting updated server settings.
2025-07-16 14:15:06 +01:00

82 lines
2.0 KiB
Go

// Package main is a nostr relay with a simple follow/mute list authentication
// scheme and the new HTTP REST based protocol. Configuration is via environment
// variables or an optional .env file.
package main
import (
"fmt"
"github.com/pkg/profile"
"net/http"
_ "net/http/pprof"
"orly.dev/app/realy"
"orly.dev/app/realy/options"
"orly.dev/utils/chk"
"orly.dev/utils/interrupt"
"orly.dev/utils/log"
"orly.dev/version"
"os"
"orly.dev/app"
"orly.dev/app/config"
"orly.dev/database"
"orly.dev/utils/context"
"orly.dev/utils/lol"
)
func main() {
var err error
var cfg *config.C
if cfg, err = config.New(); chk.T(err) {
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err)
}
config.PrintHelp(cfg, os.Stderr)
os.Exit(0)
}
log.I.F("starting %s %s", cfg.AppName, version.V)
if config.GetEnv() {
config.PrintEnv(cfg, os.Stdout)
os.Exit(0)
}
if config.HelpRequested() {
config.PrintHelp(cfg, os.Stderr)
os.Exit(0)
}
log.I.Ln("log level", cfg.LogLevel)
lol.SetLogLevel(cfg.LogLevel)
if cfg.Pprof {
defer profile.Start(profile.MemProfile).Stop()
go func() {
chk.E(http.ListenAndServe("127.0.0.1:6060", nil))
}()
}
c, cancel := context.Cancel(context.Bg())
storage, err := database.New(c, cancel, cfg.DataDir, cfg.DbLogLevel)
if chk.E(err) {
os.Exit(1)
}
r := &app.Relay{C: cfg, Store: storage}
go app.MonitorResources(c)
var server *realy.Server
serverParams := &realy.ServerParams{
Ctx: c,
Cancel: cancel,
Rl: r,
DbPath: cfg.DataDir,
MaxLimit: 512, // Default max limit for events
AuthRequired: cfg.AuthRequired,
PublicReadable: cfg.PublicReadable,
}
var opts []options.O
if server, err = realy.NewServer(serverParams, opts...); chk.E(err) {
os.Exit(1)
}
if err != nil {
log.F.F("failed to create server: %v", err)
}
interrupt.AddHandler(func() { server.Shutdown() })
if err = server.Start(cfg.Listen, cfg.Port); chk.E(err) {
log.F.F("server terminated: %v", err)
}
}