dtaservice

package
v0.0.0-...-e8a27b9 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2021 License: MIT Imports: 34 Imported by: 0

README

Contents

This directory contains the DTA specification and a generic DTA server implementation

  • dtaservice.proto: The normative specification of the GRPC specification for the DTA services
  • *.pb.go: Generated files. Created by protoc using grpc-gateway, protoc-gen-govalidators and grpc-ecosystem
  • *.go: The reference implementation for a GRPC-HTTP accessible DTA implementation

NOTE: ../swagger/dtaservice.swagger.json contains a (generated) swagger specification for a REST-specification of DTA.

Documentation

Overview

Package dtaservice is a reverse proxy.

It translates gRPC into RESTful JSON APIs.

Index

Constants

View Source
const (
	// RepoName is the name of this repository
	RepoName string = "github.com/theovassiliou/doctrans-framework"

	// Version contains the actuall version number. Might be replaces using the LDFLAGS.
	Version = "1.1.0-src"
)

Variables

View Source
var File_dtaservice_proto protoreflect.FileDescriptor

Functions

func CaptureSignals

func CaptureSignals(server IDocTransServer, registerURL string, wg *sync.WaitGroup)

CaptureSignals spans a signal handler for SIGINT and SIGTERM

func CreateListener

func CreateListener(startPort, maxPortSeek int) (net.Listener, int)

CreateListener creates a net.listener on port that is yet to be defined. startPort contains the port number where listen should start with and continues until port number startPort+maxPortSeek to open a listener. If it finally fails nil is returned as listener and the last portnumber tries as return port

func CreateMiid

func CreateMiid(s *GenDocTransServer) instanceid.Miid

func CreateMiidString

func CreateMiidString(s *GenDocTransServer) string

func FormatFullVersion

func FormatFullVersion(cmdName, version, branch, commit string) string

FormatFullVersion formats for a cmdName the version number based on version, branch and commit

func GetXinstanceIDHeader

func GetXinstanceIDHeader(s *GenDocTransServer) metadata.MD

GetXinstanceIDHeader returns, if identifity disclouse is indicated a, grpc metada to respond with an appropriate header suitable to

func HandleSignals

func HandleSignals(server IDocTransServer, signalCh chan os.Signal, registerURL string, wg *sync.WaitGroup)

HandleSignals reacts on Signals by managing registration at registry. On SIGINT (CTRL-C) Unregisters On SIGTERM (CTRL-D) Toogling Registration

func LaunchServices

func LaunchServices(grpcGateway, httpGateway IDocTransServer, appName, dtaType, homepageURL string, options DocTransServerOptions)

LaunchServices starts the grpcGateway and/or the httpGateway, registers, if indicated the respectiv services at the provided eureka service, and enables registration/deregistration or toggling of thereof via signals (CTRL-D, CTRL-C)

func MuxHTTPIntoGrpc

func MuxHTTPIntoGrpc(ctx context.Context, httpListener net.Listener, grpcPort int)

MuxHTTPIntoGrpc starts the HTTP server in a given context, with a given listener. grpcPort must contain the port number of the GRPC server in addition the http operations as defined by the GRPC reverse proxy to additional endpoint (/status and /health) are being registered

func RegisterDTAServerHandler

func RegisterDTAServerHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

RegisterDTAServerHandler registers the http handlers for service DTAServer to "mux". The handlers forward requests to the grpc endpoint over "conn".

func RegisterDTAServerHandlerClient

func RegisterDTAServerHandlerClient(ctx context.Context, mux *runtime.ServeMux, client DTAServerClient) error

RegisterDTAServerHandlerClient registers the http handlers for service DTAServer to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "DTAServerClient". Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "DTAServerClient" doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in "DTAServerClient" to call the correct interceptors.

func RegisterDTAServerHandlerFromEndpoint

func RegisterDTAServerHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)

RegisterDTAServerHandlerFromEndpoint is same as RegisterDTAServerHandler but automatically dials to "endpoint" and closes the connection when "ctx" gets done.

func RegisterDTAServerHandlerServer

func RegisterDTAServerHandlerServer(ctx context.Context, mux *runtime.ServeMux, server DTAServerServer) error

RegisterDTAServerHandlerServer registers the http handlers for service DTAServer to "mux". UnaryRPC :call DTAServerServer directly. StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. Note that using this registration option will cause many gRPC library features (such as grpc.SendHeader, etc) to stop working. Consider using RegisterDTAServerHandlerFromEndpoint instead.

