public

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 31 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 public 是给网页播放器用的公开只读 HTTP 适配器(/player/v1)。

与 internal/server 平行:不要求访问令牌,所以只暴露白名单里的歌单与歌曲, 播放链接带 HMAC 签名并会过期,按来源 IP 限流,可选用服务账号(部署者自己的网易云账号)取 VIP 播放链接。 与 CLI 一样直连 engine + endpoint,不经 gRPC service。协议与部署见 docs/player.md。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Login

func Login(ctx context.Context, eng *engine.Engine, path string, out io.Writer) error

Login 走网易云扫码登录,把服务账号的登录态写到 path。二维码与进度输出到 out。 二维码过期会自动换新的;ctx 结束(例如 Ctrl-C)时返回 ctx 的错误。

func WriteSessionFile

func WriteSessionFile(path string, f SessionFile) error

WriteSessionFile 原子地写入登录态文件(先写临时文件再改名),权限 0600。

Types

type Options

type Options struct {
	// Addr 是监听地址。
	Addr string
	// Playlists 是允许公开的歌单 ID。
	Playlists []int64
	// Songs 是允许单独公开的歌曲 ID。
	Songs []int64
	// Origins 是允许跨域调用的站点;AnyOrigin 为 true 时不限。
	Origins []string
	// AnyOrigin 表示 Origins 里出现了 *。
	AnyOrigin bool
	// SessionFile 是服务账号登录态文件路径,空表示只按匿名播放。
	SessionFile string
	// SigningKey 是播放链接签名密钥。
	SigningKey []byte
	// RatePerMinute 是每个来源 IP 每分钟允许的请求数。
	RatePerMinute int
	// TrustProxy 为 true 时按 X-Forwarded-For 取来源 IP。
	TrustProxy bool
	// Level 是播放音质上限。
	Level mmpb.SongLevel
	// LinkTTL 是播放链接签名的有效期。
	LinkTTL time.Duration
}

Options 是公开模式的运行参数,由 ParseOptions 从 config.PublicConfig 解析。

func ParseOptions

func ParseOptions(c config.PublicConfig) (Options, error)

ParseOptions 校验并解析公开模式配置。任何一项不合法都返回错误,调用方应拒绝启动: 公开模式不鉴权,配置含糊时宁可起不来,也不暴露超出预期的内容。

type Server

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

Server 是公开模式的 HTTP 服务。

func New

func New(eng *engine.Engine, opts Options) *Server

New 创建公开模式服务。eng 与 gRPC 服务共用同一个引擎(熔断、重试状态一致)。

func (*Server) Addr

func (s *Server) Addr() string

Addr 返回实际监听地址(Addr 写 :0 时用于测试)。

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler 返回完整的 HTTP 处理链:跨域 → 限流 → 路由。

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown 停止续期并排空连接。

func (*Server) Start

func (s *Server) Start() error

Start 开始监听;登录态续期在后台运行,直到 Shutdown。

type SessionFile

type SessionFile struct {
	Cookie    string    `json:"cookie"`
	UserID    int64     `json:"userId"`
	Nickname  string    `json:"nickname"`
	UpdatedAt time.Time `json:"updatedAt"`
}

SessionFile 是服务账号网易云登录态文件的内容(server public-login 写入,运行中续期时改写)。

func ReadSessionFile

func ReadSessionFile(path string) (SessionFile, error)

ReadSessionFile 读取登录态文件。

Jump to

Keyboard shortcuts

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