Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aaron-wego
Copy link
Contributor

We need to upgrade our gin version from 1.9.1 to 1.10.0, but there are a lot of changes. We can defer this change for now.

- 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]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@@ -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]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Comment on lines +28 to +38
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
}
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant