chore(resolver): export structs instead of interfaces
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
// Code generated by MockGen. DO NOT EDIT.
|
||||
// Source: github.com/qdm12/gluetun/internal/updater/resolver (interfaces: Parallel)
|
||||
|
||||
// Package mock_resolver is a generated GoMock package.
|
||||
package mock_resolver
|
||||
|
||||
import (
|
||||
context "context"
|
||||
net "net"
|
||||
reflect "reflect"
|
||||
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
)
|
||||
|
||||
// MockParallel is a mock of Parallel interface.
|
||||
type MockParallel struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockParallelMockRecorder
|
||||
}
|
||||
|
||||
// MockParallelMockRecorder is the mock recorder for MockParallel.
|
||||
type MockParallelMockRecorder struct {
|
||||
mock *MockParallel
|
||||
}
|
||||
|
||||
// NewMockParallel creates a new mock instance.
|
||||
func NewMockParallel(ctrl *gomock.Controller) *MockParallel {
|
||||
mock := &MockParallel{ctrl: ctrl}
|
||||
mock.recorder = &MockParallelMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockParallel) EXPECT() *MockParallelMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Resolve mocks base method.
|
||||
func (m *MockParallel) Resolve(arg0 context.Context, arg1 []string, arg2 int) (map[string][]net.IP, []string, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Resolve", arg0, arg1, arg2)
|
||||
ret0, _ := ret[0].(map[string][]net.IP)
|
||||
ret1, _ := ret[1].([]string)
|
||||
ret2, _ := ret[2].(error)
|
||||
return ret0, ret1, ret2
|
||||
}
|
||||
|
||||
// Resolve indicates an expected call of Resolve.
|
||||
func (mr *MockParallelMockRecorder) Resolve(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Resolve", reflect.TypeOf((*MockParallel)(nil).Resolve), arg0, arg1, arg2)
|
||||
}
|
||||
@@ -7,20 +7,13 @@ import (
|
||||
"net"
|
||||
)
|
||||
|
||||
//go:generate mockgen -destination=mock_$GOPACKAGE/$GOFILE . Parallel
|
||||
|
||||
type Parallel interface {
|
||||
Resolve(ctx context.Context, hosts []string, minToFind int) (
|
||||
hostToIPs map[string][]net.IP, warnings []string, err error)
|
||||
}
|
||||
|
||||
type parallel struct {
|
||||
repeatResolver Repeat
|
||||
type Parallel struct {
|
||||
repeatResolver *Repeat
|
||||
settings ParallelSettings
|
||||
}
|
||||
|
||||
func NewParallelResolver(settings ParallelSettings) Parallel {
|
||||
return ¶llel{
|
||||
func NewParallelResolver(settings ParallelSettings) *Parallel {
|
||||
return &Parallel{
|
||||
repeatResolver: NewRepeat(settings.Repeat),
|
||||
settings: settings,
|
||||
}
|
||||
@@ -46,7 +39,7 @@ var (
|
||||
ErrMaxFailRatio = errors.New("maximum failure ratio reached")
|
||||
)
|
||||
|
||||
func (pr *parallel) Resolve(ctx context.Context, hosts []string, minToFind int) (
|
||||
func (pr *Parallel) Resolve(ctx context.Context, hosts []string, minToFind int) (
|
||||
hostToIPs map[string][]net.IP, warnings []string, err error) {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
@@ -108,7 +101,7 @@ func (pr *parallel) Resolve(ctx context.Context, hosts []string, minToFind int)
|
||||
return hostToIPs, warnings, nil
|
||||
}
|
||||
|
||||
func (pr *parallel) resolveAsync(ctx context.Context, host string,
|
||||
func (pr *Parallel) resolveAsync(ctx context.Context, host string,
|
||||
results chan<- parallelResult, errors chan<- error) {
|
||||
IPs, err := pr.repeatResolver.Resolve(ctx, host)
|
||||
if err != nil {
|
||||
|
||||
@@ -10,17 +10,13 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Repeat interface {
|
||||
Resolve(ctx context.Context, host string) (IPs []net.IP, err error)
|
||||
}
|
||||
|
||||
type repeat struct {
|
||||
type Repeat struct {
|
||||
resolver *net.Resolver
|
||||
settings RepeatSettings
|
||||
}
|
||||
|
||||
func NewRepeat(settings RepeatSettings) Repeat {
|
||||
return &repeat{
|
||||
func NewRepeat(settings RepeatSettings) *Repeat {
|
||||
return &Repeat{
|
||||
resolver: newResolver(settings.Address),
|
||||
settings: settings,
|
||||
}
|
||||
@@ -36,7 +32,7 @@ type RepeatSettings struct {
|
||||
SortIPs bool
|
||||
}
|
||||
|
||||
func (r *repeat) Resolve(ctx context.Context, host string) (ips []net.IP, err error) {
|
||||
func (r *Repeat) Resolve(ctx context.Context, host string) (ips []net.IP, err error) {
|
||||
timedCtx, cancel := context.WithTimeout(ctx, r.settings.MaxDuration)
|
||||
defer cancel()
|
||||
|
||||
@@ -71,7 +67,7 @@ var (
|
||||
ErrMaxFails = errors.New("reached the maximum number of consecutive failures")
|
||||
)
|
||||
|
||||
func (r *repeat) resolveOnce(ctx, timedCtx context.Context, host string,
|
||||
func (r *Repeat) resolveOnce(ctx, timedCtx context.Context, host string,
|
||||
settings RepeatSettings, uniqueIPs map[string]struct{}, noNewCounter, failCounter int) (
|
||||
newNoNewCounter, newFailCounter int, err error) {
|
||||
IPs, err := r.lookupIPs(timedCtx, host)
|
||||
@@ -126,7 +122,7 @@ func (r *repeat) resolveOnce(ctx, timedCtx context.Context, host string,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *repeat) lookupIPs(ctx context.Context, host string) (ips []net.IP, err error) {
|
||||
func (r *Repeat) lookupIPs(ctx context.Context, host string) (ips []net.IP, err error) {
|
||||
addresses, err := r.resolver.LookupIPAddr(ctx, host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
// Package resolver defines custom resolvers to resolve
|
||||
// hosts multiple times with adjustable settings.
|
||||
package resolver
|
||||
Reference in New Issue
Block a user