Chore: Merge branch 'ogn-dev' into with-tun

This commit is contained in:
yaling888
2022-03-16 20:16:30 +08:00
74 changed files with 675 additions and 281 deletions

View File

@ -36,7 +36,7 @@ func NewAuthenticator(users []AuthUser) Authenticator {
au.storage.Store(user.User, user.Pass)
}
usernames := make([]string, 0, len(users))
au.storage.Range(func(key, value interface{}) bool {
au.storage.Range(func(key, value any) bool {
usernames = append(usernames, key.(string))
return true
})

View File

@ -1,5 +1,4 @@
//go:build !linux && !darwin
// +build !linux,!darwin
package dialer

View File

@ -1,5 +1,4 @@
//go:build linux
// +build linux
package dialer

View File

@ -1,5 +1,4 @@
//go:build !linux
// +build !linux
package dialer

View File

@ -1,5 +1,4 @@
//go:build !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !solaris && !windows
// +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
package dialer

View File

@ -1,5 +1,4 @@
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
package dialer

View File

@ -23,7 +23,7 @@ var (
var interfaces = singledo.NewSingle(time.Second * 20)
func ResolveInterface(name string) (*Interface, error) {
value, err, _ := interfaces.Do(func() (interface{}, error) {
value, err, _ := interfaces.Do(func() (any, error) {
ifaces, err := net.Interfaces()
if err != nil {
return nil, err

View File

@ -6,17 +6,17 @@ import (
"time"
)
type Factory = func(context.Context) (interface{}, error)
type Factory = func(context.Context) (any, error)
type entry struct {
elm interface{}
elm any
time time.Time
}
type Option func(*pool)
// WithEvict set the evict callback
func WithEvict(cb func(interface{})) Option {
func WithEvict(cb func(any)) Option {
return func(p *pool) {
p.evict = cb
}
@ -32,7 +32,7 @@ func WithAge(maxAge int64) Option {
// WithSize defined max size of Pool
func WithSize(maxSize int) Option {
return func(p *pool) {
p.ch = make(chan interface{}, maxSize)
p.ch = make(chan any, maxSize)
}
}
@ -42,13 +42,13 @@ type Pool struct {
}
type pool struct {
ch chan interface{}
ch chan any
factory Factory
evict func(interface{})
evict func(any)
maxAge int64
}
func (p *pool) GetContext(ctx context.Context) (interface{}, error) {
func (p *pool) GetContext(ctx context.Context) (any, error) {
now := time.Now()
for {
select {
@ -68,11 +68,11 @@ func (p *pool) GetContext(ctx context.Context) (interface{}, error) {
}
}
func (p *pool) Get() (interface{}, error) {
func (p *pool) Get() (any, error) {
return p.GetContext(context.Background())
}
func (p *pool) Put(item interface{}) {
func (p *pool) Put(item any) {
e := &entry{
elm: item,
time: time.Now(),
@ -100,7 +100,7 @@ func recycle(p *Pool) {
func New(factory Factory, options ...Option) *Pool {
p := &pool{
ch: make(chan interface{}, 10),
ch: make(chan any, 10),
factory: factory,
}

View File

@ -10,7 +10,7 @@ import (
func lg() Factory {
initial := -1
return func(context.Context) (interface{}, error) {
return func(context.Context) (any, error) {
initial++
return initial, nil
}
@ -34,7 +34,7 @@ func TestPool_MaxSize(t *testing.T) {
size := 5
pool := New(g, WithSize(size))
items := []interface{}{}
var items []any
for i := 0; i < size; i++ {
item, _ := pool.Get()

View File

@ -1,8 +1,4 @@
//go:build !darwin && !linux && !windows && (!freebsd || !amd64)
// +build !darwin
// +build !linux
// +build !windows
// +build !freebsd !amd64
package process

View File

@ -51,7 +51,7 @@ func ValidAndSplitDomain(domain string) ([]string, bool) {
// 3. subdomain.*.example.com
// 4. .example.com
// 5. +.example.com
func (t *DomainTrie) Insert(domain string, data interface{}) error {
func (t *DomainTrie) Insert(domain string, data any) error {
parts, valid := ValidAndSplitDomain(domain)
if !valid {
return ErrInvalidDomain
@ -68,7 +68,7 @@ func (t *DomainTrie) Insert(domain string, data interface{}) error {
return nil
}
func (t *DomainTrie) insert(parts []string, data interface{}) {
func (t *DomainTrie) insert(parts []string, data any) {
node := t.root
// reverse storage domain part to save space
for i := len(parts) - 1; i >= 0; i-- {

View File

@ -3,7 +3,7 @@ package trie
// Node is the trie's node
type Node struct {
children map[string]*Node
Data interface{}
Data any
}
func (n *Node) getChild(s string) *Node {
@ -18,7 +18,7 @@ func (n *Node) addChild(s string, child *Node) {
n.children[s] = child
}
func newNode(data interface{}) *Node {
func newNode(data any) *Node {
return &Node{
Data: data,
children: map[string]*Node{},