Skip to content

Commit

Permalink
Chore: return error as last argument
Browse files Browse the repository at this point in the history
Change the return arguments order of `getMD5Hash` function to follow Go's standard convention where error is the last return value.
  • Loading branch information
huiyifyj committed Jan 13, 2025
1 parent aa8f77c commit 8a6cda9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions gravatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Gravatar struct {
func (v *Verifier) CheckGravatar(email string) (*Gravatar, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
err, emailMd5 := getMD5Hash(strings.ToLower(strings.TrimSpace(email)))
emailMd5, err := getMD5Hash(strings.ToLower(strings.TrimSpace(email)))
if err != nil {
return nil, err
}
Expand All @@ -41,7 +41,7 @@ func (v *Verifier) CheckGravatar(email string) (*Gravatar, error) {
return nil, err
}
// check body
err, md5Body := getMD5Hash(string(body))
md5Body, err := getMD5Hash(string(body))
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ func callJobFuncWithParams(jobFunc interface{}, params []interface{}) []reflect.

// getMD5Hash use md5 to encode string
// #nosec
func getMD5Hash(str string) (error, string) {
func getMD5Hash(str string) (string, error) {
h := md5.New()
_, err := h.Write([]byte(str))
if err != nil {
return err, ""
return "", err
}
return nil, hex.EncodeToString(h.Sum(nil))
return hex.EncodeToString(h.Sum(nil)), nil
}

0 comments on commit 8a6cda9

Please sign in to comment.