utils

package
v0.3.3-nightly Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Conservative Note Size
	BufferMessageSizeLimit = 128000 // 128 KiloBytes
)

Constants based on your database analysis

Variables

View Source
var Registry = &LoggerRegistry{
	loggers: make(map[string]*slog.Logger),
}

Global registry instance

Functions

func AdjustEventTimeConstraints

func AdjustEventTimeConstraints(cfg *cfgTypes.ServerConfig)

AdjustEventTimeConstraints adjusts the event time constraints based on the configuration

func CalculateOptimalBufferSize

func CalculateOptimalBufferSize(cfg *configTypes.ServerConfig) int

CalculateOptimalBufferSize determines buffer size based on system resources

func DecodeNpub

func DecodeNpub(npub string) (string, error)

DecodeNpub decodes a Bech32 encoded npub to its corresponding pubkey

func DetermineEventCategory

func DetermineEventCategory(kind int) string

func EnsureFileExists

func EnsureFileExists(filePath, examplePath string)

func FetchPubkeysFromDomains

func FetchPubkeysFromDomains(domains []string) ([]string, error)

FetchPubkeysFromDomains fetches nostr.json pubkeys from multiple domains with caching.

func GetClientIP

func GetClientIP(r *http.Request) string

func GetLogger

func GetLogger(component string) *slog.Logger

The GetLogger function now simply delegates to the registry

func InitializeLoggers

func InitializeLoggers(cfg *cfgTypes.ServerConfig)

InitializeLoggers sets up the central logging system with the given configuration

func LoadRelayMetadata

func LoadRelayMetadata(filename string) error

func LoadRelayMetadataJSON

func LoadRelayMetadataJSON() error

func RelayInfoHandler

func RelayInfoHandler(w http.ResponseWriter, r *http.Request)

func SendToBackupRelay

func SendToBackupRelay(backupURL string, evt relay.Event) error

func SerializeEvent

func SerializeEvent(evt relay.Event) string

SerializeEvent manually constructs the JSON string for event serialization according to NIP-01

func StartPeriodicLogTrimmer

func StartPeriodicLogTrimmer(logFilePath string, maxSizeMB int, checkIntervalMinutes int)

PeriodicLogTrimmer starts a goroutine that periodically checks log size and trims if needed

func ToInt

func ToInt(i interface{}) *int

func ToInt64

func ToInt64(i interface{}) *int64

func ToIntArray

func ToIntArray(i interface{}) []int

func ToStringArray

func ToStringArray(i interface{}) []string

func ToTagsMap

func ToTagsMap(i interface{}) map[string][]string

func ToTime

func ToTime(data interface{}) *time.Time

Types

type CachedDomains

type CachedDomains struct {
	Timestamp int64               `json:"timestamp"` // Store Unix timestamp
	Domains   map[string][]string `json:"domains"`   // Cached pubkeys per domain
}

type JSONLogWriter

type JSONLogWriter struct {
	// contains filtered or unexported fields
}

JSONLogWriter writes logs in a pretty-printed JSON array format

func NewJSONLogWriter

func NewJSONLogWriter(filePath string, level slog.Level, maxSizeMB int) *JSONLogWriter

NewJSONLogWriter creates a new instance of JSONLogWriter

func (*JSONLogWriter) Close

func (j *JSONLogWriter) Close()

Close is now a no-op since logs are written properly on each entry.

func (*JSONLogWriter) Enabled

func (j *JSONLogWriter) Enabled(ctx context.Context, level slog.Level) bool

Required interface methods for slog.Handler

func (*JSONLogWriter) Handle

func (j *JSONLogWriter) Handle(ctx context.Context, r slog.Record) error

Handle writes logs in JSON format

func (*JSONLogWriter) WithAttrs

func (j *JSONLogWriter) WithAttrs(attrs []slog.Attr) slog.Handler

func (*JSONLogWriter) WithGroup

func (j *JSONLogWriter) WithGroup(name string) slog.Handler

type LoggerRegistry

type LoggerRegistry struct {
	// contains filtered or unexported fields
}

LoggerRegistry maintains a map of all loggers by component name

func (*LoggerRegistry) Get

func (r *LoggerRegistry) Get(component string) *slog.Logger

Get returns a logger for the specified component

type NostrJSON

type NostrJSON struct {
	Names map[string]string `json:"names"`
}

Domain types

type PrettyLogWriter

type PrettyLogWriter struct {
	// contains filtered or unexported fields
}

PrettyLogWriter writes logs ONLY to a file

func (*PrettyLogWriter) Enabled

func (h *PrettyLogWriter) Enabled(ctx context.Context, level slog.Level) bool

Required interface methods for slog.Handler

func (*PrettyLogWriter) Handle

func (h *PrettyLogWriter) Handle(ctx context.Context, r slog.Record) error

Handle writes logs to the log file

func (*PrettyLogWriter) WithAttrs

func (h *PrettyLogWriter) WithAttrs(attrs []slog.Attr) slog.Handler

func (*PrettyLogWriter) WithGroup

func (h *PrettyLogWriter) WithGroup(name string) slog.Handler

type RelayMetadata

type RelayMetadata struct {
	Name          string `json:"name"`
	Description   string `json:"description"`
	Pubkey        string `json:"pubkey"`
	Contact       string `json:"contact"`
	SupportedNIPs []int  `json:"supported_nips"`
	Software      string `json:"software"`
	Version       string `json:"version"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL