This commit is contained in:
hu xiaotong
2025-07-02 16:12:52 +08:00
commit 0246bc7060
48 changed files with 460639 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
package model
import (
"encoding/json"
"time"
)
// Equipment 装备模型
type Equipment struct {
ID string `json:"id" db:"id"`
Code string `json:"code" db:"code"`
Ct time.Time `json:"ct" db:"created_time"`
E int `json:"e" db:"experience"`
G int `json:"g" db:"grade"`
L bool `json:"l" db:"locked"`
Mg int `json:"mg" db:"magic"`
Op []Operation `json:"op" db:"operations"`
P int `json:"p" db:"power"`
S string `json:"s" db:"string_value"`
Sk int `json:"sk" db:"skill"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
// Operation 操作属性
type Operation struct {
Type string `json:"type"`
Value interface{} `json:"value"`
}
// MarshalJSON 自定义JSON序列化
func (e *Equipment) MarshalJSON() ([]byte, error) {
type Alias Equipment
return json.Marshal(&struct {
*Alias
Ct int64 `json:"ct"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}{
Alias: (*Alias)(e),
Ct: e.Ct.Unix(),
CreatedAt: e.CreatedAt.Unix(),
UpdatedAt: e.UpdatedAt.Unix(),
})
}
// UnmarshalJSON 自定义JSON反序列化
func (e *Equipment) UnmarshalJSON(data []byte) error {
type Alias Equipment
aux := &struct {
*Alias
Ct int64 `json:"ct"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}{
Alias: (*Alias)(e),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
e.Ct = time.Unix(aux.Ct, 0)
e.CreatedAt = time.Unix(aux.CreatedAt, 0)
e.UpdatedAt = time.Unix(aux.UpdatedAt, 0)
return nil
}

31
internal/model/packet.go Normal file
View File

@@ -0,0 +1,31 @@
package model
// TCPData TCP数据包模型
type TCPData struct {
Payload []byte
Seq uint32
Ack uint32
SrcPort uint16
DstPort uint16
}
// CaptureResult 抓包结果
type CaptureResult struct {
Data []Equipment `json:"data"`
Units []interface{} `json:"units"`
}
// NetworkInterface 网络接口信息
type NetworkInterface struct {
Name string `json:"name"`
Description string `json:"description"`
Addresses []string `json:"addresses"`
IsLoopback bool `json:"is_loopback"`
}
// CaptureStatus 抓包状态
type CaptureStatus struct {
IsCapturing bool `json:"is_capturing"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
}