server

package
v2.2.5 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package server provides rest-like api and serves static assets as well

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHashedIP

func GetHashedIP(r *http.Request) string

GetHashedIP retrieves hashed IP from context

func HashedIP

func HashedIP(secret string) func(http.Handler) http.Handler

HashedIP middleware adds anonymized IP to request context for audit logging. Must run after rest.RealIP middleware which sets r.RemoteAddr to the client IP.

func Logger

func Logger(l log.L) func(http.Handler) http.Handler

Logger middleware with security masking for sensitive paths and IP anonymization. Must run after HashedIP middleware which sets hashed IP in context.

func RequireHTMX added in v2.1.0

func RequireHTMX(next http.Handler) http.Handler

RequireHTMX middleware rejects requests without HX-Request header. Used for web form routes that require client-side JavaScript encryption.

func SecurityHeaders added in v2.1.0

func SecurityHeaders(protocol string) func(http.Handler) http.Handler

SecurityHeaders adds security headers to all responses. Disable with --proxy-security-headers when running behind a proxy that sets these.

func SendErrorJSON added in v2.1.0

func SendErrorJSON(w http.ResponseWriter, r *http.Request, l log.L, code int, err error, msg string)

SendErrorJSON sends error response and logs with hashed IP (privacy-safe alternative to rest.SendErrorJSON)

func StripSlashes

func StripSlashes(next http.Handler) http.Handler

StripSlashes removes trailing slashes from URLs

func Timeout

func Timeout(timeout time.Duration) func(http.Handler) http.Handler

Timeout creates a timeout middleware

Types

type Config

type Config struct {
	Domain   []string // allowed domains list
	WebRoot  string
	Protocol string
	Branding string
	Listen   string // server listen address (ip:port or :port), defaults to :8080
	SignKey  string // sign key (will be hashed before use for IP anonymization)

	// validation parameters
	PinSize        int
	MaxPinAttempts int
	MaxExpire      time.Duration

	// file upload settings
	EnableFiles bool
	MaxFileSize int64 // bytes, 0 means use default (1MB)

	// authentication (optional)
	AuthHash   string        // bcrypt hash of password, empty disables auth
	SessionTTL time.Duration // session lifetime, defaults to 168h (7 days)

	EmailEnabled           bool // email sharing (optional)
	AllowNoPin             bool // allow creating secrets without PIN protection
	DisableSecurityHeaders bool // skip security headers when proxy handles them
}

Config is a configuration for the server

type EmailSender

type EmailSender interface {
	Send(ctx context.Context, req email.Request) error
	GetDefaultFromName() string
}

EmailSender defines the interface for sending emails (consumer-side interface)

type Messager

type Messager interface {
	MakeMessage(ctx context.Context, req messager.MsgReq) (result *store.Message, err error)
	MakeFileMessage(ctx context.Context, req messager.FileRequest) (result *store.Message, err error)
	LoadMessage(ctx context.Context, key, pin string) (msg *store.Message, err error)
	IsFile(ctx context.Context, key string) bool          // checks if message is a file without decrypting
	HasPin(ctx context.Context, key string) (bool, error) // checks if message requires PIN
}

Messager interface making and loading messages

type Server

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

Server is a rest with store

func New

func New(m Messager, version string, cfg Config) (Server, error)

New creates a new server with template cache

func (Server) Run

func (s Server) Run(ctx context.Context) error

Run the lister and request's router, activate rest server

func (Server) WithEmail

func (s Server) WithEmail(sender EmailSender) Server

WithEmail sets the email sender for the server

Directories

Path Synopsis
Package assets provides embedded static files and templates
Package assets provides embedded static files and templates
Package validator provides functionality for validating and sanitizing data.
Package validator provides functionality for validating and sanitizing data.

Jump to

Keyboard shortcuts

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