Created
January 18, 2022 16:54
-
-
Save fulviodenza/012244027bbdba6634224b2b7ccbde16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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