fix golint issues in rest (#529)

This commit is contained in:
Kevin Wan
2021-03-01 19:15:35 +08:00
committed by GitHub
parent d894b88c3e
commit 655ae8034c
29 changed files with 132 additions and 32 deletions

View File

@@ -28,15 +28,19 @@ var (
)
type (
// A AuthorizeOptions is authorize options.
AuthorizeOptions struct {
PrevSecret string
Callback UnauthorizedCallback
}
// UnauthorizedCallback defines the method of unauthorized callback.
UnauthorizedCallback func(w http.ResponseWriter, r *http.Request, err error)
AuthorizeOption func(opts *AuthorizeOptions)
// AuthorizeOption defines the method to customize an AuthorizeOptions.
AuthorizeOption func(opts *AuthorizeOptions)
)
// Authorize returns an authorize middleware.
func Authorize(secret string, opts ...AuthorizeOption) func(http.Handler) http.Handler {
var authOpts AuthorizeOptions
for _, opt := range opts {
@@ -78,12 +82,14 @@ func Authorize(secret string, opts ...AuthorizeOption) func(http.Handler) http.H
}
}
// WithPrevSecret returns an AuthorizeOption with setting previous secret.
func WithPrevSecret(secret string) AuthorizeOption {
return func(opts *AuthorizeOptions) {
opts.PrevSecret = secret
}
}
// WithUnauthorizedCallback returns an AuthorizeOption with setting unauthorized callback.
func WithUnauthorizedCallback(callback UnauthorizedCallback) AuthorizeOption {
return func(opts *AuthorizeOptions) {
opts.Callback = callback