astikit

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2019 License: MIT Imports: 11 Imported by: 243

README

Astikit is a set of golang helpers that don't require any external dependencies.

Documentation

Index

Constants

View Source
const (
	ExecStatusCrashed = "crashed"
	ExecStatusRunning = "running"
	ExecStatusStopped = "stopped"
)

Statuses

Variables

This section is empty.

Functions

func ServeHTTP added in v0.0.2

func ServeHTTP(w *Worker, o ServeHTTPOptions)

ServeHTTP spawns an HTTP server

func Sleep

func Sleep(ctx context.Context, d time.Duration) (err error)

Sleep is a cancellable sleep

Types

type ExecCmdOptions added in v0.0.2

type ExecCmdOptions struct {
	Args       []string
	CmdAdapter func(cmd *exec.Cmd, h *ExecHandler) error
	Name       string
	StopFunc   func(cmd *exec.Cmd) error
}

ExecCmdOptions represents exec options

type ExecHandler added in v0.0.2

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

ExecHandler represents an object capable of handling the execution of a cmd

func ExecCmd added in v0.0.2

func ExecCmd(w *Worker, o ExecCmdOptions) (h *ExecHandler, err error)

ExecCmd executes a cmd The process will be stopped when the worker stops

func (*ExecHandler) Status added in v0.0.2

func (h *ExecHandler) Status() string

func (*ExecHandler) Stop added in v0.0.2

func (h *ExecHandler) Stop()

type Logger added in v0.0.2

type Logger interface {
	Debugf(format string, v ...interface{})
	Error(v ...interface{})
	Info(v ...interface{})
	Infof(format string, v ...interface{})
}

type ServeHTTPOptions added in v0.0.2

type ServeHTTPOptions struct {
	Addr    string
	Handler http.Handler
}

ServeHTTPOptions represents serve options

type SignalHandler added in v0.0.2

type SignalHandler func(s os.Signal)

SignalHandler represents a func that can handle a signal

func TermSignalHandler added in v0.0.2

func TermSignalHandler(f func()) SignalHandler

TermSignalHandler returns a SignalHandler that is executed only on a term signal

type Task added in v0.0.2

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

Task represents a task

func (*Task) Do added in v0.0.2

func (t *Task) Do(f func())

Do executes the task

func (*Task) Done added in v0.0.2

func (t *Task) Done()

Done indicates the task is done

func (*Task) NewSubTask added in v0.0.2

func (t *Task) NewSubTask() *Task

NewSubTask creates a new sub task

func (*Task) Wait added in v0.0.2

func (t *Task) Wait()

Wait waits for the task to be finished

type TaskFunc added in v0.0.2

type TaskFunc func() *Task

TaskFunc represents a function that can create a new task

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp represents a timestamp you can marshal and umarshal

func NewTimestamp

func NewTimestamp(t time.Time) *Timestamp

NewTimestamp creates a new timestamp

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSONMarshaler interface

func (Timestamp) MarshalText

func (t Timestamp) MarshalText() (text []byte, err error)

MarshalText implements the TextMarshaler interface

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(text []byte) error

UnmarshalJSON implements the JSONUnmarshaler interface

func (*Timestamp) UnmarshalText

func (t *Timestamp) UnmarshalText(text []byte) (err error)

UnmarshalText implements the TextUnmarshaler interface

type Worker added in v0.0.2

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

Worker represents an object capable of blocking, handling signals and stopping

func NewWorker added in v0.0.2

func NewWorker(l Logger) (w *Worker)

NewWorker builds a new worker

func (*Worker) Context added in v0.0.2

func (w *Worker) Context() context.Context

Context returns the worker's context

func (*Worker) HandleSignals added in v0.0.2

func (w *Worker) HandleSignals(hs ...SignalHandler)

HandleSignals handles signals

func (*Worker) Logger added in v0.0.2

func (w *Worker) Logger() Logger

Logger returns the worker's logger

func (*Worker) NewTask added in v0.0.2

func (w *Worker) NewTask() *Task

NewTask creates a new task

func (*Worker) Stop added in v0.0.2

func (w *Worker) Stop()

Stop stops the Worker

func (*Worker) Wait added in v0.0.2

func (w *Worker) Wait()

Wait is a blocking pattern

Jump to

Keyboard shortcuts

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