Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix/bugfix #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
helays merged 13 commits into master from fix/bugfix
Jun 26, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
13 commits
Select commit Hold shift + click to select a range
2c787c4
补充redis 方法。
May 28, 2026
ea2e17f
Bool 新增PTR
May 28, 2026
5bd1153
CustomTime 新增UnmarshalParam
Jun 1, 2026
16b4d22
refactor: 简化 CustomDate/CustomTime 的 Scan 方法
Jun 2, 2026
01233d5
fix: 优化 dateObjectFormat 中 Any2string 调用时机
Jun 2, 2026
9eed0b8
refactor: 将 JSONMap 从 map 类型别名改为 struct
Jun 3, 2026
96c6534
feat: 添加 GenericStringHasher 和 JSONMap 构造函数
Jun 9, 2026
e671705
feat: 添加 ToStrings 泛型函数
Jun 16, 2026
1d8b588
feat: JSONMap 添加 ToMap 方法返回内部 map
Jun 17, 2026
33a7cdf
feat: 为 Byte 类型添加类型转换方法
Jun 17, 2026
72e28d5
feat: EmailSender 添加 EnableExternalTo 字段和 Clone 方法
Jun 18, 2026
89a1bde
chore: 升级 go.mod 依赖版本
Jun 26, 2026
ef78367
feat: 适配 go-redis v9.21.0 新接口
Jun 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dataType/bool.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,7 @@ func (b *Bool) GobDecode(data []byte) error {
b.bool = data[0] != 0
return nil
}

func (b Bool) ToPtr() *Bool {
return &b
}
52 changes: 42 additions & 10 deletions dataType/date.go
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dataType

