Skip to content

Instantly share code, notes, and snippets.

@fulviodenza
Created January 18, 2022 16:54
Show Gist options
  • Save fulviodenza/012244027bbdba6634224b2b7ccbde16 to your computer and use it in GitHub Desktop.
Save fulviodenza/012244027bbdba6634224b2b7ccbde16 to your computer and use it in GitHub Desktop.
func (cv *CustomValidator) Validate(i interface{}) error {
if err := cv.validator.Struct(i); err != nil {
// Optionally, you could return the error to give each route more control over the status code
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
}
return nil
}
func validateUser(sl validator.StructLevel) {
if len(sl.Current().Interface().(User).Username) == 0 || len(sl.Current().Interface().(User).Password) == 0 {
sl.ReportError(sl.Current().Interface(), "User", "", "", "")
}
}
func computeSecretHash(clientSecret string, username string, clientId string) string {
mac := hmac.New(sha256.New, []byte(clientSecret))
mac.Write([]byte(username + clientId))
return base64.StdEncoding.EncodeToString(mac.Sum(nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment