Moved endpoint handlers in tree

This commit is contained in:
Peter 2021-01-13 18:07:04 +01:00
parent bb9f45ce91
commit dc4a9b18a3
Signed by: prskr
GPG key ID: C1DB5D2E8DB512F9
33 changed files with 55 additions and 55 deletions

View file

@ -2,11 +2,11 @@ package main
import ( import (
"gitlab.com/inetmock/inetmock/internal/cmd" "gitlab.com/inetmock/inetmock/internal/cmd"
_ "gitlab.com/inetmock/inetmock/plugins/dns_mock" _ "gitlab.com/inetmock/inetmock/internal/endpoint/handler/dns/mock"
_ "gitlab.com/inetmock/inetmock/plugins/http_mock" _ "gitlab.com/inetmock/inetmock/internal/endpoint/handler/http/mock"
_ "gitlab.com/inetmock/inetmock/plugins/http_proxy" _ "gitlab.com/inetmock/inetmock/internal/endpoint/handler/http/proxy"
_ "gitlab.com/inetmock/inetmock/plugins/metrics_exporter" _ "gitlab.com/inetmock/inetmock/internal/endpoint/handler/metrics"
_ "gitlab.com/inetmock/inetmock/plugins/tls_interceptor" _ "gitlab.com/inetmock/inetmock/internal/endpoint/handler/tls/interceptor"
) )
func main() { func main() {

View file

@ -9,7 +9,7 @@ import (
"syscall" "syscall"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"gitlab.com/inetmock/inetmock/internal/endpoints" "gitlab.com/inetmock/inetmock/internal/endpoint"
"gitlab.com/inetmock/inetmock/pkg/api" "gitlab.com/inetmock/inetmock/pkg/api"
"gitlab.com/inetmock/inetmock/pkg/audit" "gitlab.com/inetmock/inetmock/pkg/audit"
"gitlab.com/inetmock/inetmock/pkg/audit/sink" "gitlab.com/inetmock/inetmock/pkg/audit/sink"
@ -31,7 +31,7 @@ type App interface {
api.PluginContext api.PluginContext
Config() config.Config Config() config.Config
Checker() health.Checker Checker() health.Checker
EndpointManager() endpoints.EndpointManager EndpointManager() endpoint.EndpointManager
HandlerRegistry() api.HandlerRegistry HandlerRegistry() api.HandlerRegistry
Context() context.Context Context() context.Context
MustRun() MustRun()
@ -45,7 +45,7 @@ type app struct {
rootLogger logging.Logger rootLogger logging.Logger
certStore cert.Store certStore cert.Store
checker health.Checker checker health.Checker
endpointManager endpoints.EndpointManager endpointManager endpoint.EndpointManager
registry api.HandlerRegistry registry api.HandlerRegistry
ctx context.Context ctx context.Context
cancel context.CancelFunc cancel context.CancelFunc
@ -81,7 +81,7 @@ func (a app) Checker() health.Checker {
return a.checker return a.checker
} }
func (a app) EndpointManager() endpoints.EndpointManager { func (a app) EndpointManager() endpoint.EndpointManager {
return a.endpointManager return a.endpointManager
} }
@ -144,7 +144,7 @@ func NewApp(registrations ...api.Registration) (inetmockApp App, err error) {
return return
} }
a.endpointManager = endpoints.NewEndpointManager( a.endpointManager = endpoint.NewEndpointManager(
a.registry, a.registry,
a.Logger().Named("EndpointManager"), a.Logger().Named("EndpointManager"),
a.checker, a.checker,

View file

@ -5,11 +5,11 @@ import (
"os" "os"
"gitlab.com/inetmock/inetmock/internal/app" "gitlab.com/inetmock/inetmock/internal/app"
"gitlab.com/inetmock/inetmock/plugins/dns_mock" "gitlab.com/inetmock/inetmock/internal/endpoint/handler/dns/mock"
"gitlab.com/inetmock/inetmock/plugins/http_mock" mock2 "gitlab.com/inetmock/inetmock/internal/endpoint/handler/http/mock"
"gitlab.com/inetmock/inetmock/plugins/http_proxy" "gitlab.com/inetmock/inetmock/internal/endpoint/handler/http/proxy"
"gitlab.com/inetmock/inetmock/plugins/metrics_exporter" "gitlab.com/inetmock/inetmock/internal/endpoint/handler/metrics"
"gitlab.com/inetmock/inetmock/plugins/tls_interceptor" "gitlab.com/inetmock/inetmock/internal/endpoint/handler/tls/interceptor"
) )
var ( var (
@ -19,11 +19,11 @@ var (
func ExecuteServerCommand() { func ExecuteServerCommand() {
var err error var err error
if server, err = app.NewApp( if server, err = app.NewApp(
http_mock.AddHTTPMock, mock2.AddHTTPMock,
dns_mock.AddDNSMock, mock.AddDNSMock,
tls_interceptor.AddTLSInterceptor, interceptor.AddTLSInterceptor,
http_proxy.AddHTTPProxy, proxy.AddHTTPProxy,
metrics_exporter.AddMetricsExporter, metrics.AddMetricsExporter,
); err != nil { ); err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
os.Exit(1) os.Exit(1)

View file

@ -1,4 +1,4 @@
package endpoints package endpoint
import "time" import "time"

View file

@ -1,5 +1,5 @@
//go:generate mockgen -source=$GOFILE -destination=./../../internal/mock/endpoints/endpoint.mock.go -package=endpoints_mock //go:generate mockgen -source=$GOFILE -destination=./../../internal/mock/endpoints/endpoint.mock.go -package=endpoints_mock
package endpoints package endpoint
import ( import (
"context" "context"

View file

@ -1,4 +1,4 @@
package endpoints package endpoint
import ( import (
"context" "context"

View file

@ -1,4 +1,4 @@
package endpoints package endpoint
import ( import (
"reflect" "reflect"

View file

@ -1,4 +1,4 @@
package dns_mock package mock
import ( import (
"encoding/binary" "encoding/binary"

View file

@ -1,4 +1,4 @@
package dns_mock package mock
import ( import (
"net" "net"

View file

@ -1,4 +1,4 @@
package dns_mock package mock
import ( import (
"context" "context"

View file

@ -1,4 +1,4 @@
package dns_mock package mock
import ( import (
"net" "net"

View file

@ -1,4 +1,4 @@
package dns_mock package mock
import ( import (
"net" "net"

View file

@ -1,4 +1,4 @@
package dns_mock package mock
import ( import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"

View file

@ -1,4 +1,4 @@
package http_mock package mock
import ( import (
"context" "context"

View file

@ -1,4 +1,4 @@
package http_mock package mock
import ( import (
"context" "context"

View file

@ -1,4 +1,4 @@
package http_mock_test package mock_test
import ( import (
"context" "context"
@ -13,12 +13,12 @@ import (
"github.com/golang/mock/gomock" "github.com/golang/mock/gomock"
"github.com/spf13/viper" "github.com/spf13/viper"
"gitlab.com/inetmock/inetmock/internal/endpoint/handler/http/mock"
api_mock "gitlab.com/inetmock/inetmock/internal/mock/api" api_mock "gitlab.com/inetmock/inetmock/internal/mock/api"
audit_mock "gitlab.com/inetmock/inetmock/internal/mock/audit" audit_mock "gitlab.com/inetmock/inetmock/internal/mock/audit"
"gitlab.com/inetmock/inetmock/pkg/api" "gitlab.com/inetmock/inetmock/pkg/api"
"gitlab.com/inetmock/inetmock/pkg/config" "gitlab.com/inetmock/inetmock/pkg/config"
"gitlab.com/inetmock/inetmock/pkg/logging" "gitlab.com/inetmock/inetmock/pkg/logging"
"gitlab.com/inetmock/inetmock/plugins/http_mock"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -65,7 +65,7 @@ func setupHandler(b *testing.B, ctrl *gomock.Controller, listenPort uint16) (api
b.Helper() b.Helper()
registry := api.NewHandlerRegistry() registry := api.NewHandlerRegistry()
if err := http_mock.AddHTTPMock(registry); err != nil { if err := mock.AddHTTPMock(registry); err != nil {
b.Errorf("AddHTTPMock() error = %v", err) b.Errorf("AddHTTPMock() error = %v", err)
} }
handler, ok := registry.HandlerForName("http_mock") handler, ok := registry.HandlerForName("http_mock")

View file

@ -1,5 +1,5 @@
//go:generate go-enum -f $GOFILE --lower --marshal --names //go:generate go-enum -f $GOFILE --lower --marshal --names
package http_mock package mock
import ( import (
"net/http" "net/http"

View file

@ -1,4 +1,4 @@
package http_mock package mock
import ( import (
"path/filepath" "path/filepath"

View file

@ -1,4 +1,4 @@
package http_mock package mock
import ( import (
"net/http" "net/http"

View file

@ -1,4 +1,4 @@
package http_mock package mock
import ( import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"

View file

@ -1,4 +1,4 @@
package http_proxy package proxy
import ( import (
"context" "context"

View file

@ -1,4 +1,4 @@
package http_proxy package proxy
import ( import (
"fmt" "fmt"

View file

@ -1,4 +1,4 @@
package http_proxy package proxy
import ( import (
"context" "context"

View file

@ -1,4 +1,4 @@
package http_proxy package proxy
import ( import (
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"

View file

@ -1,4 +1,4 @@
package metrics_exporter package metrics
import ( import (
"context" "context"

View file

@ -1,4 +1,4 @@
package metrics_exporter package metrics
type metricsExporterOptions struct { type metricsExporterOptions struct {
Route string Route string

View file

@ -1,4 +1,4 @@
package metrics_exporter package metrics
import ( import (
"gitlab.com/inetmock/inetmock/pkg/api" "gitlab.com/inetmock/inetmock/pkg/api"

View file

@ -1,4 +1,4 @@
package tls_interceptor package interceptor
import ( import (
"context" "context"

View file

@ -1,4 +1,4 @@
package tls_interceptor package interceptor
import ( import (
"fmt" "fmt"

View file

@ -1,4 +1,4 @@
package tls_interceptor package interceptor
import ( import (
"net" "net"

View file

@ -1,4 +1,4 @@
package tls_interceptor package interceptor
import ( import (
"fmt" "fmt"

View file

@ -1,4 +1,4 @@
package tls_interceptor package interceptor
import ( import (
"sync" "sync"

View file

@ -3,12 +3,12 @@ package rpc
import ( import (
"context" "context"
"gitlab.com/inetmock/inetmock/internal/endpoints" "gitlab.com/inetmock/inetmock/internal/endpoint"
) )
type endpointsServer struct { type endpointsServer struct {
UnimplementedEndpointsServer UnimplementedEndpointsServer
endpointsManager endpoints.EndpointManager endpointsManager endpoint.EndpointManager
} }
func (e endpointsServer) GetEndpoints(_ context.Context, _ *GetEndpointsRequest) (*GetEndpointsResponse, error) { func (e endpointsServer) GetEndpoints(_ context.Context, _ *GetEndpointsRequest) (*GetEndpointsResponse, error) {
@ -18,7 +18,7 @@ func (e endpointsServer) GetEndpoints(_ context.Context, _ *GetEndpointsRequest)
}, nil }, nil
} }
func rpcEndpointsFromEndpoints(eps []endpoints.Endpoint) *[]*Endpoint { func rpcEndpointsFromEndpoints(eps []endpoint.Endpoint) *[]*Endpoint {
out := make([]*Endpoint, 0) out := make([]*Endpoint, 0)
for _, ep := range eps { for _, ep := range eps {
out = append(out, rpcEndpointFromEndpoint(ep)) out = append(out, rpcEndpointFromEndpoint(ep))
@ -26,7 +26,7 @@ func rpcEndpointsFromEndpoints(eps []endpoints.Endpoint) *[]*Endpoint {
return &out return &out
} }
func rpcEndpointFromEndpoint(ep endpoints.Endpoint) *Endpoint { func rpcEndpointFromEndpoint(ep endpoint.Endpoint) *Endpoint {
return &Endpoint{ return &Endpoint{
Id: ep.Id().String(), Id: ep.Id().String(),
Name: ep.Name(), Name: ep.Name(),