func RegisterDTAServerServer

func RegisterDTAServerServer(s *grpc.Server, srv DTAServerServer)

func StartGrpcServer

func StartGrpcServer(lis net.Listener, dtaServer DTAServerServer)

StartGrpcServer starts the grpc server implementation for a given listener

Types

type DTAServerClient

type DTAServerClient interface {
	// Request to transform a plain text document
	TransformDocument(ctx context.Context, in *TransformDocumentRequest, opts ...grpc.CallOption) (*TransformDocumentResponse, error)
	ListServices(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*ListServicesResponse, error)
	TransformDocumentPipe(ctx context.Context, in *TransformDocumentPipeRequest, opts ...grpc.CallOption) (*TransformDocumentResponse, error)
	Options(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*OptionsResponse, error)
}

DTAServerClient is the client API for DTAServer service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewDTAServerClient

func NewDTAServerClient(cc grpc.ClientConnInterface) DTAServerClient

type DTAServerServer

type DTAServerServer interface {
	// Request to transform a plain text document
	TransformDocument(context.Context, *TransformDocumentRequest) (*TransformDocumentResponse, error)
	ListServices(context.Context, *empty.Empty) (*ListServicesResponse, error)
	TransformDocumentPipe(context.Context, *TransformDocumentPipeRequest) (*TransformDocumentResponse, error)
	Options(context.Context, *empty.Empty) (*OptionsResponse, error)
}

DTAServerServer is the server API for DTAServer service.

type DocTransServerGenericOptions

type DocTransServerGenericOptions struct {
	LogLevel log.Level `opts:"group=Generic" help:"Log level, one of panic, fatal, error, warn or warning, info, debug, trace"`
	CfgFile  string    `opts:"group=Generic" help:"The config file to use" json:"-"`
	Init     bool      `` /* 154-byte string literal not displayed */
}

DocTransServerGenericOptions describes generic options that a DTS server offers to the user

type DocTransServerOptions

type DocTransServerOptions struct {
	GRPC         bool   `opts:"group=Protocols" help:"Start service only with GRPC protocol support if set"`
	HTTP         bool   `opts:"group=Protocols" help:"Start service only with HTTP protocol support if set"`
	Port         int    `opts:"group=Protocols" help:"On which port (starting point) to listen for the supported protocol(s)."`
	XInstanceID  bool   `opts:"group=Protocols" help:"If set disable X-Instance-Id disclosure on request."` // my instance ID
	RegHostName  string `opts:"group=Service" help:"If provided will be used as hostname for registration, else automatically derived."`
	RegIPAddress string `opts:"group=Service" help:"If provided will be used as ip-address for registration, else automatically derived."`
	RegPort      string `opts:"group=Service" help:"If provided will be used as port for registration, else automatically derived."`
	RegistrarURL string `opts:"group=Registrar" help:"Registry URL (ex http://eureka:8761/eureka). If set to \"\", no registration to eureka"`
}

DocTransServerOptions describes communication related options that a DTS offers to the user

type GenDocTransServer

type GenDocTransServer struct {
	AppName              string `opts:"-"`
	DtaType              string `opts:"-"`
	Proto                string `opts:"-"`
	XInstanceIDprefix    string `opts:"instance-id"` // my instance ID
	XInstanceIDstartTime time.Time
	// contains filtered or unexported fields
}

GenDocTransServer is the struct that contains a generic server.

func (*GenDocTransServer) ApplicationName

func (dtas *GenDocTransServer) ApplicationName() string

ApplicationName returns the application name of the service

func (*GenDocTransServer) GetResolver

func (dtas *GenDocTransServer) GetResolver() *eureka.Client

func (*GenDocTransServer) InstanceInfo

func (dtas *GenDocTransServer) InstanceInfo() *eureka.InstanceInfo

InstanceInfo returns the eureka.InstanceInfo of this server

func (*GenDocTransServer) ListServices

func (dtas *GenDocTransServer) ListServices(ctx context.Context, req *empty.Empty) (*ListServicesResponse, error)

ListServices standard implementation of listing the supported services

func (*GenDocTransServer) NewInstanceInfo

func (dtas *GenDocTransServer) NewInstanceInfo(hostName, app, ip string, port int, ttl uint, isSsl bool, dtaType, proto string,
	homePageURL, statusURL, healthURL string) *eureka.InstanceInfo

NewInstanceInfo returns an eureka.InstanceInfo build from the information provided. This InstanceInfo can be send to an eureka server.

