api

package
v0.0.0-...-f8a1a26 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToEntityTarget

func ConvertToEntityTarget(target Target) entity.Target

ConvertToEntityTarget converts api.Target to entity.Target

func ConvertToEntityTask

func ConvertToEntityTask(task Task) entity.Task

ConvertToEntityTask converts api.Task to entity.Task

func GetTarget

func GetTarget(targetName string, config map[string]interface{}) (entity.Target, error)

func GetTask

func GetTask(taskName string, config map[string]interface{}) (entity.Task, error)

func RegisterTargetType

func RegisterTargetType(name string, targetConstructor TargetConstructor)

func RegisterTaskType

func RegisterTaskType(name string, taskConstructor TaskConstructor)

Types

type Application

type Application struct {
	ApplicationName string
	ApplicationHome string
	PrivatePort     int
	PublicPort      int
	CustomTaskTypes []entity.TaskConstructor
	CustomTargets   []entity.TargetConstructor
	LogLevel        LogLevel
	Hub             Hub
	PublicHandler   *requesthandler.RequestHandler
	PrivateHandler  *requesthandler.RequestHandler
	Logger          *zerolog.Logger
}

func NewApplication

func NewApplication(applicationName string, opts ...Option) *Application

func (*Application) Start

func (a *Application) Start() error

func (*Application) Stop

func (a *Application) Stop() error

type Hub

type Hub interface {
	HandleRequest(r *http.Request) (entity.ServiceResponse, error)
	SetLogger(l *zerolog.Logger)
	GetLogger() *zerolog.Logger
	GetServices() map[string]*entity.Service
}

type LogLevel

type LogLevel int
const (
	// Define log levels as constants
	DebugLevel LogLevel = iota
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
	PanicLevel
)

func (LogLevel) ToZeroLogLevel

func (l LogLevel) ToZeroLogLevel() zerolog.Level

ToZeroLogLevel converts LogLevel to zerolog.Level

type Option

type Option func(*Application)

func WithApplicationHome

func WithApplicationHome(home string) Option

func WithCustomTargets

func WithCustomTargets(targets ...entity.TargetConstructor) Option

func WithCustomTasks

func WithCustomTasks(targets ...entity.TaskConstructor) Option

func WithLogLevel

func WithLogLevel(level LogLevel) Option

func WithPrivatePort

func WithPrivatePort(port int) Option

func WithPublicPort

func WithPublicPort(port int) Option

type RegisteredTargets

type RegisteredTargets map[string]TargetConstructor

RegisteredTargets allows us to register targets at start-up

type ServiceRequest

type ServiceRequest entity.ServiceRequest

type ServiceResponse

type ServiceResponse entity.ServiceResponse

type Target

type Target interface {
	Apply(ctx context.Context, request ServiceRequest) (ServiceResponse, error)
}

We duplicate the Target interface from the entity package to allow for the evolution of the API without breaking changes.

type TargetAdapter

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

TargetAdapter wraps an api.Target and implements entity.Target

func NewTargetAdapter

func NewTargetAdapter(target Target) *TargetAdapter

NewTargetAdapter creates a new TargetAdapter

func (*TargetAdapter) Apply

Apply implements entity.Target

type TargetConstructor

type TargetConstructor interface {
	New(config map[string]any) (Target, error)
}

TargetConstructor takes a config object and returns a configured Target instance.

type TargetConstructorFunc

type TargetConstructorFunc func(config map[string]any) (Target, error)

TaskConstructorFunc is a function type that implements TaskConstructor

func TargetConstructorFromFunction

func TargetConstructorFromFunction(
	fn func(map[string]interface{}) (Target, error),
) TargetConstructorFunc

TargetConstructorFromFunction creates a TargetConstructorFunc from a function with the signature func(map[string]interface{}) (T, error), where T implements Target

func (TargetConstructorFunc) New

func (f TargetConstructorFunc) New(config map[string]any) (Target, error)

New implements the TaskConstructor interface for TaskConstructorFunc

type Task

type Task interface {
	Name() string
	Apply(ctx context.Context, request ServiceRequest) error
}

We duplicate the Task interface from the entity package to allow for the evolution of the API without breaking changes.

type TaskAdapter

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

TaskAdapter wraps an api.Task and implements entity.Task

func NewTaskAdapter

func NewTaskAdapter(task Task) *TaskAdapter

NewTaskAdapter creates a new TaskAdapter

func (*TaskAdapter) Apply

func (a *TaskAdapter) Apply(ctx context.Context, request entity.ServiceRequest) error

Apply implements entity.Task

func (*TaskAdapter) Name

func (a *TaskAdapter) Name() string

Name implements entity.Task

type TaskConstructor

type TaskConstructor interface {
	New(config map[string]any) (Task, error)
}

type TaskConstructorFunc

type TaskConstructorFunc func(config map[string]any) (Task, error)

TaskConstructorFunc is a function type that implements TaskConstructor

func TaskConstructorFromFunction

func TaskConstructorFromFunction(
	fn func(map[string]interface{}) (Task, error),
) TaskConstructorFunc

TaskConstructorFromFunction creates a TaskConstructorFunc from a function with the signature func(map[string]interface{}) (T, error), where T implements Task

func (TaskConstructorFunc) New

func (f TaskConstructorFunc) New(config map[string]any) (Task, error)

New implements the TaskConstructor interface for TaskConstructorFunc

Jump to

Keyboard shortcuts

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