app

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 52 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package app 装配配置、日志、账号、请求账本与 HTTP 服务并管理其生命周期

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminURL

func AdminURL(address string) string

AdminURL 返回监听地址对应的本机管理页地址,通配地址换成 127.0.0.1

func LoadConfig

func LoadConfig(args []string) (config.Config, bool, error)

LoadConfig 读取 .env 与启动参数,同时返回启动后是否打开管理页

func Main

func Main(args []string) error

Main 分派首次配置、版本查询与默认服务

func NewRouter

func NewRouter(deps Deps) *gin.Engine

NewRouter 注册就绪检查与全部兼容 API

func ParseFlags

func ParseFlags(args []string, cfg *config.Config) (bool, error)

ParseFlags 用命令行参数覆盖最常用的启动配置,返回是否打开管理页,不带参数启动时默认打开

func Version

func Version() string

Version 返回发行构建写入的版本号,未写入时返回模块版本与提交

Types

type Deps

type Deps struct {
	Pool     *balancer.AccountPool
	Store    *requestdb.Store
	Accounts *accounts.Manager
	// APIKey 返回当前生效的公开 API key,多个 key 以逗号分隔
	APIKey func() string
	// Admin 为管理端组件,nil 时不注册 /api
	Admin *admin.Deps
}

Deps 是路由使用的运行期组件

type Instance

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

Instance 是已取得实例锁并占用端口、尚未开始服务的进程

func Start

func Start(cfg config.Config, logWriter io.Writer, desktop bool) (*Instance, error)

Start 配置日志与日志文件,取得数据目录的实例锁并监听端口,logWriter 为 nil 时写标准错误

func (*Instance) Address added in v0.1.7

func (instance *Instance) Address() string

Address 返回实际监听地址

func (*Instance) Serve

func (instance *Instance) Serve(ctx context.Context) error

Serve 运行服务直到 ctx 结束,停机后释放端口与实例锁

Jump to

Keyboard shortcuts

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