func (*GenDocTransServer) Options

Options has no default implementation. Overwrite to provide own implementation

func (*GenDocTransServer) RegisterAtRegistry

func (dtas *GenDocTransServer) RegisterAtRegistry(registerURL string)

RegisterAtRegistry registers the DocTransServer at the EUREKA Registry

func (*GenDocTransServer) Registrar

func (dtas *GenDocTransServer) Registrar() *eureka.Client

Registrar returns the Eureka intance where the server has registered.

func (*GenDocTransServer) SetResolver

func (dtas *GenDocTransServer) SetResolver(e *eureka.Client)

func (*GenDocTransServer) TransformDocument

TransformDocument has no default implementation. Overwrite to provide own implementation

func (*GenDocTransServer) TransformDocumentPipe

TransformDocumentPipe has no default implementation. Overwrite to provide own implementation

func (*GenDocTransServer) UnregisterAtRegistry

func (dtas *GenDocTransServer) UnregisterAtRegistry()

UnregisterAtRegistry unregisteres this DocTransServer from EUREKA Registry

type IDocTransServer

type IDocTransServer interface {
	GetDocTransServer() *GenDocTransServer
	DTAServerServer
}

IDocTransServer specifies the interfaces a DocTransServer must implement

type ListServicesResponse

type ListServicesResponse struct {
	ServiceInfos *ServiceInfo `protobuf:"bytes,1,opt,name=serviceInfos,proto3" json:"serviceInfos,omitempty"`
	Services     []string     `protobuf:"bytes,2,rep,name=services,proto3" json:"services,omitempty"`
	// contains filtered or unexported fields
}

func (*ListServicesResponse) Descriptor deprecated

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

Deprecated: Use ListServicesResponse.ProtoReflect.Descriptor instead.

func (*ListServicesResponse) GetServiceInfos

func (x *ListServicesResponse) GetServiceInfos() *ServiceInfo

func (*ListServicesResponse) GetServices

func (x *ListServicesResponse) GetServices() []string

func (*ListServicesResponse) ProtoMessage

func (*ListServicesResponse) ProtoMessage()

func (*ListServicesResponse) ProtoReflect

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

func (*ListServicesResponse) Reset

func (x *ListServicesResponse) Reset()

func (*ListServicesResponse) String

func (x *ListServicesResponse) String() string

func (*ListServicesResponse) Validate

func (this *ListServicesResponse) Validate() error

type OptionsResponse

type OptionsResponse struct {
	Options *_struct.Struct `protobuf:"bytes,1,opt,name=options,proto3" json:"options,omitempty"`
	// contains filtered or unexported fields
}

func (*OptionsResponse) Descriptor deprecated

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

Deprecated: Use OptionsResponse.ProtoReflect.Descriptor instead.

func (*OptionsResponse) GetOptions

func (x *OptionsResponse) GetOptions() *_struct.Struct

func (*OptionsResponse) ProtoMessage

func (*OptionsResponse) ProtoMessage()

func (*OptionsResponse) ProtoReflect

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

func (*OptionsResponse) Reset

func (x *OptionsResponse) Reset()

func (*OptionsResponse) String

func (x *OptionsResponse) String() string

func (*OptionsResponse) Validate

func (this *OptionsResponse) Validate() error

type ServiceInfo

type ServiceInfo struct {
	Name    string          `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	Version string          `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"`
	Options *_struct.Struct `protobuf:"bytes,3,opt,name=options,proto3" json:"options,omitempty"`
	// contains filtered or unexported fields
}

func (*ServiceInfo) Descriptor deprecated

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

Deprecated: Use ServiceInfo.ProtoReflect.Descriptor instead.

func (*ServiceInfo) GetName

func (x *ServiceInfo) GetName() string

func (*ServiceInfo) GetOptions

func (x *ServiceInfo) GetOptions() *_struct.Struct

func (*ServiceInfo) GetVersion

func (x *ServiceInfo) GetVersion() string

func (*ServiceInfo) ProtoMessage

func (*ServiceInfo) ProtoMessage()

func (*ServiceInfo) ProtoReflect

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

func (*ServiceInfo) Reset

func (x *ServiceInfo) Reset()

func (*ServiceInfo) String

func (x *ServiceInfo) String() string

func (*ServiceInfo) Validate

func (this *ServiceInfo) Validate() error

type TransformDocumentPipeRequest

