初步优化成全部go+wails

This commit is contained in:
yml2213
2026-06-24 19:11:02 +08:00
parent 86374fdd4d
commit 154e55d484
27 changed files with 2222 additions and 1798 deletions
+158
View File
@@ -0,0 +1,158 @@
package types
import (
"encoding/json"
"time"
)
// Config 应用配置。
type Config struct {
TimeAPIURL string `json:"timeApiUrl"`
}
// AppPaths 运行时路径。
type AppPaths struct {
ConfigFile string
AccountFile string
LogDir string
SuccessDir string
FontFiles []string
}
// TraceConfig 追踪配置。
type TraceConfig struct {
Enabled bool
MaxBodyBytes int
}
// Account 账号信息。
type Account struct {
Name string `json:"name"`
Password string `json:"password"`
Cookie string `json:"cookie"`
}
// Product 商品信息。
type Product struct {
CommodityID string `json:"commodityId"`
CommodityName string `json:"commodityName"`
Score int `json:"score"`
Count int `json:"count"`
Pic string `json:"pic"`
Status int `json:"status"`
OpenStatus int `json:"openStatus"`
StoreStatus int `json:"storeStatus"`
TimeLimited int `json:"timeLimited"`
CountLimited int `json:"countLimited"`
EliteLimited int `json:"eliteLimited"`
}
// ProductPayload 前端商品响应。
type ProductPayload struct {
Success bool `json:"success"`
Source string `json:"source"`
Products []Product `json:"products"`
Count int `json:"count"`
FetchedAt string `json:"fetchedAt"`
AgeSecond int `json:"ageSecond"`
Stale bool `json:"stale"`
}
// AccountView 前端账号视图。
type AccountView struct {
Index int `json:"index"`
Name string `json:"name"`
Cookie string `json:"cookie"`
}
// SeckillRequest 抢购请求。
type SeckillRequest struct {
AccountProducts map[string]string `json:"accountProducts"`
TargetTime string `json:"targetTime"`
Advance int `json:"advance"`
}
// APIResponse 斗鱼 API 通用响应。
type APIResponse struct {
Error int `json:"error"`
Msg string `json:"msg"`
Data json.RawMessage `json:"data"`
}
// LogEntry 日志条目。
type LogEntry struct {
ID int64 `json:"id"`
Time string `json:"time"`
Level string `json:"level"`
Category string `json:"category"`
Message string `json:"message"`
}
// ExchangeAttempt 兑换尝试。
type ExchangeAttempt struct {
Account Account
Product Product
Index int
}
// ExchangeResult 兑换结果。
type ExchangeResult struct {
OK bool
Account string
Product string
Attempt int
RoleName string
Message string
}
// TimeSample 时间采样。
type TimeSample struct {
ServerTime time.Time
LocalTime time.Time
RTT time.Duration
Offset time.Duration
ErrorBound time.Duration
RawCurrentTime int64
Samples int
Source string
Fallback bool
}
// EstimatedServerNow 根据采样偏移估算当前斗鱼时间。
func (t TimeSample) EstimatedServerNow() time.Time {
if t.LocalTime.IsZero() {
return t.ServerTime
}
return time.Now().Add(t.Offset).UTC()
}
// TimeCalibration 时间校准结果。
type TimeCalibration struct {
Offset time.Duration
ErrorBound time.Duration
RTT time.Duration
Samples int
CreatedAt time.Time
Source string
Fallback bool
}
// EstimatedServerNow 根据校准偏移估算当前斗鱼时间。
func (c TimeCalibration) EstimatedServerNow() time.Time {
if c.CreatedAt.IsZero() {
return time.Now().UTC()
}
return time.Now().Add(c.Offset).UTC()
}
// IsZero 判断校准结果是否为零值。
func (c TimeCalibration) IsZero() bool {
return c.CreatedAt.IsZero()
}
// WarmupData 预热数据。
type WarmupData struct {
CSRF string
RoleName string
CreatedAt time.Time
}