mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 04:51:56 +00:00
update dependencies
This commit is contained in:
@@ -281,10 +281,10 @@ func New(w io.Writer) *AccessLog {
|
||||
BodyMinify: true,
|
||||
KeepMultiLineError: true,
|
||||
PanicLog: LogHandler,
|
||||
logsPool: &sync.Pool{New: func() interface{} {
|
||||
logsPool: &sync.Pool{New: func() any {
|
||||
return new(Log)
|
||||
}},
|
||||
bufPool: &sync.Pool{New: func() interface{} {
|
||||
bufPool: &sync.Pool{New: func() any {
|
||||
return new(bytes.Buffer)
|
||||
}},
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ type CSV struct {
|
||||
func (f *CSV) SetOutput(dest io.Writer) {
|
||||
f.ac, _ = dest.(*AccessLog)
|
||||
f.writerPool = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
New: func() any {
|
||||
return csv.NewWriter(dest)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ const (
|
||||
//
|
||||
// Default implementations are:
|
||||
// AllowUsers and AllowUsersFile functions.
|
||||
type AuthFunc func(ctx *context.Context, username, password string) (interface{}, bool)
|
||||
type AuthFunc func(ctx *context.Context, username, password string) (any, bool)
|
||||
|
||||
// ErrorHandler should handle the given request credentials failure.
|
||||
// See Options.ErrorHandler and DefaultErrorHandler for details.
|
||||
@@ -242,7 +242,7 @@ func New(opts Options) context.Handler {
|
||||
// A user list can defined with one of the following values:
|
||||
//
|
||||
// map[string]string form of: {username:password, ...}
|
||||
// map[string]interface{} form of: {"username": {"password": "...", "other_field": ...}, ...}
|
||||
// map[string]any form of: {"username": {"password": "...", "other_field": ...}, ...}
|
||||
// []T which T completes the User interface, where T is a struct value
|
||||
// []T which T contains at least Username and Password fields.
|
||||
//
|
||||
@@ -252,7 +252,7 @@ func New(opts Options) context.Handler {
|
||||
// "admin": "admin",
|
||||
// "john": "p@ss",
|
||||
// })
|
||||
func Default(users interface{}, userOpts ...UserAuthOption) context.Handler {
|
||||
func Default(users any, userOpts ...UserAuthOption) context.Handler {
|
||||
opts := Options{
|
||||
Realm: DefaultRealm,
|
||||
Allow: AllowUsers(users, userOpts...),
|
||||
|
||||
@@ -78,18 +78,18 @@ func toUserAuthOptions(opts []UserAuthOption) (options UserAuthOptions) {
|
||||
// The "users" input parameter can be one of the following forms:
|
||||
//
|
||||
// map[string]string e.g. {username: password, username: password...}.
|
||||
// []map[string]interface{} e.g. []{"username": "...", "password": "...", "other_field": ...}, ...}.
|
||||
// []map[string]any e.g. []{"username": "...", "password": "...", "other_field": ...}, ...}.
|
||||
// []T which T completes the User interface.
|
||||
// []T which T contains at least Username and Password fields.
|
||||
//
|
||||
// Usage:
|
||||
// New(Options{Allow: AllowUsers(..., [BCRYPT])})
|
||||
func AllowUsers(users interface{}, opts ...UserAuthOption) AuthFunc {
|
||||
func AllowUsers(users any, opts ...UserAuthOption) AuthFunc {
|
||||
// create a local user structure to be used in the map copy,
|
||||
// takes longer to initialize but faster to serve.
|
||||
type user struct {
|
||||
password string
|
||||
ref interface{}
|
||||
ref any
|
||||
}
|
||||
cp := make(map[string]*user)
|
||||
|
||||
@@ -114,7 +114,7 @@ func AllowUsers(users interface{}, opts ...UserAuthOption) AuthFunc {
|
||||
switch m := elem.(type) {
|
||||
case map[string]string:
|
||||
return userMap(m, opts...)
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
username, password, ok := mapUsernameAndPassword(m)
|
||||
if !ok {
|
||||
break
|
||||
@@ -133,7 +133,7 @@ func AllowUsers(users interface{}, opts ...UserAuthOption) AuthFunc {
|
||||
|
||||
options := toUserAuthOptions(opts)
|
||||
|
||||
return func(_ *context.Context, username, password string) (interface{}, bool) {
|
||||
return func(_ *context.Context, username, password string) (any, bool) {
|
||||
if u, ok := cp[username]; ok { // fast map access,
|
||||
if options.ComparePassword(u.password, password) {
|
||||
return u.ref, true
|
||||
@@ -147,7 +147,7 @@ func AllowUsers(users interface{}, opts ...UserAuthOption) AuthFunc {
|
||||
func userMap(usernamePassword map[string]string, opts ...UserAuthOption) AuthFunc {
|
||||
options := toUserAuthOptions(opts)
|
||||
|
||||
return func(_ *context.Context, username, password string) (interface{}, bool) {
|
||||
return func(_ *context.Context, username, password string) (any, bool) {
|
||||
pass, ok := usernamePassword[username]
|
||||
return nil, ok && options.ComparePassword(pass, password)
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func AllowUsersFile(jsonOrYamlFilename string, opts ...UserAuthOption) AuthFunc
|
||||
usernamePassword map[string]string
|
||||
// no need to support too much forms, this would be for:
|
||||
// "$username": { "password": "$pass", "other_field": ...}
|
||||
userList []map[string]interface{}
|
||||
userList []map[string]any
|
||||
)
|
||||
|
||||
if err := decodeFile(jsonOrYamlFilename, &usernamePassword, &userList); err != nil {
|
||||
@@ -199,7 +199,7 @@ func AllowUsersFile(jsonOrYamlFilename string, opts ...UserAuthOption) AuthFunc
|
||||
panic("malformed document file: " + jsonOrYamlFilename)
|
||||
}
|
||||
|
||||
func decodeFile(src string, dest ...interface{}) error {
|
||||
func decodeFile(src string, dest ...any) error {
|
||||
data, err := ReadFile(src)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -208,7 +208,7 @@ func decodeFile(src string, dest ...interface{}) error {
|
||||
// We use unmarshal instead of file decoder
|
||||
// as we may need to read it more than once (dests, see below).
|
||||
var (
|
||||
unmarshal func(data []byte, v interface{}) error
|
||||
unmarshal func(data []byte, v any) error
|
||||
ext string
|
||||
)
|
||||
|
||||
@@ -245,7 +245,7 @@ func decodeFile(src string, dest ...interface{}) error {
|
||||
return nil // if at least one is succeed we are ok.
|
||||
}
|
||||
|
||||
func extractUsernameAndPassword(s interface{}) (username, password string, ok bool) {
|
||||
func extractUsernameAndPassword(s any) (username, password string, ok bool) {
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
@@ -256,7 +256,7 @@ func extractUsernameAndPassword(s interface{}) (username, password string, ok bo
|
||||
password = u.GetPassword()
|
||||
ok = username != "" && password != ""
|
||||
return
|
||||
case map[string]interface{}:
|
||||
case map[string]any:
|
||||
return mapUsernameAndPassword(u)
|
||||
default:
|
||||
b, err := json.Marshal(u)
|
||||
@@ -264,7 +264,7 @@ func extractUsernameAndPassword(s interface{}) (username, password string, ok bo
|
||||
return
|
||||
}
|
||||
|
||||
var m map[string]interface{}
|
||||
var m map[string]any
|
||||
if err = json.Unmarshal(b, &m); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -273,7 +273,7 @@ func extractUsernameAndPassword(s interface{}) (username, password string, ok bo
|
||||
}
|
||||
}
|
||||
|
||||
func mapUsernameAndPassword(m map[string]interface{}) (username, password string, ok bool) {
|
||||
func mapUsernameAndPassword(m map[string]any) (username, password string, ok bool) {
|
||||
// type of username: password.
|
||||
if len(m) == 1 {
|
||||
for username, v := range m {
|
||||
|
||||
@@ -13,13 +13,13 @@ import (
|
||||
)
|
||||
|
||||
type IUserRepository interface {
|
||||
GetByUsernameAndPassword(dest interface{}, username, password string) error
|
||||
GetByUsernameAndPassword(dest any, username, password string) error
|
||||
}
|
||||
|
||||
// Test a custom implementation of AuthFunc with a user repository.
|
||||
// This is a usage example of custom AuthFunc implementation.
|
||||
func UserRepository(repo IUserRepository, newUserPtr func() interface{}) AuthFunc {
|
||||
return func(_ *context.Context, username, password string) (interface{}, bool) {
|
||||
func UserRepository(repo IUserRepository, newUserPtr func() any) AuthFunc {
|
||||
return func(_ *context.Context, username, password string) (any, bool) {
|
||||
dest := newUserPtr()
|
||||
err := repo.GetByUsernameAndPassword(dest, username, password)
|
||||
if err == nil {
|
||||
@@ -50,7 +50,7 @@ type testRepo struct {
|
||||
}
|
||||
|
||||
// Implements IUserRepository interface.
|
||||
func (r *testRepo) GetByUsernameAndPassword(dest interface{}, username, password string) error {
|
||||
func (r *testRepo) GetByUsernameAndPassword(dest any, username, password string) error {
|
||||
for _, e := range r.entries {
|
||||
if e.username == username && e.password == password {
|
||||
*dest.(*testUser) = e
|
||||
@@ -68,7 +68,7 @@ func TestAllowUserRepository(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
allow := UserRepository(repo, func() interface{} {
|
||||
allow := UserRepository(repo, func() any {
|
||||
return new(testUser)
|
||||
})
|
||||
|
||||
@@ -260,7 +260,7 @@ func TestAllowUsersFile(t *testing.T) {
|
||||
|
||||
u, ok := v.(context.Map)
|
||||
if !ok {
|
||||
t.Fatalf("[%d] a user loaded from external source or file should be alway type of map[string]interface{} but got: %#+v (%T)", i, v, v)
|
||||
t.Fatalf("[%d] a user loaded from external source or file should be alway type of map[string]any but got: %#+v (%T)", i, v, v)
|
||||
}
|
||||
|
||||
if expected, got := len(tt.user), len(u); expected != got {
|
||||
|
||||
@@ -352,7 +352,7 @@ func main() {
|
||||
// You can also register the pre-defined jwt middleware for all protected routes
|
||||
// which performs verification automatically and set the custom Claims to the Context
|
||||
// for next handlers to use through: claims := jwt.Get(ctx).(*Claims).
|
||||
app.Use(accessVerifier.Verify(func() interface{} {
|
||||
app.Use(accessVerifier.Verify(func() any {
|
||||
return new(Claims)
|
||||
}))
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ func TestJWT(t *testing.T) {
|
||||
verifier.ErrorHandler = func(ctx iris.Context, err error) { // app.OnErrorCode(401, ...)
|
||||
ctx.StopWithError(iris.StatusUnauthorized, err)
|
||||
}
|
||||
middleware := verifier.Verify(func() interface{} { return new(fooClaims) })
|
||||
middleware := verifier.Verify(func() any { return new(fooClaims) })
|
||||
app.Get("/protected", middleware, func(ctx iris.Context) {
|
||||
claims := jwt.Get(ctx).(*fooClaims)
|
||||
ctx.WriteString(claims.Foo)
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
// It does not support JWE, JWK.
|
||||
type Signer struct {
|
||||
Alg Alg
|
||||
Key interface{}
|
||||
Key any
|
||||
|
||||
// MaxAge to set "exp" and "iat".
|
||||
// Recommended value for access tokens: 15 minutes.
|
||||
@@ -33,7 +33,7 @@ type Signer struct {
|
||||
//
|
||||
// signer := NewSigner(HS256, secret, 15*time.Minute)
|
||||
// token, err := signer.Sign(userClaims{Username: "kataras"})
|
||||
func NewSigner(signatureAlg Alg, signatureKey interface{}, maxAge time.Duration) *Signer {
|
||||
func NewSigner(signatureAlg Alg, signatureKey any, maxAge time.Duration) *Signer {
|
||||
if signatureAlg == HS256 {
|
||||
// A tiny helper if the end-developer uses string instead of []byte for hmac keys.
|
||||
if k, ok := signatureKey.(string); ok {
|
||||
@@ -66,7 +66,7 @@ func (s *Signer) WithEncryption(key, additionalData []byte) *Signer {
|
||||
}
|
||||
|
||||
// Sign generates a new token based on the given "claims" which is valid up to "s.MaxAge".
|
||||
func (s *Signer) Sign(claims interface{}, opts ...SignOption) ([]byte, error) {
|
||||
func (s *Signer) Sign(claims any, opts ...SignOption) ([]byte, error) {
|
||||
if len(opts) > 0 {
|
||||
opts = append(opts, s.Options...)
|
||||
} else {
|
||||
@@ -79,7 +79,7 @@ func (s *Signer) Sign(claims interface{}, opts ...SignOption) ([]byte, error) {
|
||||
// NewTokenPair accepts the access and refresh claims plus the life time duration for the refresh token
|
||||
// and generates a new token pair which can be sent to the client.
|
||||
// The same token pair can be json-decoded.
|
||||
func (s *Signer) NewTokenPair(accessClaims interface{}, refreshClaims interface{}, refreshMaxAge time.Duration, accessOpts ...SignOption) (TokenPair, error) {
|
||||
func (s *Signer) NewTokenPair(accessClaims any, refreshClaims any, refreshMaxAge time.Duration, accessOpts ...SignOption) (TokenPair, error) {
|
||||
if refreshMaxAge <= s.MaxAge {
|
||||
return TokenPair{}, fmt.Errorf("refresh max age should be bigger than access token's one[%d - %d]", refreshMaxAge, s.MaxAge)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ const (
|
||||
)
|
||||
|
||||
// Get returns the claims decoded by a verifier.
|
||||
func Get(ctx *context.Context) interface{} {
|
||||
func Get(ctx *context.Context) any {
|
||||
if v := ctx.Values().Get(claimsContextKey); v != nil {
|
||||
return v
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func GetVerifiedToken(ctx *context.Context) *VerifiedToken {
|
||||
// It does not support JWE, JWK.
|
||||
type Verifier struct {
|
||||
Alg Alg
|
||||
Key interface{}
|
||||
Key any
|
||||
|
||||
Decrypt func([]byte) ([]byte, error)
|
||||
|
||||
@@ -67,7 +67,7 @@ type Verifier struct {
|
||||
//
|
||||
// verifier := NewVerifier(HS256, secret, Expected{Issuer: "my-app"})
|
||||
//
|
||||
// claimsGetter := func() interface{} { return new(userClaims) }
|
||||
// claimsGetter := func() any { return new(userClaims) }
|
||||
// middleware := verifier.Verify(claimsGetter)
|
||||
//
|
||||
// OR
|
||||
@@ -86,7 +86,7 @@ type Verifier struct {
|
||||
// Get the context user:
|
||||
//
|
||||
// username, err := ctx.User().GetUsername()
|
||||
func NewVerifier(signatureAlg Alg, signatureKey interface{}, validators ...TokenValidator) *Verifier {
|
||||
func NewVerifier(signatureAlg Alg, signatureKey any, validators ...TokenValidator) *Verifier {
|
||||
if signatureAlg == HS256 {
|
||||
// A tiny helper if the end-developer uses string instead of []byte for hmac keys.
|
||||
if k, ok := signatureKey.(string); ok {
|
||||
@@ -183,7 +183,7 @@ func (v *Verifier) VerifyToken(token []byte, validators ...TokenValidator) (*Ver
|
||||
//
|
||||
// If the "claimsType" is nil then only the jwt.GetVerifiedToken is available
|
||||
// and the handler should unmarshal the payload to extract the claims by itself.
|
||||
func (v *Verifier) Verify(claimsType func() interface{}, validators ...TokenValidator) context.Handler {
|
||||
func (v *Verifier) Verify(claimsType func() any, validators ...TokenValidator) context.Handler {
|
||||
unmarshal := jwt.Unmarshal
|
||||
if claimsType != nil {
|
||||
c := claimsType()
|
||||
@@ -252,7 +252,7 @@ func (v *Verifier) Verify(claimsType func() interface{}, validators ...TokenVali
|
||||
}
|
||||
}
|
||||
|
||||
func hasRequired(i interface{}) bool {
|
||||
func hasRequired(i any) bool {
|
||||
val := reflect.Indirect(reflect.ValueOf(i))
|
||||
typ := val.Type()
|
||||
if typ.Kind() != reflect.Struct {
|
||||
|
||||
@@ -69,7 +69,7 @@ type Config struct {
|
||||
// LogFunc is the writer which logs are written to,
|
||||
// if missing the logger middleware uses the app.Logger().Infof instead.
|
||||
// Note that message argument can be empty.
|
||||
LogFunc func(endTime time.Time, latency time.Duration, status, ip, method, path string, message interface{}, headerMessage interface{})
|
||||
LogFunc func(endTime time.Time, latency time.Duration, status, ip, method, path string, message any, headerMessage any)
|
||||
// LogFuncCtx can be used instead of `LogFunc` if handlers need to customize the output based on
|
||||
// custom request-time information that the LogFunc isn't aware of.
|
||||
LogFuncCtx func(ctx *context.Context, latency time.Duration)
|
||||
|
||||
@@ -86,7 +86,7 @@ func (l *requestLoggerMiddleware) ServeHTTP(ctx *context.Context) {
|
||||
status = strconv.Itoa(ctx.GetStatusCode())
|
||||
}
|
||||
|
||||
var message interface{}
|
||||
var message any
|
||||
if ctxKeys := l.config.MessageContextKeys; len(ctxKeys) > 0 {
|
||||
for _, key := range ctxKeys {
|
||||
msg := ctx.Values().Get(key)
|
||||
@@ -97,7 +97,7 @@ func (l *requestLoggerMiddleware) ServeHTTP(ctx *context.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
var headerMessage interface{}
|
||||
var headerMessage any
|
||||
if headerKeys := l.config.MessageHeaderKeys; len(headerKeys) > 0 {
|
||||
for _, key := range headerKeys {
|
||||
msg := ctx.GetHeader(key)
|
||||
|
||||
@@ -16,7 +16,7 @@ func init() {
|
||||
type options struct {
|
||||
getters []GetterFunc
|
||||
methods []string
|
||||
saveOriginalMethodContextKey interface{} // if not nil original value will be saved.
|
||||
saveOriginalMethodContextKey any // if not nil original value will be saved.
|
||||
}
|
||||
|
||||
func (o *options) configure(opts ...Option) {
|
||||
@@ -65,7 +65,7 @@ func Methods(methods ...string) Option {
|
||||
// on Context.Request().Context().Value(requestContextKey).
|
||||
//
|
||||
// Defaults to nil, don't save it.
|
||||
func SaveOriginalMethod(requestContextKey interface{}) Option {
|
||||
func SaveOriginalMethod(requestContextKey any) Option {
|
||||
return func(opts *options) {
|
||||
if requestContextKey == nil {
|
||||
opts.saveOriginalMethodContextKey = nil
|
||||
|
||||
@@ -35,7 +35,7 @@ func ExceedHandler(handler context.Handler) Option {
|
||||
// ClientData is an `Option` that can be passed at the `Limit` package-level function.
|
||||
// It accepts a function which provides the Iris Context and should return custom data
|
||||
// that will be stored to the Client and be retrieved as `Get(ctx).Client.Data` later on.
|
||||
func ClientData(clientDataFunc func(ctx *context.Context) interface{}) Option {
|
||||
func ClientData(clientDataFunc func(ctx *context.Context) any) Option {
|
||||
return func(l *Limiter) {
|
||||
l.clientDataFunc = clientDataFunc
|
||||
}
|
||||
@@ -79,8 +79,8 @@ type (
|
||||
// old clients from the memory. Limiter is not exposed by a function,
|
||||
// callers should use it inside an `Option` for the `Limit` package-level function.
|
||||
Limiter struct {
|
||||
clientDataFunc func(ctx *context.Context) interface{} // fill the Client's Data field.
|
||||
exceedHandler context.Handler // when too many requests.
|
||||
clientDataFunc func(ctx *context.Context) any // fill the Client's Data field.
|
||||
exceedHandler context.Handler // when too many requests.
|
||||
|
||||
limit rate.Limit
|
||||
burstSize int
|
||||
@@ -94,7 +94,7 @@ type (
|
||||
// It can be used to manually add RateLimit response headers.
|
||||
Client struct {
|
||||
ID string
|
||||
Data interface{}
|
||||
Data any
|
||||
Limiter *rate.Limiter
|
||||
|
||||
lastSeen time.Time
|
||||
|
||||
@@ -130,7 +130,7 @@ func (e *Engine) SetLogger(logger *golog.Logger) *Engine {
|
||||
}
|
||||
|
||||
// init the request logging with [DBUG].
|
||||
func (e *Engine) initDebugf(format string, args ...interface{}) {
|
||||
func (e *Engine) initDebugf(format string, args ...any) {
|
||||
if e.logger == nil {
|
||||
return
|
||||
}
|
||||
@@ -142,7 +142,7 @@ var skipDBUGSpace = strings.Repeat(" ", 7)
|
||||
|
||||
// continue debugging the same request with new lines and spacing,
|
||||
// easier to read.
|
||||
func (e *Engine) debugf(format string, args ...interface{}) {
|
||||
func (e *Engine) debugf(format string, args ...any) {
|
||||
if e.logger == nil || e.logger.Level < golog.DebugLevel {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user