import (
"database/sql"
"database/sql/driver"
"strings"
"time"
Expand All @@ -13,6 +12,16 @@ import (
"helay.net/go/utils/v3/tools"
)

var timeFormat = formatter.FormatRule[time.Time]{
FormatType: "output_date",
InputRules: []string{
"timestamp",
"2006年01月02日",
"2006年01月02日 15",
"2006年01月02日 15:04",
},
}

type CustomDate struct {
time.Time
}
Expand All @@ -23,10 +32,15 @@ func (c CustomDate) String() string {
}

// noinspection all
func (c *CustomDate) Scan(value interface{}) (err error) {
nullTime := &sql.NullTime{}
err = nullTime.Scan(value)
c.Time = nullTime.Time
func (c *CustomDate) Scan(value any) (err error) {
if value == nil {
return nil
}
t, err := timeFormat.Format(value)
if err != nil {
return err
}
c.Time = t
return
}

Expand Down Expand Up @@ -70,8 +84,7 @@ func (c *CustomDate) UnmarshalJSON(b []byte) (err error) {
//*this = CustomTime{}
return nil
}
tf := formatter.FormatRule[time.Time]{FormatType: "output_date"}
_t, err := tf.Format(s)
_t, err := timeFormat.Format(s)
if err != nil {
return err
}
Expand All @@ -98,9 +111,14 @@ func (c CustomTime) String() string {

// noinspection all
func (c *CustomTime) Scan(value interface{}) (err error) {
nullTime := &sql.NullTime{}
err = nullTime.Scan(value)
c.Time = nullTime.Time
if value == nil {
return nil
}
t, err := timeFormat.Format(value)
if err != nil {
return err
}
c.Time = t
return
}

Expand Down Expand Up @@ -155,6 +173,20 @@ func (c *CustomTime) UnmarshalJSON(b []byte) (err error) {
return err
}

// UnmarshalParam 从 query string 参数解析
func (c *CustomTime) UnmarshalParam(param string) error {
if param == "" {
return nil
}
tf := formatter.FormatRule[time.Time]{FormatType: "output_date"}
_t, err := tf.Format(param)
if err != nil {
return err
}
c.Time = _t
return nil
}

// noinspection all
func (c CustomTime) ToPtr() *CustomTime {
return &c
Expand Down
36 changes: 36 additions & 0 deletions dataType/int.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,42 @@ func (Byte) GormDBDataType(db *gorm.DB, field *schema.Field) string {
return "int"
}

func (b Byte) ToInt() int {
return int(b)
}

func (b Byte) ToInt64() int64 {
return int64(b)
}

func (b Byte) ToUint64() uint64 {
return uint64(b)
}

func (b Byte) ToFloat64() float64 {
return float64(b)
}

func (b Byte) ToString() string {
return fmt.Sprintf("%d", b)
}

func (b Byte) ToBool() bool {
return b != 0
}

func (b Byte) ToInt32() int32 {
return int32(b)
}

func (b Byte) ToInt16() int16 {
return int16(b)
}

func (b Byte) ToByte() byte {
return byte(b)
}

type Uint64 struct {
uint64
}
Expand Down
80 changes: 48 additions & 32 deletions dataType/json_map.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"database/sql/driver"
"encoding/json"
"errors"

"gorm.io/gorm"
"gorm.io/gorm/clause"
Expand All @@ -13,48 +14,36 @@ import (

// JSONMap defined JSON data type, need to implements driver.Valuer, sql.Scanner interface
// noinspection all
type JSONMap map[string]any
type JSONMap struct {
data map[string]any
}

func NewJSONMap(data map[string]any) JSONMap {
return JSONMap{data: data}
}

// Value return json value, implement driver.Valuer interface
// noinspection all
func (m JSONMap) Value() (driver.Value, error) {
return DriverValueWithJson(m)
return DriverValueWithJson(m.data)
}

// Scan scan value into Jsonb, implements sql.Scanner interface
// noinspection all
func (m *JSONMap) Scan(val any) error {
return DriverScanWithJson(val, m) // 这里暂时先用这个版本
//if val == nil {
// *m = make(JSONMap)
// return nil
//}
//var ba []byte
//switch v := val.(type) {
//case []byte:
// ba = v
//case string:
// ba = []byte(v)
//default:
// return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", val))
//}
//t := map[string]any{}
//rd := bytes.NewReader(ba)
//decoder := json.NewDecoder(rd)
//decoder.UseNumber()
//err := decoder.Decode(&t)
//*m = t
//return err
if m == nil {
return errors.New("JSONMap is nil")
}
return DriverScanWithJson(val, &m.data) // 这里暂时先用这个版本
}

// MarshalJSON to output non base64 encoded []byte
// noinspection all
func (m JSONMap) MarshalJSON() ([]byte, error) {
if m == nil {
if m.data == nil {
return []byte("null"), nil
}
t := (map[string]any)(m)
return json.Marshal(t)
return json.Marshal(m.data)
}

// UnmarshalJSON to deserialize []byte
Expand All @@ -64,10 +53,7 @@ func (m *JSONMap) UnmarshalJSON(b []byte) error {
rd := bytes.NewReader(b)
decoder := json.NewDecoder(rd)
decoder.UseNumber()
t := map[string]any{}
err := decoder.Decode(&t)
*m = t
return err
return decoder.Decode(&m.data)
}

// GormDataType gorm common data type
Expand All @@ -83,7 +69,37 @@ func (JSONMap) GormDBDataType(db *gorm.DB, field *schema.Field) string {
}

// noinspection all
func (jm JSONMap) GormValue(_ context.Context, db *gorm.DB) clause.Expr {
data, _ := jm.MarshalJSON()
func (m JSONMap) GormValue(_ context.Context, db *gorm.DB) clause.Expr {
data, _ := m.MarshalJSON()
return MapGormValue(string(data), db)
}

func (m *JSONMap) Add(k string, v any) {
if m == nil {
return
}
if m.data == nil {
m.data = make(map[string]any)
}
m.data[k] = v
}

func (m *JSONMap) Get(k string) (any, bool) {
if m == nil || m.data == nil {
return nil, false
}
v, ok := m.data[k]
return v, ok
}

func (m *JSONMap) Remove(k string) {
if m == nil || m.data == nil {
return
}

delete(m.data, k)
}

func (m *JSONMap) ToMap() map[string]any {
return m.data
}
Loading
Loading

AltStyle によって変換されたページ (->オリジナル) /