store

package
v0.0.0-...-4a21aa2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCode

func GenerateCode() string

GenerateCode 生成随机权益码

Types

type AuditLog

type AuditLog struct {
	ID        int64     `json:"id"`
	UserID    int64     `json:"user_id"`
	Action    string    `json:"action"`
	IP        string    `json:"ip"`
	UserAgent string    `json:"user_agent"`
	Timestamp time.Time `json:"timestamp"`
}

type CreditCode

type CreditCode struct {
	Code         string     `json:"code"`
	Level        int        `json:"level"`
	DurationDays int        `json:"duration_days"`
	ExpireAt     time.Time  `json:"expire_at"`
	Status       string     `json:"status"` // unused, used, disabled
	UsedBy       int64      `json:"used_by"`
	UsedAt       *time.Time `json:"used_at"`
	CreatedAt    time.Time  `json:"created_at"`
}

type Node

type Node struct {
	ID           string    `json:"id"`
	Name         string    `json:"name"`
	Type         string    `json:"type"`
	Addr         string    `json:"addr"`
	Protocol     string    `json:"protocol"`
	Multiplier   float64   `json:"multiplier"`
	PortRange    string    `json:"port_range"`
	IsSelfHosted bool      `json:"is_self_hosted"`
	AgentID      string    `json:"agent_id"`
	CreatedAt    time.Time `json:"created_at"`
}

type PortAllocator

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

func NewPortAllocator

func NewPortAllocator(min, max int, s *Store) *PortAllocator

func (*PortAllocator) Allocate

func (a *PortAllocator) Allocate() (int, error)

Allocate 分配一个可用端口

type Rule

type Rule struct {
	ID          string    `json:"id"`
	UserID      int64     `json:"user_id"`
	Name        string    `json:"name"`
	Mode        string    `json:"mode"`
	EntryNodeID string    `json:"entry_node_id"`
	ExitNodeID  string    `json:"exit_node_id"`
	HopChain    []string  `json:"hop_chain"` // 中继节点 ID 序列
	Status      string    `json:"status"`
	SyncState   string    `json:"sync_state"`
	CreatedAt   time.Time `json:"created_at"`
}

type Store

type Store struct {
	Sqlite *sql.DB
	Bolt   *bbolt.DB
}

func NewStore

func NewStore(dataDir string) (*Store, error)

func (*Store) AddNode

func (s *Store) AddNode(n *Node) error

func (*Store) Close

func (s *Store) Close()

func (*Store) CreateCreditCodes

func (s *Store) CreateCreditCodes(level, days int, count int, expireAt time.Time) ([]string, error)

func (*Store) CreateUser

func (s *Store) CreateUser(u *User, password string) error

func (*Store) GetUserByUsername

func (s *Store) GetUserByUsername(username string) (*User, error)

func (*Store) ListAuditLogs

func (s *Store) ListAuditLogs(limit, offset int) ([]AuditLog, error)

func (*Store) ListNodes

func (s *Store) ListNodes() ([]Node, error)

func (*Store) ListRulesByUser

func (s *Store) ListRulesByUser(userID int64) ([]Rule, error)

func (*Store) LogAction

func (s *Store) LogAction(userID int64, action, ip, ua string)

func (*Store) ProcessBilling

func (s *Store) ProcessBilling(userID int64, nodeID string, bytes int64) (int64, error)

ProcessBilling 执行流量扣费

func (*Store) RedeemCode

func (s *Store) RedeemCode(userID int64, code string) error

RedeemCode 执行权益码兑换 (原子操作)

func (*Store) UpdateRuleStatus

func (s *Store) UpdateRuleStatus(id string, status string) error

func (*Store) UpdateUserStatus

func (s *Store) UpdateUserStatus(id int64, status string) error

type User

type User struct {
	ID           int64      `json:"id"`
	Username     string     `json:"username"`
	Email        string     `json:"email"`
	PasswordHash string     `json:"-"`
	Role         string     `json:"role"`
	Permissions  []string   `json:"permissions"`
	Status       string     `json:"status"`
	TGID         int64      `json:"tg_id"`
	TGUsername   string     `json:"tg_username"`
	VIPLevel     int        `json:"vip_level"`
	QuotaUsed    int64      `json:"quota_used"`
	QuotaTotal   int64      `json:"quota_total"`
	ExpireAt     *time.Time `json:"expire_at"`
	CreatedAt    time.Time  `json:"created_at"`
}

Jump to

Keyboard shortcuts

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