wrapper

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWrapperContextMissing = errors.New("wrapper context missing")

Functions

func GetEventName added in v0.4.0

func GetEventName(event any) string

func NewNamedTask added in v0.5.0

func NewNamedTask(name string, run func(context.Context, Wrapper) error) *task

func Run added in v0.6.0

func Run(ctx context.Context, options *Options) error

func WithWrapper added in v0.6.0

func WithWrapper(ctx context.Context, wp Wrapper) context.Context

Types

type ConfigParser added in v0.6.0

type ConfigParser interface {
	Parse(map[string]any, Wrapper) error
}

type Event

type Event struct {
	Id        string `json:"id"`
	Timestamp int64  `json:"timestamp"`
	Name      string `json:"name"`
	Data      any    `json:"data"`
}

type Hook added in v0.4.0

type Hook interface {
	Execute(context.Context, []byte) error
}

type Map added in v0.6.0

type Map interface {
	GetInt8(string, int8) int8
	GetUint8(string, uint8) uint8
	GetInt16(string, int16) int16
	GetUint16(string, uint16) uint16
	GetInt32(string, int32) int32
	GetUint32(string, uint32) uint32
	GetInt64(string, int64) int64
	GetUint64(string, uint64) uint64
	GetBool(string, bool) bool
	GetString(string, string) string
	GetMap(string, Map) Map
}

type Options added in v0.6.0

type Options struct {
	Program  string
	Args     []string
	Dir      string
	Env      []string
	Graceful struct {
		Timeout time.Duration
		Stopper Stopper
	}
	Tasks         []Task
	Services      []Service
	ConfigParsers []ConfigParser
	Logger        *slog.Logger
}

type ProcessLogEvent

type ProcessLogEvent struct {
	Message string `json:"message"`
}

type Registry added in v0.6.0

type Registry struct {
	Tasks    []Task
	Services []Service

	Stoppers        map[string]func(map[string]any) Stopper
	LoggingHandlers map[string]func(map[string]any) slog.Handler
	Hooks           map[string]func(map[string]any) Hook
	ConfigParser    map[string]func(map[string]any) ConfigParser
}

func NewRegistry added in v0.6.0

func NewRegistry() *Registry

type ServerState added in v0.6.0

type ServerState struct {
	Status  ServerState_Status  `json:"status"`
	Players ServerState_Players `json:"players"`
}

type ServerState_Player added in v0.6.0

type ServerState_Player struct {
	Id         string         `json:"id"`
	Attributes map[string]any `json:"attributes"`
}

type ServerState_Players added in v0.6.0

type ServerState_Players struct {
	Count int                  `json:"count"`
	Max   int                  `json:"max"`
	List  []ServerState_Player `json:"list"`
}

type ServerState_Status added in v0.6.0

type ServerState_Status struct {
	Description string `json:"description"`
}

type Service added in v0.4.0

type Service interface {
	Register(grpc.ServiceRegistrar)
}

type StateUpdateEvent

type StateUpdateEvent struct {
	State ServerState `json:"state"`
}

type States added in v0.6.0

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

func NewStates added in v0.6.0

func NewStates(state ServerState) (*States, error)

func (*States) Get added in v0.6.0

func (s *States) Get() ServerState

func (*States) HandleEvent added in v0.6.0

func (s *States) HandleEvent(event Event) (Event, bool)

type Stopper added in v0.4.0

type Stopper func(Wrapper) error

type Task added in v0.4.0

type Task interface {
	Name() string
	Run(context.Context, Wrapper) error
}

type Wrapper

type Wrapper interface {
	Files() fs.FS
	WriteStdin(command string) error
	SendSignal(signal os.Signal) error
	SubscribeLogs() pubsub.Subscriber[string]
	SubscribeEvents() pubsub.Subscriber[Event]
	EmitEvent(event any)
	GetState() ServerState
	SubscribeStates() pubsub.Subscriber[ServerState]
	UpdateState(func(ServerState) ServerState)
	Logger() *slog.Logger
	GetServerConfig() (Map, error)
}

func FromContext added in v0.3.0

func FromContext(ctx context.Context) (Wrapper, error)

type WrapperContext added in v0.3.0

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

func (*WrapperContext) EmitEvent added in v0.6.0

func (wp *WrapperContext) EmitEvent(event any)

func (*WrapperContext) Files added in v0.6.0

func (wp *WrapperContext) Files() fs.FS

func (*WrapperContext) GetServerConfig added in v0.6.0

func (wp *WrapperContext) GetServerConfig() (Map, error)

func (*WrapperContext) GetState added in v0.6.0

func (wp *WrapperContext) GetState() ServerState

func (*WrapperContext) Logger added in v0.6.0

func (wp *WrapperContext) Logger() *slog.Logger

func (*WrapperContext) SendSignal added in v0.3.0

func (wp *WrapperContext) SendSignal(signal os.Signal) error

func (*WrapperContext) SubscribeEvents added in v0.3.0

func (wp *WrapperContext) SubscribeEvents() pubsub.Subscriber[Event]

func (*WrapperContext) SubscribeLogs added in v0.3.0

func (wp *WrapperContext) SubscribeLogs() pubsub.Subscriber[string]

func (*WrapperContext) SubscribeStates added in v0.3.0

func (wp *WrapperContext) SubscribeStates() pubsub.Subscriber[ServerState]

func (*WrapperContext) UpdateState added in v0.6.0

func (wp *WrapperContext) UpdateState(updateFn func(ServerState) ServerState)

func (*WrapperContext) WriteStdin added in v0.6.0

func (wp *WrapperContext) WriteStdin(command string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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