api

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package api implements the HTTP API server for xray-subscription management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

Server is the HTTP API server holding shared dependencies.

func NewServer

func NewServer(cfg *config.Config, db *database.DB, syncer Syncer) *Server

NewServer creates a new Server with the given config, database, and syncer.

func (*Server) ReconcileKillSwitchLoop added in v0.1.6

func (s *Server) ReconcileKillSwitchLoop(ctx context.Context, interval time.Duration)

ReconcileKillSwitchLoop periodically re-applies the persisted killswitch state to the Xray runtime. This catches the drift caused by an xray restart (Ansible `--tags xray_inbounds`, manual `systemctl restart xray`, package upgrade, …) reloading `/etc/xray/config.d/220-in-fallback.json` from disk while the killswitch is OFF in the DB — without this loop, raven-subscribe would not notice and the fallback inbound would silently start listening again.

The loop is a no-op when XrayAPIAddr is empty or FallbackInboundTags is unset (the same guards as applyKillSwitchInboundsLocked). interval <= 0 disables the loop entirely.

reconcileKillSwitchLocked is idempotent — repeated "remove" calls treat "not found" as benign — so the cadence trades latency-to-detect-drift for gRPC churn.

func (*Server) ReconcileKillSwitchOnStartup added in v0.1.6

func (s *Server) ReconcileKillSwitchOnStartup()

ReconcileKillSwitchOnStartup applies the current persisted killswitch state to the Xray runtime via gRPC. Intended to be called once after server initialization, before the HTTP listener is up. When disabled, removes fallback inbounds from Xray (they may have been loaded from /etc/xray/config.d/ on Xray's own startup); when enabled, no-op (Xray already has them).

func (*Server) Router

func (s *Server) Router() http.Handler

Router builds and returns the configured HTTP router.

type Syncer

type Syncer interface {
	Sync() error
	Status() syncer.SyncStatus
}

Syncer is the subset of *syncer.Syncer the api package needs. We import the syncer package only for the SyncStatus type, which lets the health endpoint forward state without redefining a parallel struct.

Jump to

Keyboard shortcuts

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