onesvm-browser-server/server/internal/gateway/util.go
chii eb972dfa93 feat: 落地 browser-server 控制面并打通 mgr1 海外订阅
单二进制三角色 + Dock 适配器 + Swarm stack 达到可部署态;mgr1 实测订阅经 central-proxy bootstrap,探活 alive=41/52。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-02 15:05:12 +08:00

36 lines
820 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// util.go:管线结果类型与工具函数。
package gateway
import (
"encoding/json"
"strconv"
"strings"
)
// jsonUnmarshal 解码辅助。
func jsonUnmarshal(b []byte, v any) error { return json.Unmarshal(b, v) }
// itoa int→string。
func itoa(n int) string { return strconv.Itoa(n) }
// itoa64 int64→string。
func itoa64(n int64) string { return strconv.FormatInt(n, 10) }
// errMsg 错误消息提取(nil 安全)。
func errMsg(err error) string {
if err == nil {
return "未知错误"
}
return strings.TrimSpace(err.Error())
}
// isOKEnvelope 判断信封字节是否为 ok=true(缓存写入仅成功结果)。
func isOKEnvelope(raw []byte) bool {
var probe struct {
OK bool `json:"ok"`
}
if err := jsonUnmarshal(raw, &probe); err != nil {
return false
}
return probe.OK
}