juniper

package module
v0.0.0-...-1c40d70 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CliUsage

func CliUsage(title, description, binName string, register CliCommandEntries) func()

CliUsage generator for the flags lib

func DBTransactionMiddleware

func DBTransactionMiddleware(db *gorm.DB) gin.HandlerFunc

DBTransactionMiddleware handles the create, commit and rollback steps of a gorm transaction for each gin http request

func PreloadDBModels

func PreloadDBModels(db *gorm.DB, preload []string) *gorm.DB

PreloadDBModels updates the db transaction with assigned model preloads

func TxHandle

func TxHandle(ctx context.Context) *gorm.DB

TxHandle gets the gorm transaction handler from the gin context

Types

type CliCommandEntries

type CliCommandEntries []CliCommandEntry

CommandEntries list

func (CliCommandEntries) Find

func (ces CliCommandEntries) Find(key string) *CliCommandEntry

Find a command entry by its key

type CliCommandEntry

type CliCommandEntry struct {
	Key   string
	Usage string
	Run   CliCommandFunc
}

type CliCommandFunc

type CliCommandFunc func(args []string) error

type CronErrors

type CronErrors map[string]error

func RunCronTasks

func RunCronTasks(tasks []CronTask, register CliCommandEntries) CronErrors

RunCranTasks that have hit their trigger

func (CronErrors) Error

func (ce CronErrors) Error() string

Error implementation keeps CronErrors adheering to the error interface

type CronTask

type CronTask struct {
	Command  string   ` yaml:"command" validate:"required"`
	Schedule string   ` yaml:"schedule" validate:"required"`
	Args     []string `yaml:"args"`
}

func ParseCronSchedule

func ParseCronSchedule(configPath string) ([]CronTask, error)

ParseCronSchedule file by its file path

func (CronTask) ShouldRun

func (task CronTask) ShouldRun(now time.Time) bool

shouldRun checks if the given time matches the schedule set on the task

type Model

type Model struct {
	ID        ModelId `gorm:"primaryKey"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

Model is the basis for a database model

type ModelId

type ModelId int

func (ModelId) String

func (i ModelId) String() string

String implements fmt.Stringer

type SoftDeleteModel

type SoftDeleteModel struct {
	ID        ModelId `gorm:"primaryKey"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt
}

SoftDeleteModel is the basis for a database model with soft delete functionality

Jump to

Keyboard shortcuts

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