优化表结构,重构模型,重新实现基于白银网关的提取节点流程
This commit is contained in:
32
web/globals/orm/inet.go
Normal file
32
web/globals/orm/inet.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package orm
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"net/netip"
|
||||
)
|
||||
|
||||
type Inet struct {
|
||||
netip.Addr
|
||||
}
|
||||
|
||||
func (inet Inet) Value() (driver.Value, error) {
|
||||
return inet.MarshalBinary()
|
||||
}
|
||||
|
||||
func (inet *Inet) Scan(value any) (err error) {
|
||||
switch value := value.(type) {
|
||||
case []byte:
|
||||
return inet.UnmarshalBinary(value)
|
||||
default:
|
||||
return fmt.Errorf("不支持的类型: %T", value)
|
||||
}
|
||||
}
|
||||
|
||||
func ParseInet(ip string) (*Inet, error) {
|
||||
addr, err := netip.ParseAddr(ip)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Inet{addr}, nil
|
||||
}
|
||||
@@ -20,8 +20,7 @@ var formats = []string{
|
||||
"2006-01-02",
|
||||
}
|
||||
|
||||
//goland:noinspection GoMixedReceiverTypes
|
||||
func (ldt *LocalDateTime) Scan(value interface{}) (err error) {
|
||||
func (ldt *LocalDateTime) Scan(value any) (err error) {
|
||||
var t time.Time
|
||||
if strValue, ok := value.(string); ok {
|
||||
var timeValue time.Time
|
||||
@@ -50,35 +49,26 @@ func (ldt *LocalDateTime) Scan(value interface{}) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
//goland:noinspection GoMixedReceiverTypes
|
||||
func (ldt LocalDateTime) Value() (driver.Value, error) {
|
||||
return time.Time(ldt).Local(), nil
|
||||
}
|
||||
|
||||
// GormDataType gorm common data type
|
||||
//
|
||||
//goland:noinspection GoMixedReceiverTy
|
||||
//goland:noinspection GoMixedReceiverTypes
|
||||
func (ldt LocalDateTime) GormDataType() string {
|
||||
return "ldt"
|
||||
}
|
||||
|
||||
//goland:noinspection GoMixedReceiverTypes
|
||||
func (ldt LocalDateTime) GobEncode() ([]byte, error) {
|
||||
return time.Time(ldt).GobEncode()
|
||||
}
|
||||
|
||||
//goland:noinspection GoMixedReceiverTypes
|
||||
func (ldt *LocalDateTime) GobDecode(b []byte) error {
|
||||
return (*time.Time)(ldt).GobDecode(b)
|
||||
}
|
||||
|
||||
//goland:noinspection GoMixedReceiverTypes
|
||||
func (ldt LocalDateTime) MarshalJSON() ([]byte, error) {
|
||||
return time.Time(ldt).MarshalJSON()
|
||||
}
|
||||
|
||||
//goland:noinspection GoMixedReceiverTypes
|
||||
func (ldt *LocalDateTime) UnmarshalJSON(b []byte) error {
|
||||
return (*time.Time)(ldt).UnmarshalJSON(b)
|
||||
}
|
||||
|
||||
24
web/globals/orm/slice.go
Normal file
24
web/globals/orm/slice.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package orm
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Slice[T any] struct {
|
||||
Arr []T
|
||||
}
|
||||
|
||||
func (s Slice[T]) Value() (driver.Value, error) {
|
||||
return json.Marshal(s)
|
||||
}
|
||||
|
||||
func (s *Slice[T]) Scan(value any) error {
|
||||
switch value := value.(type) {
|
||||
case []byte:
|
||||
return json.Unmarshal(value, s)
|
||||
default:
|
||||
return fmt.Errorf("不支持的类型: %T", value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user