Add ToURLE function
This commit is contained in:
parent
ad844c2f56
commit
ff7c360a3e
15
caste.go
15
caste.go
@ -10,6 +10,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -70,6 +71,20 @@ func ToDurationE(i interface{}) (d time.Duration, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToURLE casts an interface to a *url.URL type.
|
||||||
|
func ToURLE(i interface{}) (u *url.URL, err error) {
|
||||||
|
i = indirect(i)
|
||||||
|
|
||||||
|
switch v := i.(type) {
|
||||||
|
case url.URL:
|
||||||
|
return &v, nil
|
||||||
|
case string:
|
||||||
|
return url.Parse(v)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unable to cast %#v of type %T to URL", i, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ToBoolE casts an interface to a bool type.
|
// ToBoolE casts an interface to a bool type.
|
||||||
func ToBoolE(i interface{}) (bool, error) {
|
func ToBoolE(i interface{}) (bool, error) {
|
||||||
i = indirect(i)
|
i = indirect(i)
|
||||||
|
Loading…
Reference in New Issue
Block a user