MCPcopy Create free account
hub / github.com/GoSimplicity/LinkMe / stringToNullTimeHookFunc

Function stringToNullTimeHookFunc

internal/domain/events/es/process_util.go:197–214  ·  view source on GitHub ↗

stringToNullTimeHookFunc 转换字符串到 NullTime 类型

(layout string)

Source from the content-addressed store, hash-verified

195
196// stringToNullTimeHookFunc 转换字符串到 NullTime 类型
197func stringToNullTimeHookFunc(layout string) mapstructure.DecodeHookFunc {
198 return func(f reflect.Kind, t reflect.Kind, data interface{}) (interface{}, error) {
199 if f != reflect.String || t != reflect.Struct {
200 return data, nil
201 }
202
203 str := data.(string)
204 if str == "" {
205 return sql.NullTime{Valid: false}, nil
206 }
207
208 parsedTime, err := time.Parse(layout, str)
209 if err != nil {
210 return nil, err
211 }
212 return sql.NullTime{Time: parsedTime, Valid: true}, nil
213 }
214}

Callers 2

decodeEventDataToPostFunction · 0.85
decodeEventDataToUserFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected