astikit

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2019 License: MIT Imports: 16 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

View Source
const (
	ChanFIFOOrder = "fifo"
	ChanFILOOrder = "filo"
)

Orders

Variables

This section is empty.

Functions

func BoolPtr added in v0.0.3

func BoolPtr(i bool) *bool

BoolPtr transforms a bool into a *bool

func BytePtr added in v0.0.3

func BytePtr(i byte) *byte

BytePtr transforms a byte into a *byte

func ChainHTTPMiddlewares added in v0.0.3

func ChainHTTPMiddlewares(h http.Handler, ms ...HTTPMiddleware) http.Handler

ChainHTTPMiddlewares chains HTTP middlewares

func ChainHTTPMiddlewaresWithPrefix added in v0.0.3

func ChainHTTPMiddlewaresWithPrefix(h http.Handler, prefixes []string, ms ...HTTPMiddleware) http.Handler

ChainHTTPMiddlewaresWithPrefix chains HTTP middlewares if one of prefixes is present

func ConvertPCMBitDepth added in v0.0.3

func ConvertPCMBitDepth(srcSample int, srcBitDepth, dstBitDepth int) (dstSample int, err error)

ConvertPCMBitDepth converts the PCM bit depth

func DurationPtr added in v0.0.3

func DurationPtr(i time.Duration) *time.Duration

DurationPtr transforms a time.Duration into a *time.Duration

func Float64Ptr added in v0.0.3

func Float64Ptr(i float64) *float64

Float64Ptr transforms a float64 into a *float64

func Int64Ptr added in v0.0.3

func Int64Ptr(i int64) *int64

Int64Ptr transforms an int64 into an *int64

func IntPtr added in v0.0.3

func IntPtr(i int) *int

IntPtr transforms an int into an *int

func PCMNormalize added in v0.0.3

func PCMNormalize(samples []int, bitDepth int) (o []int)

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

func StrPtr added in v0.0.3

func StrPtr(i string) *string

StrPtr transforms a string into a *string

func UInt8Ptr added in v0.0.3

func UInt8Ptr(i uint8) *uint8

UInt8Ptr transforms a uint8 into a *uint8

func UInt32Ptr added in v0.0.3

func UInt32Ptr(i uint32) *uint32

UInt32Ptr transforms a uint32 into a *uint32

Types

type Chan added in v0.0.3

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

Chan is an object capable of doing stuff in a specific order without blocking when adding new items in the queue

func NewChan added in v0.0.3

func NewChan(o ChanOptions) *Chan

NewChan creates a new Chan

func (*Chan) Add added in v0.0.3

func (c *Chan) Add(fn func())

Add adds a new item to the chan

func (*Chan) Reset added in v0.0.3

func (c *Chan) Reset()

Reset resets the chan

func (*Chan) Start added in v0.0.3

func (c *Chan) Start(ctx context.Context)

Start starts the chan by looping through functions in the buffer and executing them if any, or waiting for a new one otherwise

func (*Chan) Stop added in v0.0.3

func (c *Chan) Stop()

Stop stops the chan

type ChanOptions added in v0.0.3

type ChanOptions struct {
	Order string
	// By default the funcs not yet processed when the context is cancelled are dropped.
	// If ProcessAll is true ALL funcs are processed even after the context is cancelled.
	// However, no funcs can be added after the context is cancelled
	ProcessAll bool
}

ChanOptions are Chan options

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 HTTPMiddleware added in v0.0.3

type HTTPMiddleware func(http.Handler) http.Handler

HTTPMiddleware represents an HTTP middleware

func HTTPMiddlewareBasicAuth added in v0.0.3

func HTTPMiddlewareBasicAuth(username, password string) HTTPMiddleware

HTTPMiddlewareBasicAuth adds basic HTTP auth to an HTTP handler

func HTTPMiddlewareContentType added in v0.0.3

func HTTPMiddlewareContentType(contentType string) HTTPMiddleware

HTTPMiddlewareContentType adds a content type to an HTTP handler

type Limiter added in v0.0.3

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

Limiter represents a limiter

func NewLimiter added in v0.0.3

func NewLimiter() *Limiter

NewLimiter creates a new limiter

func (*Limiter) Add added in v0.0.3

func (l *Limiter) Add(name string, cap int, period time.Duration) *LimiterBucket

Add adds a new bucket

func (*Limiter) Bucket added in v0.0.3

func (l *Limiter) Bucket(name string) (b *LimiterBucket, ok bool)

Bucket retrieves a bucket from the limiter

func (*Limiter) Close added in v0.0.3

func (l *Limiter) Close()

Close closes the limiter properly

type LimiterBucket added in v0.0.3

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

LimiterBucket represents a limiter bucket

func (*LimiterBucket) Close added in v0.0.3

