Files
drip/internal/shared/utils/allowed_list.go
zhiqing 307cf8e6cc feat: Add Bearer Token authentication support and optimize code structure
- Add Bearer Token authentication, supporting tunnel access control via the --auth-bearer parameter
- Refactor large modules into smaller, more focused components to improve code maintainability
- Update dependency versions, including golang.org/x/crypto, golang.org/x/net, etc.
- Add SilenceUsage and SilenceErrors configuration for all CLI commands
- Modify connector configuration structure to support the new authentication method
- Update recent change log in README with new feature descriptions

BREAKING CHANGE: Authentication via Bearer Token is now supported, requiring the new --auth-bearer parameter
2026-01-29 14:40:53 +08:00

50 lines
1.1 KiB
Go

package utils
import "strings"
// AllowedList manages a list of allowed values with case-insensitive matching.
type AllowedList struct {
items []string
}
// NewAllowedList creates a new AllowedList from the given items.
func NewAllowedList(items []string) *AllowedList {
return &AllowedList{items: items}
}
// IsAllowed checks if a value is in the allowed list.
// If the list is empty, all values are allowed.
// Matching is case-insensitive.
func (a *AllowedList) IsAllowed(value string) bool {
if len(a.items) == 0 {
return true
}
for _, item := range a.items {
if strings.EqualFold(item, value) {
return true
}
}
return false
}
// GetPreferred returns the first item in the list, or the default value if empty.
func (a *AllowedList) GetPreferred(defaultValue string) string {
if len(a.items) == 0 {
return defaultValue
}
if len(a.items) == 1 {
return a.items[0]
}
return defaultValue
}
// Items returns the underlying slice of allowed items.
func (a *AllowedList) Items() []string {
return a.items
}
// IsEmpty returns true if the allowed list is empty.
func (a *AllowedList) IsEmpty() bool {
return len(a.items) == 0
}