web

package
v0.0.0-...-fe2a775 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package web 提供 HuffZip 的 Web 界面服务

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(addr string) error

ListenAndServe 启动 Web 服务器

Types

type FileStore

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

FileStore 内存临时文件存储,带 TTL 自动清理

func NewFileStore

func NewFileStore(ttl time.Duration) *FileStore

NewFileStore 创建文件存储,启动后台清理协程

func (*FileStore) Get

func (fs *FileStore) Get(id string) *StoredFile

Get 获取文件,不存在或已过期返回 nil

func (*FileStore) Save

func (fs *FileStore) Save(name string, data []byte) string

Save 存储文件,返回唯一 ID

type Handler

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

Handler Web 请求处理器

func NewHandler

func NewHandler(tmpl *template.Template, store *FileStore) *Handler

NewHandler 创建处理器

func (*Handler) HandleCompress

func (h *Handler) HandleCompress(w http.ResponseWriter, r *http.Request)

HandleCompress 处理压缩请求,返回 HTML 片段

func (*Handler) HandleDecompress

func (h *Handler) HandleDecompress(w http.ResponseWriter, r *http.Request)

HandleDecompress 处理解压请求,返回 HTML 片段

func (*Handler) HandleDownload

func (h *Handler) HandleDownload(w http.ResponseWriter, r *http.Request)

HandleDownload 处理文件下载

func (*Handler) HandleHome

func (h *Handler) HandleHome(w http.ResponseWriter, r *http.Request)

HandleHome 渲染首页(完整页面)

type StoredFile

type StoredFile struct {
	Name      string    // 文件名
	Data      []byte    // 文件内容
	CreatedAt time.Time // 创建时间
}

StoredFile 临时存储的文件

Jump to

Keyboard shortcuts

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