resolver

package
v0.0.131 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 19 Imported by: 2

Documentation

Overview

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software. * *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *SOFTWARE.

Index

Constants

This section is empty.

Variables

View Source
var (
	Resolver_ResolverType_name = map[int32]string{
		0: "resolver_type_dns",
		1: "resolver_type_consul",
		2: "resolver_type_k8s",
	}
	Resolver_ResolverType_value = map[string]int32{
		"resolver_type_dns":    0,
		"resolver_type_consul": 1,
		"resolver_type_k8s":    2,
	}
)

Enum value maps for Resolver_ResolverType.

View Source
var (
	Resolver_LoadBalanceMode_name = map[int32]string{
		0: "load_balance_mode_random",
		1: "load_balance_mode_consist",
	}
	Resolver_LoadBalanceMode_value = map[string]int32{
		"load_balance_mode_random":  0,
		"load_balance_mode_consist": 1,
	}
)

Enum value maps for Resolver_LoadBalanceMode.

View Source
var File_pkg_resolver_resolver_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type CompletedConfig

type CompletedConfig struct {
	// contains filtered or unexported fields
}

func (CompletedConfig) New

func (c CompletedConfig) New(ctx context.Context, opts ...ResolverQueryOption) (*ResolverService, error)

type Config

type Config struct {
	Proto Resolver
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(options ...ConfigOption) *Config

func (*Config) ApplyOptions

func (o *Config) ApplyOptions(options ...ConfigOption) *Config

func (*Config) Complete

func (c *Config) Complete() CompletedConfig

Complete set default ServerRunOptions.

type ConfigOption

type ConfigOption interface {
	// contains filtered or unexported methods
}

A ConfigOption sets options.

func WithViper

func WithViper(v *viper.Viper) ConfigOption

type ConfigOptionFunc

type ConfigOptionFunc func(*Config)

ConfigOptionFunc wraps a function that modifies Client into an implementation of the ConfigOption interface.

type EmptyConfigOption

type EmptyConfigOption struct{}

EmptyConfigOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type EmptyResolverQueryOption

type EmptyResolverQueryOption struct{}

EmptyResolverQueryUrlOption does not alter the ResolverQueryuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type Resolver

type Resolver struct {
	Enabled         bool                     `protobuf:"varint,1,opt,name=enabled,proto3" json:"enabled,omitempty"`
	ResolverType    Resolver_ResolverType    `` /* 141-byte string literal not displayed */
	LoadBalanceMode Resolver_LoadBalanceMode `` /* 155-byte string literal not displayed */
	ResolveInterval *duration.Duration       `protobuf:"bytes,4,opt,name=resolve_interval,json=resolveInterval,proto3" json:"resolve_interval,omitempty"`
	Domains         []string                 `protobuf:"bytes,5,rep,name=domains,proto3" json:"domains,omitempty"`
	K8S             *Resolver_K8S            `protobuf:"bytes,6,opt,name=k8s,proto3" json:"k8s,omitempty"`
	// contains filtered or unexported fields
}

func (*Resolver) Descriptor deprecated

func (*Resolver) Descriptor() ([]byte, []int)

Deprecated: Use Resolver.ProtoReflect.Descriptor instead.

func (*Resolver) GetDomains

func (x *Resolver) GetDomains() []string

func (*Resolver) GetEnabled

func (x *Resolver) GetEnabled() bool

func (*Resolver) GetK8S

func (x *Resolver) GetK8S() *Resolver_K8S

func (*Resolver) GetLoadBalanceMode

func (x *Resolver) GetLoadBalanceMode() Resolver_LoadBalanceMode

func (*Resolver) GetResolveInterval

func (x *Resolver) GetResolveInterval() *duration.Duration

func (*Resolver) GetResolverType

func (x *Resolver) GetResolverType() Resolver_ResolverType

func (*Resolver) ProtoMessage

func (*Resolver) ProtoMessage()

func (*Resolver) ProtoReflect

func (x *Resolver) ProtoReflect() protoreflect.Message

func (*Resolver) Reset

func (x *Resolver) Reset()

func (*Resolver) String

func (x *Resolver) String() string

type ResolverOptions

type ResolverOptions struct {
	// contains filtered or unexported fields
}

type ResolverQuery

type ResolverQuery struct {
	// domain: domain for net resolver, Ex: cube-svc.ns.svc
	// domain: svc name for k8s resolver, Ex: cube
	Domain string
	// contains filtered or unexported fields
}

func NewDefaultResolverQuery

func NewDefaultResolverQuery(domain string) ResolverQuery

NewDefaultResolverQuery, dns reslover, bls consist hash

func NewResolverQuery

func NewResolverQuery(domain string, opts ...ResolverQueryOption) (ResolverQuery, error)

func (*ResolverQuery) ApplyOptions

func (o *ResolverQuery) ApplyOptions(options ...ResolverQueryOption) *ResolverQuery

func (*ResolverQuery) SetDefault

func (r *ResolverQuery) SetDefault()

func (*ResolverQuery) SetResolver

func (r *ResolverQuery) SetResolver() error

type ResolverQueryMap

type ResolverQueryMap sync.Map

func (*ResolverQueryMap) Delete

func (m *ResolverQueryMap) Delete(key string)

Delete deletes the value for a key.

func (*ResolverQueryMap) Load

func (m *ResolverQueryMap) Load(key string) (ResolverQuery, bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*ResolverQueryMap) LoadAndDelete

func (m *ResolverQueryMap) LoadAndDelete(key string) (value ResolverQuery, loaded bool)

LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.

func (*ResolverQueryMap) LoadOrStore

func (m *ResolverQueryMap) LoadOrStore(key string, value ResolverQuery) (ResolverQuery, bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*ResolverQueryMap) Range

func (m *ResolverQueryMap) Range(f func(key string, value ResolverQuery) bool)

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently, Range may reflect any mapping for that key from any point during the Range call.

Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.

func (*ResolverQueryMap) Store

func (m *ResolverQueryMap) Store(key string, value ResolverQuery)

Store sets the value for a key.

type ResolverQueryOption

type ResolverQueryOption interface {
	// contains filtered or unexported methods
}

A ResolverQueryOption sets options.

func WithLoadBalanceMode

func WithLoadBalanceMode(loadBalanceMode Resolver_LoadBalanceMode) ResolverQueryOption

func WithNodeGroup

func WithNodeGroup(nodeGroup string) ResolverQueryOption

func WithNodeUnit

func WithNodeUnit(nodeUnit string) ResolverQueryOption

func WithResolver

func WithResolver(resolver dns_.DNSResolver) ResolverQueryOption

func WithResolverType

func WithResolverType(resolverType Resolver_ResolverType) ResolverQueryOption

type ResolverQueryOptionFunc

type ResolverQueryOptionFunc func(*ResolverQuery)

ResolverQueryOptionFunc wraps a function that modifies ResolverQuery into an implementation of the ResolverQueryOption interface.

type ResolverService

type ResolverService struct {
	// contains filtered or unexported fields
}

func NewDefaultResolverServices

func NewDefaultResolverServices(resolverInterval time.Duration, domains ...string) *ResolverService

func NewResolverService

func NewResolverService(resolverInterval time.Duration, services ...ResolverQuery) *ResolverService

func (*ResolverService) AddService

func (srv *ResolverService) AddService(service ResolverQuery)

AddService, if exist, it will update

func (*ResolverService) AddServices

func (srv *ResolverService) AddServices(services ...ResolverQuery)

AddServices, if exist, it will update

func (*ResolverService) PickNode

func (srv *ResolverService) PickNode(name string, consistKey string) (node string, has bool)

func (*ResolverService) QueryServices

func (srv *ResolverService) QueryServices() (err error)

func (*ResolverService) Run

func (srv *ResolverService) Run(ctx context.Context) error

func (*ResolverService) Serve

func (srv *ResolverService) Serve(ctx context.Context) error

func (*ResolverService) Shutdown

func (srv *ResolverService) Shutdown()

type Resolver_K8S

type Resolver_K8S struct {
	ServiceNames []string `protobuf:"bytes,1,rep,name=service_names,json=serviceNames,proto3" json:"service_names,omitempty"`
	NodeGroup    string   `protobuf:"bytes,2,opt,name=node_group,json=nodeGroup,proto3" json:"node_group,omitempty"`
	NodeUnit     string   `protobuf:"bytes,3,opt,name=node_unit,json=nodeUnit,proto3" json:"node_unit,omitempty"`
	// contains filtered or unexported fields
}

func (*Resolver_K8S) Descriptor deprecated

func (*Resolver_K8S) Descriptor() ([]byte, []int)

Deprecated: Use Resolver_K8S.ProtoReflect.Descriptor instead.

func (*Resolver_K8S) GetNodeGroup

func (x *Resolver_K8S) GetNodeGroup() string

func (*Resolver_K8S) GetNodeUnit

func (x *Resolver_K8S) GetNodeUnit() string

func (*Resolver_K8S) GetServiceNames

func (x *Resolver_K8S) GetServiceNames() []string

func (*Resolver_K8S) ProtoMessage

func (*Resolver_K8S) ProtoMessage()

func (*Resolver_K8S) ProtoReflect

func (x *Resolver_K8S) ProtoReflect() protoreflect.Message

func (*Resolver_K8S) Reset

func (x *Resolver_K8S) Reset()

func (*Resolver_K8S) String

func (x *Resolver_K8S) String() string

type Resolver_LoadBalanceMode

type Resolver_LoadBalanceMode int32
const (
	Resolver_load_balance_mode_random  Resolver_LoadBalanceMode = 0
	Resolver_load_balance_mode_consist Resolver_LoadBalanceMode = 1
)

func (Resolver_LoadBalanceMode) Descriptor

func (Resolver_LoadBalanceMode) Enum

func (Resolver_LoadBalanceMode) EnumDescriptor deprecated

func (Resolver_LoadBalanceMode) EnumDescriptor() ([]byte, []int)

Deprecated: Use Resolver_LoadBalanceMode.Descriptor instead.

func (Resolver_LoadBalanceMode) Number

func (Resolver_LoadBalanceMode) String

func (x Resolver_LoadBalanceMode) String() string

func (Resolver_LoadBalanceMode) Type

type Resolver_ResolverType

type Resolver_ResolverType int32
const (
	Resolver_resolver_type_dns    Resolver_ResolverType = 0
	Resolver_resolver_type_consul Resolver_ResolverType = 1
	Resolver_resolver_type_k8s    Resolver_ResolverType = 2
)

func (Resolver_ResolverType) Descriptor

func (Resolver_ResolverType) Enum

func (Resolver_ResolverType) EnumDescriptor deprecated

func (Resolver_ResolverType) EnumDescriptor() ([]byte, []int)

Deprecated: Use Resolver_ResolverType.Descriptor instead.

func (Resolver_ResolverType) Number

func (Resolver_ResolverType) String

func (x Resolver_ResolverType) String() string

func (Resolver_ResolverType) Type

Directories

Path Synopsis
dns
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software.
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software.
k8s-resolver
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software.
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software.
net-resolver
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software.
*Copyright (c) 2022, kaydxh * *Permission is hereby granted, free of charge, to any person obtaining a copy *of this software and associated documentation files (the "Software"), to deal *in the Software without restriction, including without limitation the rights *to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *copies of the Software, and to permit persons to whom the Software is *furnished to do so, subject to the following conditions: * *The above copyright notice and this permission notice shall be included in all *copies or substantial portions of the Software.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL