Skip to content

Commit

Permalink
helper: change to interface url query getter
Browse files Browse the repository at this point in the history
  • Loading branch information
agungdwiprasetyo committed Jan 19, 2023
1 parent 7cf06bd commit 50a8403
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 15 deletions.
6 changes: 3 additions & 3 deletions candihelper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

// ParseFromQueryParam parse url query string to struct target (with multiple data type in struct field), target must in pointer
func ParseFromQueryParam(query url.Values, target interface{}) (err error) {
func ParseFromQueryParam(query URLQueryGetter, target interface{}) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("%v", r)
Expand Down Expand Up @@ -62,8 +62,8 @@ func ParseFromQueryParam(query url.Values, target interface{}) (err error) {
}

var v string
if val := query[key]; len(val) > 0 && val[0] != "" {
v = val[0]
if val := query.Get(key); val != "" {
v = val
} else {
v = typ.Tag.Get("default")
}
Expand Down
17 changes: 17 additions & 0 deletions candihelper/interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package candihelper

// URLQueryGetter abstraction
type URLQueryGetter interface {
Get(key string) string
}

// MultiError abstract interface
type MultiError interface {
Append(key string, err error) MultiError
HasError() bool
IsNil() bool
Clear()
ToMap() map[string]string
Merge(MultiError) MultiError
Error() string
}
11 changes: 0 additions & 11 deletions candihelper/multierror.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ import (
)

type (
// MultiError abstract interface
MultiError interface {
Append(key string, err error) MultiError
HasError() bool
IsNil() bool
Clear()
ToMap() map[string]string
Merge(MultiError) MultiError
Error() string
}

multiError struct {
lock sync.Mutex
errs map[string]string
Expand Down
2 changes: 1 addition & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package candi

const (
// Version of this library
Version = "v1.13.13"
Version = "v1.13.14"
)
39 changes: 39 additions & 0 deletions mocks/candihelper/URLQueryGetter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 50a8403

Please sign in to comment.