Documentation
¶
Overview ¶
Package local 管理同一用户、同一运行目录下的长期驻留服务。 客户端和控制通道均不依赖 CGO。
Index ¶
- Constants
- Variables
- func EnsureLocal(ctx context.Context, config Config) (connection *client.Client, returnErr error)
- func Run(ctx context.Context, config Config, build func() (Application, error), ...) (returnErr error)
- func Stop(ctx context.Context, config Config) (returnErr error)
- type Application
- type Config
- type Health
Constants ¶
const DefaultListenAddress = "127.0.0.1:8999"
DefaultListenAddress 指定本机渲染服务的默认回环地址。
const TokenEnvironment = "HTMLRENDER_TOKEN"
TokenEnvironment 指定 CLI 与子进程读取渲染凭据的环境变量名。
Variables ¶
var ErrAlreadyRunning = errors.New("htmlrender instance is already running")
ErrAlreadyRunning 表示同一运行目录的实例锁已被其他服务持有。
Functions ¶
func EnsureLocal ¶
EnsureLocal 只在服务不存在时启动 Binary;已有实例的设置由服务持有。
Types ¶
type Application ¶
type Application struct {
Handler http.Handler
Close func() error
Status func() map[htmlrender.EngineName]htmlrender.EngineStatus
}
Application 将渲染 Handler、状态与关闭动作交给实例运行器持有。
type Config ¶
type Config struct {
RuntimeDirectory string `json:"runtime_dir"`
Listen string `json:"listen"`
DefaultEngine htmlrender.EngineName `json:"default_engine"`
Concurrency int `json:"concurrency"`
ChromiumExecutable string `json:"chrome_path,omitempty"`
Binary string `json:"-"` // 启动新实例的程序,省略时从 PATH 查找 h2i。
Token string `json:"-"` // 仅传给客户端和子进程环境,健康响应省略。
}
Config 指定实例运行位置与引擎设置;Token 只进入请求及子进程环境。
type Health ¶
type Health struct {
Version string `json:"version"`
InstanceID string `json:"instance_id"`
ProcessID int `json:"pid"`
Endpoint string `json:"endpoint"`
Config Config `json:"config"`
Engines map[htmlrender.EngineName]htmlrender.EngineStatus `json:"engines"`
Error string `json:"error,omitempty"`
}
Health 描述当前实例的身份、公开地址和引擎状态。