mirror of
https://github.com/v2fly/v2ray-core.git
synced 2026-07-13 04:30:13 -04:00
split listening settings from inbound proxies and apply context
This commit is contained in:
@@ -48,6 +48,10 @@ func (v Destination) String() string {
|
||||
return v.Network.URLPrefix() + ":" + v.NetAddr()
|
||||
}
|
||||
|
||||
func (v Destination) IsValid() bool {
|
||||
return v.Network != Network_Unknown
|
||||
}
|
||||
|
||||
func (v *Endpoint) AsDestination() Destination {
|
||||
return Destination{
|
||||
Network: v.Network,
|
||||
|
||||
23
common/protocol/context.go
Normal file
23
common/protocol/context.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type key int
|
||||
|
||||
const (
|
||||
userKey key = iota
|
||||
)
|
||||
|
||||
func ContextWithUser(ctx context.Context, user *User) context.Context {
|
||||
return context.WithValue(ctx, userKey, user)
|
||||
}
|
||||
|
||||
func UserFromContext(ctx context.Context) *User {
|
||||
v := ctx.Value(userKey)
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
return v.(*User)
|
||||
}
|
||||
@@ -25,7 +25,7 @@ func CreateObject(ctx context.Context, config interface{}) (interface{}, error)
|
||||
configType := reflect.TypeOf(config)
|
||||
creator, found := typeCreatorRegistry[configType]
|
||||
if !found {
|
||||
return nil, errors.New("Common: " + configType.Name() + " is not registered.")
|
||||
return nil, errors.New("Common: " + configType.String() + " is not registered.")
|
||||
}
|
||||
return creator(ctx, config)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user