type TransformDocumentPipeRequest struct {
	Pipe []*TransformDocumentRequest `protobuf:"bytes,1,rep,name=pipe,proto3" json:"pipe,omitempty"`
	// contains filtered or unexported fields
}

func (*TransformDocumentPipeRequest) Descriptor deprecated

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

Deprecated: Use TransformDocumentPipeRequest.ProtoReflect.Descriptor instead.

func (*TransformDocumentPipeRequest) GetPipe

func (*TransformDocumentPipeRequest) ProtoMessage

func (*TransformDocumentPipeRequest) ProtoMessage()

func (*TransformDocumentPipeRequest) ProtoReflect

func (*TransformDocumentPipeRequest) Reset

func (x *TransformDocumentPipeRequest) Reset()

func (*TransformDocumentPipeRequest) String

func (*TransformDocumentPipeRequest) Validate

func (this *TransformDocumentPipeRequest) Validate() error

type TransformDocumentRequest

type TransformDocumentRequest struct {
	FileName    string          `protobuf:"bytes,1,opt,name=file_name,json=fileName,proto3" json:"file_name,omitempty"`
	Document    []byte          `protobuf:"bytes,2,opt,name=document,proto3" json:"document,omitempty"`
	ServiceName string          `protobuf:"bytes,3,opt,name=service_name,json=serviceName,proto3" json:"service_name,omitempty"`
	Options     *_struct.Struct `protobuf:"bytes,4,opt,name=options,proto3" json:"options,omitempty"`
	// contains filtered or unexported fields
}

The request message containing the document to be transformed

func (*TransformDocumentRequest) Descriptor deprecated

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

Deprecated: Use TransformDocumentRequest.ProtoReflect.Descriptor instead.

func (*TransformDocumentRequest) GetDocument

func (x *TransformDocumentRequest) GetDocument() []byte

func (*TransformDocumentRequest) GetFileName

func (x *TransformDocumentRequest) GetFileName() string

func (*TransformDocumentRequest) GetOptions

func (x *TransformDocumentRequest) GetOptions() *_struct.Struct

func (*TransformDocumentRequest) GetServiceName

func (x *TransformDocumentRequest) GetServiceName() string

func (*TransformDocumentRequest) ProtoMessage

func (*TransformDocumentRequest) ProtoMessage()

func (*TransformDocumentRequest) ProtoReflect

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

func (*TransformDocumentRequest) Reset

func (x *TransformDocumentRequest) Reset()

func (*TransformDocumentRequest) String

func (x *TransformDocumentRequest) String() string

func (*TransformDocumentRequest) Validate

func (this *TransformDocumentRequest) Validate() error

type TransformDocumentResponse

type TransformDocumentResponse struct {
	Document    []byte   `protobuf:"bytes,1,opt,name=document,proto3" json:"document,omitempty"`
	TransOutput []string `protobuf:"bytes,2,rep,name=trans_output,json=transOutput,proto3" json:"trans_output,omitempty"`
	Error       []string `protobuf:"bytes,3,rep,name=error,proto3" json:"error,omitempty"`
	// contains filtered or unexported fields
}

The response message containing the transformed message

func (*TransformDocumentResponse) Descriptor deprecated

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

Deprecated: Use TransformDocumentResponse.ProtoReflect.Descriptor instead.

func (*TransformDocumentResponse) GetDocument

func (x *TransformDocumentResponse) GetDocument() []byte

func (*TransformDocumentResponse) GetError

func (x *TransformDocumentResponse) GetError() []string

func (*TransformDocumentResponse) GetTransOutput

func (x *TransformDocumentResponse) GetTransOutput() []string

func (*TransformDocumentResponse) ProtoMessage

func (*TransformDocumentResponse) ProtoMessage()

func (*TransformDocumentResponse) ProtoReflect

func (*TransformDocumentResponse) Reset

func (x *TransformDocumentResponse) Reset()

func (*TransformDocumentResponse) String

func (x *TransformDocumentResponse) String() string

func (*TransformDocumentResponse) Validate

func (this *TransformDocumentResponse) Validate() error

type UnimplementedDTAServerServer

type UnimplementedDTAServerServer struct {
}

UnimplementedDTAServerServer can be embedded to have forward compatible implementations.

func (*UnimplementedDTAServerServer) ListServices

func (*UnimplementedDTAServerServer) Options

func (*UnimplementedDTAServerServer) TransformDocument

func (*UnimplementedDTAServerServer) TransformDocumentPipe

Jump to

Keyboard shortcuts

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