Skip to content

Commit

Permalink
deprecate panicking functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ludusrusso committed Apr 28, 2022
1 parent e010bf4 commit 393336f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
6 changes: 6 additions & 0 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ func (obj *Object) GetInt64(attr string) (int64, error) {
}

// MustGetInt64 is like GetInt64, but it panic in case of error.
// Deprecated: use GetInt64 instead
func (obj *Object) MustGetInt64(attr string) int64 {
result, err := obj.GetInt64(attr)
if err != nil {
Expand All @@ -255,6 +256,7 @@ func (obj *Object) GetFloat64(attr string) (float64, error) {
}

// MustGetFloat64 is like GetFloat64, but it panic in case of error.
// Deprecated: use GetFloat64 instead
func (obj *Object) MustGetFloat64(attr string) float64 {
result, err := obj.GetFloat64(attr)
if err != nil {
Expand All @@ -278,6 +280,7 @@ func (obj *Object) GetString(attr string) (s string, err error) {
}

// MustGetString is like GetString, but it panic in case of error.
// Deprecated: use GetString instead
func (obj *Object) MustGetString(attr string) string {
result, err := obj.GetString(attr)
if err != nil {
Expand All @@ -302,6 +305,7 @@ func (obj *Object) GetTime(attr string) (t time.Time, err error) {
}

// MustGetTime is like GetTime, but it panic in case of error.
// Deprecated: use GetTime instead
func (obj *Object) MustGetTime(attr string) time.Time {
result, err := obj.GetTime(attr)
if err != nil {
Expand All @@ -325,6 +329,7 @@ func (obj *Object) GetBool(attr string) (b bool, err error) {
}

// MustGetBool is like GetTime, but it panic in case of error.
// Deprecated: use GetBool instead
func (obj *Object) MustGetBool(attr string) bool {
result, err := obj.GetBool(attr)
if err != nil {
Expand Down Expand Up @@ -358,6 +363,7 @@ func (obj *Object) GetStringSlice(attr string) (s []string, err error) {
}

// MustGetStringSlice is like GetStringSlice, but it panic in case of error.
// Deprecated: use GetStringSlice instead
func (obj *Object) MustGetStringSlice(attr string) []string {
result, err := obj.GetStringSlice(attr)
if err != nil {
Expand Down
22 changes: 17 additions & 5 deletions vt.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,32 @@ func (e Error) Error() string {
return e.Message
}

// URL returns a full VirusTotal API URL from a relative path (i.e: a path
// NewURL returns a full VirusTotal API URL from a relative path (i.e: a path
// without the domain name and the "/api/v3/" prefix). The path can contain
// format 'verbs' as defined in the "fmt". This function is useful for creating
// URLs to be passed to any function expecting a *url.URL in this library.
func URL(pathFmt string, a ...interface{}) *url.URL {
func NewURL(pathFmt string, a ...interface{}) (*url.URL, error) {
path := fmt.Sprintf(pathFmt, a...)
url, err := url.Parse(path)
if err != nil {
msg := fmt.Sprintf(
return nil, fmt.Errorf(
"error formatting URL \"%s\": %s",
pathFmt, err)
panic(msg)
}
return baseURL.ResolveReference(url)
return baseURL.ResolveReference(url), nil
}

// URL returns a full VirusTotal API URL from a relative path (i.e: a path
// without the domain name and the "/api/v3/" prefix). The path can contain
// format 'verbs' as defined in the "fmt". This function is useful for creating
// URLs to be passed to any function expecting a *url.URL in this library.
// Deprecated: use NewURL instead
func URL(pathFmt string, a ...interface{}) *url.URL {
url, err := NewURL(pathFmt, a...)
if err != nil {
panic(err.Error())
}
return url
}

// SetHost allows to change the host used while sending requests to the
Expand Down

0 comments on commit 393336f

Please sign in to comment.