profile

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package profile parses vmess://, vless://, trojan://, ss:// share links into Server profiles, and persists the saved server list as JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSubscriptionURL

func IsSubscriptionURL(input string) bool

IsSubscriptionURL reports whether input looks like a subscription URL (http/https) rather than a single vmess/vless/trojan/ss share link.

func ShareLink(s Server) (string, error)

ShareLink turns a saved server back into a standard share link, so it can be copied into another client (or another Kite) and parsed by ParseLink.

Types

type Server

type Server struct {
	ID       string            `json:"id"`
	Name     string            `json:"name"`
	Protocol string            `json:"protocol"` // vmess, vless, trojan, shadowsocks
	Address  string            `json:"address"`
	Port     int               `json:"port"`
	UUID     string            `json:"uuid,omitempty"`     // vmess/vless
	Password string            `json:"password,omitempty"` // trojan/ss
	Method   string            `json:"method,omitempty"`   // ss cipher
	Extra    map[string]string `json:"extra,omitempty"`    // network, tls, sni, path, etc.
}

Server is one saved proxy profile, storage- and UI-agnostic.

func ParseLink(link string) (Server, error)

ParseLink dispatches to the right parser based on the URI scheme.

func ParseSubscription

func ParseSubscription(body string) ([]Server, []string, []error)

ParseSubscription parses the body of a subscription URL, which is conventionally either:

  • a base64-encoded blob that decodes to a newline-separated list of share links (the near-universal "subscription" format used by V2RayN/V2RayNG/Shadowrocket/Clash-compatible clients), or
  • a plain newline-separated list of share links, uncompressed.

Lines that fail to parse are skipped rather than failing the whole subscription, since a subscription commonly mixes supported and unsupported (e.g. ss2022, vmess with unusual fields) entries. Many providers also throw in a few non-functional "info" entries disguised as real links -- e.g. a vless:// whose host is literally "dontUseThis" -- just to surface plan/expiry/traffic details inside clients that list every node. Those are recognized by isInfoNode and dropped rather than imported as dead servers.

type Store

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

Store persists the server list as a single JSON file under the user's config directory. Sqlite is deferred until v1 needs querying beyond a flat list.

func NewStore

func NewStore() *Store

func (*Store) Add

func (s *Store) Add(server Server) (Server, error)

Add persists a new server, assigning it an ID if it doesn't already have one, and returns the stored copy (with that ID set) so the caller can hand back something actually usable by Get/Connect -- the server passed in is a value, so its own ID field is never visible to the caller otherwise.

func (*Store) Delete

func (s *Store) Delete(id string) error

func (*Store) Get

func (s *Store) Get(id string) (Server, error)

func (*Store) List

func (s *Store) List() ([]Server, error)

func (*Store) ReplaceWhere

func (s *Store) ReplaceWhere(drop func(Server) bool, added []Server) ([]Server, error)

ReplaceWhere removes every stored server matching drop, appends added (assigning IDs), and writes the file once -- so importing or refreshing a subscription with hundreds of servers isn't hundreds of full rewrites.

func (*Store) Update

func (s *Store) Update(server Server) error

Update replaces the server with the same ID, preserving its position.

func (*Store) UpdateWhere

func (s *Store) UpdateWhere(match func(Server) bool, fn func(*Server)) (int, error)

UpdateWhere applies fn to every stored server matching match, in place, and writes the file once. Returns how many servers matched.

type SubscriptionUsage

type SubscriptionUsage struct {
	UploadBytes   int64 `json:"uploadBytes"`
	DownloadBytes int64 `json:"downloadBytes"`
	TotalBytes    int64 `json:"totalBytes"`
	ExpireUnix    int64 `json:"expireUnix"` // 0 if not reported
}

SubscriptionUsage is traffic/expiry info a subscription provider can report via the (informal but widely adopted) "Subscription-Userinfo" response header, e.g.:

Subscription-Userinfo: upload=123; download=456; total=10737418240; expire=1780000000

func ParseSubscriptionUserinfo

func ParseSubscriptionUserinfo(header string) (SubscriptionUsage, bool)

ParseSubscriptionUserinfo parses a Subscription-Userinfo header value. Returns false if the header was empty or carried none of the known fields.

Jump to

Keyboard shortcuts

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