singbox

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package singbox renders sing-box server configurations.

It earns its place beside xray and hysteria for two reasons. One binary serves TUIC, Hysteria2, VLESS, VMess, Trojan and Shadowsocks, so a protocol added here costs a renderer rather than another process on every node. And unlike hysteria it ships an offline validator — `sing-box check` — which means a document can be refused while the operator is still looking at it, instead of on a node at restart time.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoInbounds = errors.New("a sing-box config needs at least one inbound")
	ErrBadConfig  = errors.New("invalid sing-box config")
)

Functions

func Render

func Render(profile json.RawMessage, opts RenderOptions) ([]byte, string, error)

Render writes the users into each inbound in the shape its type expects, and returns the bytes a node runs plus their hash.

func Starter

func Starter(domain string) json.RawMessage

Starter is a working TUIC + Hysteria2 document to edit rather than write from nothing, in the same spirit as the VLESS + REALITY starter.

func Validate

func Validate(config json.RawMessage) error

Types

type Inbound

type Inbound struct {
	Tag  string `json:"tag"`
	Type string `json:"type"`
	Port int    `json:"port"`
}

Inbound is the part of an inbound the panel needs to know about: enough to let a squad grant it and a host publish it.

func ParseInbounds

func ParseInbounds(config json.RawMessage) ([]Inbound, error)

ParseInbounds pulls out the inbounds a squad can grant.

type RenderOptions

type RenderOptions struct {
	// UsersByTag is who may use each inbound, keyed by inbound tag.
	UsersByTag map[string][]User
	// ActiveTags limits which inbounds this node serves. Empty means all.
	ActiveTags []string
}

type User

type User struct {
	// Name is what sing-box logs and counts traffic against. It carries the
	// uuid so a figure can be charged back even if a username is reused later.
	Name     string
	UUID     string
	Password string
	Flow     string
}

User is one subscriber. Which fields matter depends on the inbound type, so all of them travel and the renderer picks.

Jump to

Keyboard shortcuts

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