code clean

This commit is contained in:
ginuerzh
2024-10-22 22:53:01 +08:00
parent 4e1a63c922
commit 11b592b173
3 changed files with 0 additions and 88 deletions
-19
View File
@@ -8,22 +8,3 @@ type Option func(opts *Options)
type Admission interface {
Admit(ctx context.Context, addr string, opts ...Option) bool
}
type admissionGroup struct {
admissions []Admission
}
func AdmissionGroup(admissions ...Admission) Admission {
return &admissionGroup{
admissions: admissions,
}
}
func (p *admissionGroup) Admit(ctx context.Context, addr string, opts ...Option) bool {
for _, admission := range p.admissions {
if admission != nil && !admission.Admit(ctx, addr, opts...) {
return false
}
}
return true
}
-26
View File
@@ -10,29 +10,3 @@ type Option func(opts *Options)
type Authenticator interface {
Authenticate(ctx context.Context, user, password string, opts ...Option) (id string, ok bool)
}
type authenticatorGroup struct {
authers []Authenticator
}
func AuthenticatorGroup(authers ...Authenticator) Authenticator {
return &authenticatorGroup{
authers: authers,
}
}
func (p *authenticatorGroup) Authenticate(ctx context.Context, user, password string, opts ...Option) (string, bool) {
if len(p.authers) == 0 {
return "", false
}
for _, auther := range p.authers {
if auther == nil {
continue
}
if id, ok := auther.Authenticate(ctx, user, password, opts...); ok {
return id, ok
}
}
return "", false
}
-43
View File
@@ -2,7 +2,6 @@ package bypass
import (
"context"
"slices"
)
type Options struct {
@@ -30,45 +29,3 @@ type Bypass interface {
IsWhitelist() bool
Contains(ctx context.Context, network, addr string, opts ...Option) bool
}
type bypassGroup struct {
bypasses []Bypass
}
func BypassGroup(bypasses ...Bypass) Bypass {
return &bypassGroup{
bypasses: bypasses,
}
}
func (p *bypassGroup) Contains(ctx context.Context, network, addr string, opts ...Option) bool {
var whitelist, blacklist []bool
for _, bypass := range p.bypasses {
result := bypass.Contains(ctx, network, addr, opts...)
if bypass.IsWhitelist() {
whitelist = append(whitelist, result)
} else {
blacklist = append(blacklist, result)
}
}
status := false
if len(whitelist) > 0 {
if slices.Contains(whitelist, false) {
status = false
} else {
status = true
}
}
if !status && len(blacklist) > 0 {
if slices.Contains(blacklist, true) {
status = true
} else {
status = false
}
}
return status
}
func (p *bypassGroup) IsWhitelist() bool {
return false
}