utils

package
v0.3.331-nightly Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

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

Global registry instance

Functions

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, backupCount int)

StartPeriodicLogTrimmer starts a goroutine that periodically checks and manages log size

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, backupCount 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