Help us shape the future of Go! Take the 2026 Go Developer Survey

singbox

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package singbox renders the sing-box source rule-set JSON document. It owns format only: target limits and policy decisions are supplied by the target definition and the planner. Unlike the Keenetic dialect this format is a declarative match set rather than a list of imperative route commands, and it carries domains and both address families instead of IPv4 routes alone.

Index

Constants

View Source
const (
	ID      = "singbox-ruleset-json"
	Version = "singbox-source-json-v1"
	// FormatVersion is the sing-box source rule-set schema version this
	// renderer emits and the only version its validator accepts.
	FormatVersion   = 3
	MaxEntries      = 8192
	MaxArtifactSize = 1 << 20
	ContentType     = "application/json"
	FileExtension   = "json"
)

Variables

This section is empty.

Functions

func ProjectedRuleCount

func ProjectedRuleCount(plan domain.RoutingPlan) (int, error)

ProjectedRuleCount counts the canonical match entries the document will carry. It is the number a target rule limit is compared against, so it must not count a duplicate twice.

func Render

func Render(plan domain.RoutingPlan) ([]byte, error)

Render projects already-decided rules into one canonical rule-set document.

func Validate

func Validate(payload []byte) error

Types

type Renderer

type Renderer struct{}

func (Renderer) Descriptor

func (Renderer) Descriptor() domain.RendererDescriptor

func (Renderer) ID

func (Renderer) ID() string

func (Renderer) ProjectedRuleCount

func (Renderer) ProjectedRuleCount(plan domain.RoutingPlan) (int, error)

func (Renderer) Render

func (Renderer) Render(plan domain.RoutingPlan) ([]byte, error)

func (Renderer) SupportedRuleKinds

func (Renderer) SupportedRuleKinds() []domain.RuleKind

SupportedRuleKinds is deliberately wider than the Keenetic dialect: the same plan therefore reaches this format with domain rules the router format has to drop.

func (Renderer) Validate

func (Renderer) Validate(payload []byte) error

func (Renderer) Version

func (Renderer) Version() string

type Rule

type Rule struct {
	Domain       []string
	DomainSuffix []string
	IPCIDR       []string
}

Rule is one sing-box headless rule. Only the match fields this renderer emits are modelled; an unknown field makes a document invalid rather than ignored.

type RuleSet

type RuleSet struct {
	Version int
	Rule    Rule
}

RuleSet is the independent validator's typed projection of the document.

func Parse

func Parse(payload []byte) (RuleSet, error)

Parse validates the document independently of Render and returns the typed projection. Canonical ordering and form are checked by rendering the projection again, exactly as the Keenetic validator does.

Jump to

Keyboard shortcuts

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