subscription

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package subscription turns a user's hosts into client-ready connection links.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64

func Base64(b Bundle) string

Base64 renders the classic base64 subscription payload understood by nearly every client.

func Clash

func Clash(b Bundle) string

Clash renders a Mihomo/Clash.Meta profile. It is emitted as YAML by hand because the document is small, fixed in shape, and hand-writing it avoids a YAML dependency in the panel.

func Headers

func Headers(b Bundle) map[string]string

Headers are the subscription-userinfo style metadata clients read to display quota and expiry without opening the panel.

func Links(b Bundle) []string

Links renders one connection URI per enabled host.

func Render

func Render(b Bundle, f Format) string

Render produces the payload for a format.

func SingBox

func SingBox(b Bundle) string

SingBox renders a sing-box client configuration with a selector and a urltest group over every host.

Types

type Bundle

type Bundle struct {
	User  *domain.User
	Hosts []domain.Host
	// Title is shown as the profile name in client apps.
	Title      string
	SupportURL string
	// UpdateInterval is how often clients should refresh, in hours.
	UpdateInterval int
}

Bundle is everything a subscription response is built from.

type Format

type Format string

Format is a subscription encoding a client understands.

const (
	FormatBase64  Format = "base64"
	FormatPlain   Format = "plain"
	FormatClash   Format = "clash"
	FormatSingBox Format = "singbox"
	FormatJSON    Format = "json"
)

func DetectFormat

func DetectFormat(userAgent string) Format

DetectFormat picks an encoding from the client's User-Agent. Clients that announce themselves get their native format; everything else falls back to the base64 list, which is universally understood.

func (Format) ContentType

func (f Format) ContentType() string

ContentType is what the response should be served as.

func (Format) Valid

func (f Format) Valid() bool

type Info

type Info struct {
	Username        string     `json:"username"`
	Status          string     `json:"status"`
	UsedBytes       int64      `json:"usedTrafficBytes"`
	LimitBytes      int64      `json:"trafficLimitBytes"`
	LifetimeBytes   int64      `json:"lifetimeUsedTrafficBytes"`
	ExpireAt        *time.Time `json:"expireAt"`
	SubscriptionURL string     `json:"subscriptionUrl"`
	Links           []string   `json:"links"`
	Title           string     `json:"title"`
	SupportURL      string     `json:"supportUrl,omitempty"`
	DaysLeft        *int       `json:"daysLeft,omitempty"`
}

Info is the JSON payload the subscription page renders.

func BuildInfo

func BuildInfo(b Bundle, subURL string) Info

Jump to

Keyboard shortcuts

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