Add ToURL

This commit is contained in:
andrewheberle 2019-06-24 09:57:59 +08:00 committed by GitHub
parent c01685bb84
commit ad844c2f56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

11
cast.go
View File

@ -6,7 +6,10 @@
// Package cast provides easy and safe casting in Go.
package cast
import "time"
import (
"net/url"
"time"
)
// ToBool casts an interface to a bool type.
func ToBool(i interface{}) bool {
@ -20,6 +23,12 @@ func ToTime(i interface{}) time.Time {
return v
}
// ToURL casts an interface to a *url.URL type.
func ToURL(i interface{}) *url.URL {
v, _ := ToURLE(i)
return v
}
// ToDuration casts an interface to a time.Duration type.
func ToDuration(i interface{}) time.Duration {
v, _ := ToDurationE(i)