Skip to content

Commit 393336f

Browse files
committed
deprecate panicking functions
1 parent e010bf4 commit 393336f

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

object.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ func (obj *Object) GetInt64(attr string) (int64, error) {
232232
}
233233

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

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

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

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

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

360365
// MustGetStringSlice is like GetStringSlice, but it panic in case of error.
366+
// Deprecated: use GetStringSlice instead
361367
func (obj *Object) MustGetStringSlice(attr string) []string {
362368
result, err := obj.GetStringSlice(attr)
363369
if err != nil {

vt.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,32 @@ func (e Error) Error() string {
6464
return e.Message
6565
}
6666

67-
// URL returns a full VirusTotal API URL from a relative path (i.e: a path
67+
// NewURL returns a full VirusTotal API URL from a relative path (i.e: a path
6868
// without the domain name and the "/api/v3/" prefix). The path can contain
6969
// format 'verbs' as defined in the "fmt". This function is useful for creating
7070
// URLs to be passed to any function expecting a *url.URL in this library.
71-
func URL(pathFmt string, a ...interface{}) *url.URL {
71+
func NewURL(pathFmt string, a ...interface{}) (*url.URL, error) {
7272
path := fmt.Sprintf(pathFmt, a...)
7373
url, err := url.Parse(path)
7474
if err != nil {
75-
msg := fmt.Sprintf(
75+
return nil, fmt.Errorf(
7676
"error formatting URL \"%s\": %s",
7777
pathFmt, err)
78-
panic(msg)
7978
}
80-
return baseURL.ResolveReference(url)
79+
return baseURL.ResolveReference(url), nil
80+
}
81+
82+
// URL returns a full VirusTotal API URL from a relative path (i.e: a path
83+
// without the domain name and the "/api/v3/" prefix). The path can contain
84+
// format 'verbs' as defined in the "fmt". This function is useful for creating
85+
// URLs to be passed to any function expecting a *url.URL in this library.
86+
// Deprecated: use NewURL instead
87+
func URL(pathFmt string, a ...interface{}) *url.URL {
88+
url, err := NewURL(pathFmt, a...)
89+
if err != nil {
90+
panic(err.Error())
91+
}
92+
return url
8193
}
8294

8395
// SetHost allows to change the host used while sending requests to the

0 commit comments

Comments
 (0)