func (b *LimiterBucket) Close()

close closes the bucket properly

func (*LimiterBucket) Inc added in v0.0.3

func (b *LimiterBucket) Inc() bool

Inc increments the bucket count

type Logger added in v0.0.2

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

type PCMChannelsConverter added in v0.0.3

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

func NewPCMChannelsConverter added in v0.0.3

func NewPCMChannelsConverter(srcNumChannels, dstNumChannels int, fn PCMSampleFunc) *PCMChannelsConverter

func (*PCMChannelsConverter) Add added in v0.0.3

func (c *PCMChannelsConverter) Add(i int) (err error)

func (*PCMChannelsConverter) Reset added in v0.0.3

func (c *PCMChannelsConverter) Reset()

type PCMSampleFunc added in v0.0.3

type PCMSampleFunc func(s int) error

type PCMSampleRateConverter added in v0.0.3

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

func NewPCMSampleRateConverter added in v0.0.3

func NewPCMSampleRateConverter(srcSampleRate, dstSampleRate, numChannels int, fn PCMSampleFunc) *PCMSampleRateConverter

func (*PCMSampleRateConverter) Add added in v0.0.3

func (c *PCMSampleRateConverter) Add(i int) (err error)

func (*PCMSampleRateConverter) Reset added in v0.0.3

func (c *PCMSampleRateConverter) Reset()

type PCMSilenceDetector added in v0.0.3

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

PCMSilenceDetector represents a PCM silence detector

func NewPCMSilenceDetector added in v0.0.3

func NewPCMSilenceDetector(o PCMSilenceDetectorOptions) (d *PCMSilenceDetector)

NewPCMSilenceDetector creates a new silence detector

func (*PCMSilenceDetector) Add added in v0.0.3

func (d *PCMSilenceDetector) Add(samples []int) (validSamples [][]int)

Add adds samples to the buffer and checks whether there are valid samples between silences

func (*PCMSilenceDetector) Reset added in v0.0.3

func (d *PCMSilenceDetector) Reset()

Reset resets the silence detector

type PCMSilenceDetectorOptions added in v0.0.3

type PCMSilenceDetectorOptions struct {
	MaxSilenceLevel    float64       `toml:"max_silence_level"`
	MinSilenceDuration time.Duration `toml:"min_silence_duration"`
	SampleRate         int           `toml:"sample_rate"`
	StepDuration       time.Duration `toml:"step_duration"`
}

PCMSilenceDetectorOptions represents a PCM silence detector options

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 Templater added in v0.0.3

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

Templater represents an object capable of storing and parsing templates

func NewTemplater added in v0.0.3

func NewTemplater() *Templater

NewTemplater creates a new templater

func (*Templater) AddLayout added in v0.0.3

func (t *Templater) AddLayout(c string)

AddLayout adds a new layout

func (*Templater) AddLayoutsFromDir added in v0.0.3

func (t *Templater) AddLayoutsFromDir(dirPath, ext string) (err error)

AddLayoutsFromDir walks through a dir and add files as layouts

func (*Templater) AddTemplate added in v0.0.3

func (t *Templater) AddTemplate(path, content string) (err error)

AddTemplate adds a new template

func (*Templater) AddTemplatesFromDir added in v0.0.3

func (t *Templater) AddTemplatesFromDir(dirPath, ext string) (err error)

AddTemplatesFromDir walks through a dir and add files as templates

func (*Templater) DelTemplate added in v0.0.3

func (t *Templater) DelTemplate(path string)

DelTemplate deletes a template

func (*Templater) Parse added in v0.0.3

func (t *Templater) Parse(content string) (o *template.Template, err error)

Parse parses the content of a template

func (*Templater) Template added in v0.0.3

func (t *Templater) Template(path string) (tpl *template.Template, ok bool)

Template retrieves a templates

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(o WorkerOptions) (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

type WorkerOptions added in v0.0.3

type WorkerOptions struct {
	Logger Logger
}

WorkerOptions represents worker options

type WriterAdapter added in v0.0.3

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

WriterAdapter represents an object that can adapt a Writer

func NewWriterAdapter added in v0.0.3

func NewWriterAdapter(o WriterAdapterOptions) *WriterAdapter

NewWriterAdapter creates a new WriterAdapter

func (*WriterAdapter) Close added in v0.0.3

func (w *WriterAdapter) Close()

Close closes the adapter properly

func (*WriterAdapter) Write added in v0.0.3

func (w *WriterAdapter) Write(i []byte) (n int, err error)

Write implements the io.Writer interface

type WriterAdapterOptions added in v0.0.3

type WriterAdapterOptions struct {
	Callback func(i []byte)
	Split    []byte
}

WriterAdapterOptions represents WriterAdapter options

Jump to

Keyboard shortcuts

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