golaze

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 14 Imported by: 3

README

Golaze

Golaze is a personal toolkit for Golang, designed for easy and simple applications. It includes a collection of favorite packages for personal projects, prioritizing coding convenience over wide compatibility. It's not intended for heavy-duty applications but for smoothing out the coding process.

License

The project is licensed under the MIT license.

About

The toolkit is created to facilitate personal Golang projects, making development smoother by including essential packages.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONError

func JSONError(w http.ResponseWriter, msg string, code int)

func JSONResponse

func JSONResponse(w http.ResponseWriter, data interface{}, code int)

func LivenessHandler

func LivenessHandler(hooks ...func() error) func(w http.ResponseWriter, r *http.Request)

func LogMiddleware added in v0.2.0

func LogMiddleware(next http.Handler) http.Handler

func NewAuthMiddleware added in v0.2.0

func NewAuthMiddleware(getAuthTokens func() ([]*AuthToken, error)) func(http.Handler) http.Handler

func NewLogger added in v0.2.0

func NewLogger() zerolog.Logger

func NewRouter added in v0.2.0

func NewRouter() *chi.Mux

func ReadinessHandler

func ReadinessHandler(hooks ...func() error) func(w http.ResponseWriter, r *http.Request)

Types

type App

type App struct {
	*AppConfig
}

func NewApp

func NewApp(config *AppConfig) *App

func (*App) AddWorker added in v0.2.0

func (app *App) AddWorker(worker *Worker)

func (*App) Run

func (app *App) Run() error

type AppConfig

type AppConfig struct {
	Name        string
	Version     string
	LogLevel    zerolog.Level
	HealthCheck *HealthCheck
	WebApp      *WebApp
	Worker      *Worker
}

type AuthToken added in v0.2.0

type AuthToken struct {
	Token string
}

type Event added in v0.2.0

type Event struct {
	Data interface{}
}

type EventBus added in v0.2.0

type EventBus struct {
	*EventBusConfig
}

func NewEventBus added in v0.2.0

func NewEventBus(config *EventBusConfig) *EventBus

func (*EventBus) Publish added in v0.2.0

func (eb *EventBus) Publish(eventType string, event *Event)

func (*EventBus) Subscribe added in v0.2.0

func (eb *EventBus) Subscribe(eventType string, handler EventBusHandler)

func (*EventBus) Unsubscribe added in v0.2.0

func (eb *EventBus) Unsubscribe(eventType string, handler EventBusHandler)

type EventBusConfig added in v0.2.0

type EventBusConfig struct {
	Subscribers map[string][]EventBusHandler
	Shutdown    chan bool
	// contains filtered or unexported fields
}

type EventBusHandler added in v0.2.0

type EventBusHandler interface {
	Handle(event *Event) error
}

type HealthCheck

type HealthCheck struct {
	*HealthCheckConfig
}

func NewHealthCheck

func NewHealthCheck(config *HealthCheckConfig) *HealthCheck

type HealthCheckConfig

type HealthCheckConfig struct {
	Port           string
	LivenessHooks  []func() error
	ReadinessHooks []func() error
	Router         *chi.Mux
}

type State added in v0.2.0

type State struct {
	Data map[string]interface{}
	// contains filtered or unexported fields
}

func (*State) Clear added in v0.2.0

func (s *State) Clear()

func (*State) Context added in v0.2.0

func (s *State) Context() context.Context

func (*State) Delete added in v0.2.0

func (s *State) Delete(key string)

func (*State) Get added in v0.2.0

func (s *State) Get(key string) interface{}

func (*State) Set added in v0.2.0

func (s *State) Set(key string, value interface{})

type Task added in v0.2.0

type Task struct {
	*TaskConfig
}

func NewTask added in v0.2.0

func NewTask(config *TaskConfig) *Task

func (*Task) IsRunning added in v0.2.0

func (t *Task) IsRunning() bool

func (*Task) Run added in v0.2.0

func (t *Task) Run(state *State)

type TaskConfig added in v0.2.0

type TaskConfig struct {
	Name          string
	Exec          func(state *State) error
	MaxRetries    int
	RetryInterval time.Duration
	Repeat        int // -1 for infinite, 0 for no repeat, > 0 for n times
	RepeatDelay   time.Duration
	Timeout       time.Duration
	RunHistory    []time.Time

	Done chan bool
}

type WebApp added in v0.2.0

type WebApp struct {
	*WebAppConfig
}

func NewWebApp added in v0.2.0

func NewWebApp(config *WebAppConfig) *WebApp

type WebAppConfig added in v0.2.0

type WebAppConfig struct {
	Port   string
	Router *chi.Mux
}

type Worker added in v0.2.0

type Worker struct {
	*WorkerConfig
}

func NewWorker added in v0.2.0

func NewWorker(config *WorkerConfig) *Worker

func (*Worker) AddTask added in v0.2.0

func (w *Worker) AddTask(task *Task) error

func (*Worker) RemoveTask added in v0.2.0

func (w *Worker) RemoveTask(task *Task) error

func (*Worker) Start added in v0.2.0

func (w *Worker) Start()

Start the worker non-blocking

func (*Worker) Stop added in v0.2.0

func (w *Worker) Stop()

type WorkerConfig added in v0.2.0

type WorkerConfig struct {
	Tasks           []*Task
	Shutdown        chan bool
	State           *State
	ConcurrentTasks int
	// contains filtered or unexported fields
}

Directories

Path Synopsis
examples
web_app Module

Jump to

Keyboard shortcuts

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