local

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 18 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 local 管理同一用户、同一运行目录下的长期驻留服务。 客户端和控制通道均不依赖 CGO。

Index

Constants

View Source
const DefaultListenAddress = "127.0.0.1:8999"

DefaultListenAddress 指定本机渲染服务的默认回环地址。

View Source
const TokenEnvironment = "HTMLRENDER_TOKEN"

TokenEnvironment 指定 CLI 与子进程读取渲染凭据的环境变量名。

Variables

View Source
var ErrAlreadyRunning = errors.New("htmlrender instance is already running")

ErrAlreadyRunning 表示同一运行目录的实例锁已被其他服务持有。

Functions

func EnsureLocal

func EnsureLocal(ctx context.Context, config Config) (connection *client.Client, returnErr error)

EnsureLocal 只在服务不存在时启动 Binary;已有实例的设置由服务持有。

func Run

func Run(ctx context.Context, config Config, build func() (Application, error), ready io.Writer) (returnErr error)

Run 在获得实例锁后才创建引擎。ready 供启动助手接收确定的就绪结果。

func Stop

func Stop(ctx context.Context, config Config) (returnErr error)

Stop 仅通过当前用户的 Unix 控制通道关闭对应实例。

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 只进入请求及子进程环境。

func (Config) Defaults

func (c Config) Defaults() (Config, error)

Defaults 补齐本机实例设置,并将 RuntimeDirectory 解析为绝对路径。

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 描述当前实例的身份、公开地址和引擎状态。

func Status

func Status(ctx context.Context, config Config) (status Health, returnErr error)

Status 通过当前用户的私有控制 socket 读取实例快照。

Jump to

Keyboard shortcuts

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