-
Notifications
You must be signed in to change notification settings - Fork 0
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
add-marshal-unmarshal-text-param-for-common-date #164
base: main
Are you sure you want to change the base?
Conversation
- add marshal and unmarshal text to be able to use in query params - minor refactor in context.go - added tests
- added UnmarshalParam to support query param gin-gonic/gin#3933
@@ -33,7 +34,7 @@ func GetString(ctx context.Context, key ContextKey) (value string) { | |||
func GetBasic(ctx context.Context, key string) (value interface{}) { | |||
if ctx != nil { | |||
if basics, ok := ctx.Value(ctxBasics).(Basics); ok { | |||
value, _ = basics[key] | |||
value = basics[key] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -90,7 +91,7 @@ func SetExtras(parent context.Context, extras Extras) context.Context { | |||
func GetExtra(ctx context.Context, key string) (value interface{}) { | |||
if ctx != nil { | |||
if extras, ok := ctx.Value(ctxExtras).(Extras); ok { | |||
value, _ = extras[key] | |||
value = extras[key] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (d *Date) UnmarshalText(text []byte) (err error) { | ||
s := strings.Trim(string(text), `"`) | ||
parsedTime, err := time.Parse(layout, s) | ||
*d = Date(parsedTime) | ||
return | ||
} | ||
|
||
// MarshalText marshall Date into Text | ||
func (d Date) MarshalText() ([]byte, error) { | ||
return []byte(d.quote()), nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if these are useful in the future as it is not used by gin
gin-gonic/gin#3933
} | ||
|
||
// UnmarshalParam Parses the form's value to the Date | ||
func (d *Date) UnmarshalParam(param string) (err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to implement their BindUnmarshaler
interface
gin-gonic/gin#3933
feat(binding): Support custom BindUnmarshaler for binding. gin-gonic/gin#3933
We need to upgrade our gin version from
1.9.1
to1.10.0
, but there are a lot of changes. We can defer this change for now.