app

package
v0.0.0-...-9c55465 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvLocal = "local"
	EnvDev   = "dev"
	EnvTest  = "test"
	EnvPre   = "pre"
	EnvProd  = "prod"
)

Env names

View Source
const (
	ObjCli = "cli"
	ObjRux = "rux"

	ObjConf = "config"
	ObjLog  = "logger"

	ObjPlugin = "plugin"
	ObjScript = "script"

	ObjGit  = "git"
	ObjGlab = "gitlab"
	ObjGhub = "github"
)

Variables

View Source
var (
	// PathMarkPrefixes allowed path name prefix mark.
	PathMarkPrefixes = []byte{'$', '#', '@'}

	OSPathSepChar = uint8(os.PathSeparator)
	OSPathSepStr  = string(os.PathSeparator)
)

some special chars

View Source
var (
	// L kite logger
	L *slog.Logger
	// CL kite console logger
	CL *slog.Logger
	// SL server logger
	SL *slog.Logger
)
View Source
var (
	Lcp *lcproxy.LocalProxy

	Scripts *kscript.Runner
	Plugins *kiteext.PluginRunner

	QJump *quickjump.QuickJump

	// PathMap data
	PathMap *kiteext.PathMap
	OpenMap maputil.Aliases

	Vars *kiteext.VarMap
	HTpl *httptpl.Manager
)
View Source
var (
	KiteVerbose = sysutil.Getenv(appconst.EnvKiteVerbose, slog.WarnLevel.LowerName())
)

Functions

func Add

func Add[T any](name string, obj T)

Add object by name

func Cfg

func Cfg() *config.Config

Cfg get the config object

func Cli

func Cli() *gcli.App

Cli get the cli app

func Get

func Get[T any](name string) T

Get object by name, if not exists will panic

func GetAny

func GetAny(name string) any

GetAny value from box

func Ghub

func Ghub() *github.GitHub

Ghub get

func Gitx

func Gitx() *gitx.Config

Gitx get

func Glab

func Glab() *gitlab.GitLab

Glab get

func Has

func Has(name string) bool

Has object by name

func HasAliasMark

func HasAliasMark(path string) bool

HasAliasMark check path string, start one of PathMarkPrefixes

func IsDebug

func IsDebug() bool

IsDebug mode

func Log

func Log() *slog.Logger

Log get

func Lookup

func Lookup[T any](name string) (v T, ok bool)

Lookup object by name

func Names

func Names() []string

Names object name list from box

func Run

func Run()

Run app

func Rux

func Rux() *rux.Router

Rux get the web app

func Set

func Set[T any](name string, obj T)

Set object by name

Types

type BootChecker

type BootChecker interface {
	// BeforeBoot check something before boot run
	BeforeBoot() bool
}

BootChecker for app start boot.

type BootFunc

type BootFunc func(ka *KiteApp) error

BootFunc for application

func (BootFunc) Boot

func (fn BootFunc) Boot(ka *KiteApp) error

Boot do something

type BootLoader

type BootLoader interface {
	// Boot do something before application run
	Boot(ka *KiteApp) error
}

BootLoader for app start boot.

type Config

type Config struct {

	// BaseDir base data dir
	BaseDir string `json:"base_dir" default:"${KITE_BASE_DIR}"`
	// TmpDir tmp dir
	TmpDir string `json:"tmp_dir"`
	// DataDir tmp dir
	DataDir string `json:"data_dir"`
	// CacheDir cache dir
	CacheDir string `json:"cache_dir"`
	// ConfigDir config dir
	ConfigDir string `json:"config_dir"`
	// ResourceDir resource dir
	ResourceDir string `json:"resource_dir"`
	// IncludeConfig include config files.
	// default file path relative the config_dir
	IncludeConfig []string `json:"include_config"`
	// contains filtered or unexported fields
}

Config struct of app

Gen by:

kite go gen st -s @c -t json --name Conf

func (*Config) CachePath

func (c *Config) CachePath(subPaths ...string) string

CachePath build and get full path relative the cache dir.

func (*Config) ConfFile

func (c *Config) ConfFile() string

ConfFile get main config file

func (*Config) ConfigPath

func (c *Config) ConfigPath(subPaths ...string) string

ConfigPath build and get full path relative the config dir.

func (*Config) DotenvFile

func (c *Config) DotenvFile() string

DotenvFile path

func (*Config) HasAliasMark

func (c *Config) HasAliasMark(path string) bool

HasAliasMark check has alias mark

func (*Config) IsPathAlias

func (c *Config) IsPathAlias(name string) bool

IsPathAlias check is path alias name, without prefix char.

func (*Config) Path

func (c *Config) Path(subPaths ...string) string

Path build and get full path relative the base dir.

func (*Config) PathBuild

func (c *Config) PathBuild(subPaths ...string) string

PathBuild build and get full path relative the base dir.

func (*Config) PathByName

func (c *Config) PathByName(name string) string

PathByName get path by alias name

func (*Config) PathResolve

func (c *Config) PathResolve(path string) string

PathResolve resolve path alias. "$base/tmp" => "path/to/base_dir/tmp"

func (*Config) ResolvePath

func (c *Config) ResolvePath(path string) string

ResolvePath alias name.

func (*Config) SetDotenvFile

func (c *Config) SetDotenvFile(dotenvFile string)

SetDotenvFile path

func (*Config) TmpPath

func (c *Config) TmpPath(subPaths ...string) string

TmpPath build and get full path relative the tmp dir.

type Info

type Info struct {
	Branch    string
	Version   string
	Revision  string
	GoVersion string
	BuildDate string
	PublishAt string
	UpdatedAt string
}

Info for kite app

type KiteApp

type KiteApp struct {
	*Info
	*Config
	*gcli.Context
	// AfterPreFn hook on after app pre-bootloaders booted
	AfterPreFn func(ka *KiteApp) error
	// contains filtered or unexported fields
}

KiteApp kite app container

func App

func App() *KiteApp

App instance

func (*KiteApp) AddBootFuncs

func (ka *KiteApp) AddBootFuncs(bfs ...BootFunc) *KiteApp

AddBootFuncs to app

func (*KiteApp) AddLoader

func (ka *KiteApp) AddLoader(bl BootLoader) *KiteApp

AddLoader to app

func (*KiteApp) AddLoaders

func (ka *KiteApp) AddLoaders(bls ...BootLoader) *KiteApp

AddLoaders to app

func (*KiteApp) AddPreLoader

func (ka *KiteApp) AddPreLoader(bfs ...BootFunc) *KiteApp

AddPreLoader to app

func (*KiteApp) Boot

func (ka *KiteApp) Boot() error

Boot app start

func (*KiteApp) InitPaths

func (ka *KiteApp) InitPaths()

InitPaths for app

func (*KiteApp) OnShutdown

func (ka *KiteApp) OnShutdown(fn func())

OnShutdown handler.

func (*KiteApp) SetConfFile

func (ka *KiteApp) SetConfFile(file string)

SetConfFile path.

type StdLoader

type StdLoader struct {
	BeforeFn func() bool
	BootFn   BootFunc
}

StdLoader struct

func NewStdLoader

func NewStdLoader(fn BootFunc) *StdLoader

NewStdLoader instance

func (*StdLoader) BeforeBoot

func (l *StdLoader) BeforeBoot() bool

BeforeBoot handle

func (*StdLoader) Boot

func (l *StdLoader) Boot(ka *KiteApp) error

Boot handle

func (*StdLoader) WithBeforeFn

func (l *StdLoader) WithBeforeFn(fn func() bool) *StdLoader

WithBeforeFn handle

Jump to

Keyboard shortcuts

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