rkentry

package
Version: v2.2.11 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: Apache-2.0 Imports: 48 Imported by: 72

Documentation

Index

Constants

View Source
const (

	// CertEntryType public access
	CertEntryType = "CertEntry"
	// ConfigEntryType public access
	ConfigEntryType = "ConfigEntry"
	// EventEntryType public access
	EventEntryType = "EventEntry"
	// LoggerEntryType public access
	LoggerEntryType = "LoggerEntry"
	// CommonServiceEntryType public access
	CommonServiceEntryType = "CommonServiceEntry"
	// SWEntryType public access
	SWEntryType = "SWEntry"
	// StaticFileHandlerEntryType public access
	StaticFileHandlerEntryType = "StaticFileHandlerEntry"
	// PromEntryType public access
	PromEntryType = "PromEntry"
	// DocsEntryType public access
	DocsEntryType      = "DocsEntry"
	SignerJwtEntryType = "SignerJwtEntry"
	CryptoEntryType    = "CryptoEntry"
	PProfEntryType     = "PProfEntry"
)

Variables

View Source
var (
	// GlobalAppCtx global application context
	GlobalAppCtx = &appContext{
		startTime: time.Now(),
		entries: map[string]map[string]Entry{
			appInfoEntryType: {
				appInfoEntryName: appInfoEntryDefault(),
			},
		},
		embedFS:       map[string]map[string]*embed.FS{},
		appInfoEntry:  appInfoEntryDefault(),
		shutdownSig:   make(chan os.Signal),
		shutdownHooks: make(map[string]ShutdownHook),
		userValues:    make(map[string]interface{}),
	}

	LoggerEntryNoop   = NewLoggerEntryNoop()
	LoggerEntryStdout = NewLoggerEntryStdout()
	EventEntryNoop    = NewEventEntryNoop()
	EventEntryStdout  = NewEventEntryStdout()
)

Functions

func BootstrapBuiltInEntryFromYAML added in v2.2.0

func BootstrapBuiltInEntryFromYAML(raw []byte)

BootstrapBuiltInEntryFromYAML register and bootstrap builtin entries first

func BootstrapPluginEntryFromYAML added in v2.2.0

func BootstrapPluginEntryFromYAML(raw []byte)

BootstrapPluginEntryFromYAML register and bootstrap plugin entries first

func BootstrapUserEntryFromYAML added in v2.2.0

func BootstrapUserEntryFromYAML(raw []byte)

BootstrapUserEntryFromYAML register and bootstrap builtin entries first

func BootstrapWebFrameEntryFromYAML added in v2.2.0

func BootstrapWebFrameEntryFromYAML(raw []byte)

BootstrapWebFrameEntryFromYAML register and bootstrap web framework entries first

func IsValidDomain added in v2.1.0

func IsValidDomain(domain string) bool

IsValidDomain mainly used in entry config.

func RegisterAsymmetricJwtSigner added in v2.0.5

func RegisterAsymmetricJwtSigner(entryName, algo string, privPEM, pubPEM []byte) *asymmetricJwtSigner

RegisterAsymmetricJwtSigner create asymmetricJwtSigner

func RegisterCertEntryYAML

func RegisterCertEntryYAML(raw []byte) map[string]Entry

RegisterCertEntryYAML register function

func RegisterConfigEntryYAML

func RegisterConfigEntryYAML(raw []byte) map[string]Entry

RegisterConfigEntryYAML register function

func RegisterEventEntryYAML

func RegisterEventEntryYAML(raw []byte) map[string]Entry

RegisterEventEntryYAML register function

func RegisterLoggerEntryYAML

func RegisterLoggerEntryYAML(raw []byte) map[string]Entry

RegisterLoggerEntryYAML register function

func RegisterPluginRegFunc added in v2.2.0

func RegisterPluginRegFunc(regFunc RegFunc)

RegisterPluginRegFunc register rk plugins registration function. Call this while you need provided Entry needs to be registered and bootstrapped before user defined Entries.

func RegisterSymmetricJwtSigner added in v2.0.5

func RegisterSymmetricJwtSigner(entryName, algo string, rawKey []byte) *symmetricJwtSigner

RegisterSymmetricJwtSigner create symmetricJwtSigner

func RegisterUserEntryRegFunc added in v2.2.0

func RegisterUserEntryRegFunc(regFunc RegFunc)

RegisterUserEntryRegFunc register user defined registration function. Call this while you need provided Entry needs to be registered and bootstrapped before user defined Entries.

func RegisterWebFrameRegFunc added in v2.2.0

func RegisterWebFrameRegFunc(regFunc RegFunc)

RegisterWebFrameRegFunc register rk web framework registration function. Call this while you need provided Entry needs to be registered and bootstrapped before user defined Entries.

func ShutdownWithError

func ShutdownWithError(err error)

ShutdownWithError shuts down and panic.

func UnmarshalBootYAML

func UnmarshalBootYAML(raw []byte, config interface{})

UnmarshalBootYAML this function will parse boot config file with ENV and pflag overrides.

User who want to implement his/her own entry, may use this function to parse YAML config into struct. This function would also parse --rkset flags.

This function would do the following: 1: Read config file and unmarshal content into a map. 2: Read --rkset flags and override values in map unmarshalled at above step. 3: Unmarshal map into user provided struct.

[Flag]: Override boot config value with flag of rkset:

pflag.FlagSet which contains rkset as key.

Receives flattened boot config file(YAML) keys and override them in provided boot config. We follow the way of HELM does while overriding keys, refer to https://helm.sh/docs/intro/using_helm/ example:

Lets assuming we have boot config YAML file as bellow:

example-boot.yaml: gin:

  • port: 1949 commonService: enabled: true

We can override values in example-boot.yaml file as bellow:

./your_compiled_binary --rkset "gin[0].port=2008,gin[0].commonService.enabled=false"

Basic rules: 1: Using comma(,) to separate different k/v section. 2: Using [index] to access arrays in YAML file. 3: Using equal sign(=) to distinguish key and value. 4: Using dot(.) to access map in YAML file.

[Environment variable]: Override boot config value

Prefix of "RK" will be used as environment variable key. The schema follows above.

example-boot.yaml: gin:

  • port: 1949 commonService: enabled: true

We can override values in example-boot.yaml file as bellow:

os.Setenv("RK_GIN_0_PORT", "2008") os.Setenv("RK_GIN_0_COMMONSERVICE_ENABLED", "false")

./your_compiled_binary

Important! Please make sure the type of value keeps the same, otherwise, it won't override. For example, os.Setenv("RK_GIN_0_PORT", "invalid-port") won't success, but keep original value.

Types

type BootCert

type BootCert struct {
	Cert []*BootCertE `yaml:"cert" json:"cert"`
}

BootCert is bootstrap config of CertEntry.

type BootCertE

type BootCertE struct {
	Name        string `yaml:"name" json:"name"`
	Description string `yaml:"description" json:"description"`
	Domain      string `yaml:"domain" json:"domain"`
	CAPath      string `yaml:"caPath" json:"caPath"`
	CertPemPath string `yaml:"certPemPath" json:"certPemPath"`
	KeyPemPath  string `yaml:"keyPemPath" json:"keyPemPath"`
}

BootCertE element of CertEntry

type BootCommonService

type BootCommonService struct {
	Enabled    bool   `yaml:"enabled" json:"enabled"`
	PathPrefix string `yaml:"pathPrefix" json:"pathPrefix"`
}

BootCommonService Bootstrap config of common service.

type BootConfig

type BootConfig struct {
	Config []*BootConfigE `yaml:"config" json:"config"`
}

BootConfig is bootstrap config of ConfigEntry information.

type BootConfigE

type BootConfigE struct {
	Name        string                 `yaml:"name" json:"name"`
	Description string                 `yaml:"description" json:"description"`
	Domain      string                 `yaml:"domain" json:"domain"`
	Path        string                 `yaml:"path" json:"name"`
	EnvPrefix   string                 `yaml:"envPrefix" json:"envPrefix"`
	Content     map[string]interface{} `yaml:"content" json:"content"`
}

BootConfigE element of ConfigEntry

type BootDocs

type BootDocs struct {
	Enabled  bool     `yaml:"enabled" json:"enabled"`
	Path     string   `yaml:"path" json:"path"`
	SpecPath string   `yaml:"specPath" json:"specPath"`
	Headers  []string `yaml:"headers" json:"headers"`
	Style    struct {
		Theme string `yaml:"theme" json:"theme"`
	} `yaml:"style" json:"style"`
	Debug bool `yaml:"debug" json:"debug"`
}

BootDocs Bootstrap config of swagger. 1: Enabled: Enable swagger. 2: Path: Swagger path accessible from restful API. 3: SpecPath: The path of where swagger or open API spec file was located. 4: Headers: The headers that would be added into each API response.

type BootEvent

type BootEvent struct {
	Event []*BootEventE `yaml:"event" json:"event"`
}

BootEvent bootstrap config of Event Logger information.

type BootEventE

type BootEventE struct {
	Name        string             `yaml:"name" json:"name"`
	Description string             `yaml:"description" json:"description"`
	Domain      string             `yaml:"domain" json:"domain"`
	Default     bool               `yaml:"default" json:"default"`
	Encoding    string             `yaml:"encoding" json:"encoding"`
	OutputPaths []string           `yaml:"outputPaths" json:"outputPaths"`
	Lumberjack  *lumberjack.Logger `yaml:"lumberjack" json:"lumberjack"`
	Loki        BootLoki           `yaml:"loki" json:"loki"`
}

BootEventE bootstrap element of EventEntry

type BootLogger

type BootLogger struct {
	Logger []*BootLoggerE `json:"logger" yaml:"logger"`
}

BootLogger bootstrap config of Zap Logger information.

type BootLoggerE

type BootLoggerE struct {
	Name        string                  `yaml:"name" json:"name"`
	Description string                  `yaml:"description" json:"description"`
	Domain      string                  `yaml:"domain" json:"domain"`
	Default     bool                    `yaml:"default" json:"default"`
	Zap         *rklogger.ZapConfigWrap `yaml:"zap" json:"zap"`
	Lumberjack  *lumberjack.Logger      `yaml:"lumberjack" json:"lumberjack"`
	Loki        BootLoki                `yaml:"loki" json:"loki"`
}

BootLoggerE bootstrap element of LoggerEntry

type BootLoki

type BootLoki struct {
	Enabled            bool              `yaml:"enabled" json:"enabled"`
	Addr               string            `yaml:"addr" json:"addr"`
	Path               string            `yaml:"path" json:"path"`
	Username           string            `yaml:"username" json:"username"`
	Password           string            `yaml:"password" json:"password"`
	InsecureSkipVerify bool              `yaml:"insecureSkipVerify" json:"insecureSkipVerify"`
	Labels             map[string]string `yaml:"labels" json:"labels"`
	MaxBatchWaitMs     int               `yaml:"maxBatchWaitMs" json:"maxBatchWaitMs"`
	MaxBatchSize       int               `yaml:"maxBatchSize" json:"maxBatchSize"`
}

BootLoki bootstrap config of Loki

type BootPProf added in v2.1.2

type BootPProf struct {
	Enabled bool   `yaml:"enabled" json:"enabled"`
	Path    string `yaml:"path" json:"path"`
}

type BootProm

type BootProm struct {
	Enabled bool   `yaml:"enabled" json:"enabled"`
	Path    string `yaml:"path" json:"path"`
	Pusher  struct {
		Enabled       bool   `yaml:"enabled" json:"enabled"`
		IntervalMs    int64  `yaml:"IntervalMs" json:"IntervalMs"`
		JobName       string `yaml:"jobName" json:"jobName"`
		RemoteAddress string `yaml:"remoteAddress" json:"remoteAddress"`
		BasicAuth     string `yaml:"basicAuth" json:"basicAuth"`
		CertEntry     string `yaml:"certEntry" json:"certEntry"`
		LoggerEntry   string `yaml:"loggerEntry" json:"loggerEntry"`
	} `yaml:"pusher" json:"pusher"`
}

BootProm Boot config which is for prom entry.

type BootSW

type BootSW struct {
	Enabled  bool     `yaml:"enabled" json:"enabled"`
	Path     string   `yaml:"path" json:"path"`
	JsonPath string   `yaml:"jsonPath" json:"jsonPath"`
	Headers  []string `yaml:"headers" json:"headers"`
}

BootSW Bootstrap config of swagger. 1: Enabled: Enable swagger. 2: Path: Swagger path accessible from restful API. 3: JsonPath: The path of where swagger JSON file was located. 4: Headers: The headers that would added into each API response.

type BootStaticFileHandler

type BootStaticFileHandler struct {
	Enabled    bool   `yaml:"enabled" json:"enabled"`
	Path       string `yaml:"path" json:"path"`
	SourceType string `yaml:"sourceType" json:"sourceType"`
	SourcePath string `yaml:"sourcePath" json:"sourcePath"`
}

BootStaticFileHandler bootstrap config of StaticHandler.

type CertEntry

type CertEntry struct {
	RootCA      *x509.Certificate `json:"-" json:"-"`
	Certificate *tls.Certificate  `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

CertEntry contains bellow fields.

func RegisterCertEntry

func RegisterCertEntry(boot *BootCert) []*CertEntry

RegisterCertEntry create cert entry with options.

func (*CertEntry) Bootstrap

func (entry *CertEntry) Bootstrap(ctx context.Context)

Bootstrap iterate retrievers and call Retrieve() for each of them.

func (*CertEntry) GetDescription

func (entry *CertEntry) GetDescription() string

GetDescription return description of entry

func (*CertEntry) GetName

func (entry *CertEntry) GetName() string

GetName return name of entry.

func (*CertEntry) GetType

func (entry *CertEntry) GetType() string

GetType return type of entry.

func (*CertEntry) Interrupt

func (entry *CertEntry) Interrupt(context.Context)

Interrupt entry.

func (*CertEntry) MarshalJSON

func (entry *CertEntry) MarshalJSON() ([]byte, error)

MarshalJSON marshal entry

func (*CertEntry) String

func (entry *CertEntry) String() string

String return string of entry.

func (*CertEntry) UnmarshalJSON

func (entry *CertEntry) UnmarshalJSON([]byte) error

UnmarshalJSON unmarshal entry

type CommonServiceEntry

type CommonServiceEntry struct {
	ReadyPath string `json:"-" yaml:"-"`
	AlivePath string `json:"-" yaml:"-"`
	GcPath    string `json:"-" yaml:"-"`
	InfoPath  string `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

CommonServiceEntry RK common service which contains commonly used APIs

func RegisterCommonServiceEntry

func RegisterCommonServiceEntry(boot *BootCommonService, opts ...CommonServiceEntryOption) *CommonServiceEntry

RegisterCommonServiceEntry Create new common service entry with options.

func (*CommonServiceEntry) Alive

func (entry *CommonServiceEntry) Alive(writer http.ResponseWriter, request *http.Request)

Alive handler @Summary Get application liveness status @Id 8002 @version 1.0 @Security ApiKeyAuth @Security BasicAuth @Security JWT @produce application/json @Success 200 {object} aliveResp @Router /rk/v1/alive [get]

func (*CommonServiceEntry) Bootstrap

func (entry *CommonServiceEntry) Bootstrap(context.Context)

Bootstrap common service entry.

func (*CommonServiceEntry) Gc

func (entry *CommonServiceEntry) Gc(writer http.ResponseWriter, request *http.Request)

Gc handler @Summary Trigger Gc @Id 8003 @version 1.0 @Security ApiKeyAuth @Security BasicAuth @Security JWT @produce application/json @Success 200 {object} gcResp @Router /rk/v1/gc [get]

func (*CommonServiceEntry) GetDescription

func (entry *CommonServiceEntry) GetDescription() string

GetDescription Get description of entry.

func (*CommonServiceEntry) GetName

func (entry *CommonServiceEntry) GetName() string

GetName Get name of entry.

func (*CommonServiceEntry) GetType

func (entry *CommonServiceEntry) GetType() string

GetType Get entry type.

func (*CommonServiceEntry) Info

func (entry *CommonServiceEntry) Info(writer http.ResponseWriter, request *http.Request)

Info handler @Summary Get application and process info @Id 8004 @version 1.0 @Security ApiKeyAuth @Security BasicAuth @Security JWT @produce application/json @Success 200 {object} ProcessInfo @Router /rk/v1/info [get]

func (*CommonServiceEntry) Interrupt

func (entry *CommonServiceEntry) Interrupt(context.Context)

Interrupt common service entry.

func (*CommonServiceEntry) MarshalJSON

func (entry *CommonServiceEntry) MarshalJSON() ([]byte, error)

MarshalJSON Marshal entry.

func (*CommonServiceEntry) Ready

func (entry *CommonServiceEntry) Ready(writer http.ResponseWriter, request *http.Request)

Ready handler @Summary Get application readiness status @Id 8001 @version 1.0 @Security ApiKeyAuth @Security BasicAuth @Security JWT @produce application/json @Success 200 {object} readyResp @Failure 500 {object} rkerror.ErrorInterface @Router /rk/v1/ready [get]

func (*CommonServiceEntry) String

func (entry *CommonServiceEntry) String() string

String Stringfy entry.

func (*CommonServiceEntry) UnmarshalJSON

func (entry *CommonServiceEntry) UnmarshalJSON([]byte) error

UnmarshalJSON Not supported.

type CommonServiceEntryOption

type CommonServiceEntryOption func(entry *CommonServiceEntry)

CommonServiceEntryOption option for CommonServiceEntry

func WithNameCommonServiceEntry

func WithNameCommonServiceEntry(name string) CommonServiceEntryOption

WithNameCommonServiceEntry provide entry name

type ConfigEntry

type ConfigEntry struct {
	*viper.Viper

	Locale    string `yaml:"-" json:"-"`
	Path      string `yaml:"-" json:"-"`
	EnvPrefix string `yaml:"-" json:"-"`
	// contains filtered or unexported fields
}

ConfigEntry contains bellow fields.

func RegisterConfigEntry

func RegisterConfigEntry(boot *BootConfig) []*ConfigEntry

RegisterConfigEntry create ConfigEntry with BootConfigConfig.

func (*ConfigEntry) Bootstrap

func (entry *ConfigEntry) Bootstrap(context.Context)

Bootstrap entry.

func (*ConfigEntry) GetDescription

func (entry *ConfigEntry) GetDescription() string

GetDescription return description of entry.

func (*ConfigEntry) GetName

func (entry *ConfigEntry) GetName() string

GetName returns name of entry.

func (*ConfigEntry) GetType

func (entry *ConfigEntry) GetType() string

GetType returns type of entry.

func (*ConfigEntry) Interrupt

func (entry *ConfigEntry) Interrupt(context.Context)

Interrupt entry.

func (*ConfigEntry) MarshalJSON

func (entry *ConfigEntry) MarshalJSON() ([]byte, error)

MarshalJSON marshal entry.

func (*ConfigEntry) String

func (entry *ConfigEntry) String() string

String convert entry into JSON style string.

func (*ConfigEntry) UnmarshalJSON

func (entry *ConfigEntry) UnmarshalJSON([]byte) error

UnmarshalJSON is not supported.

type Crypto added in v2.0.6

type Crypto interface {
	Entry

	Encrypt(plaintext []byte) ([]byte, error)

	Decrypt(plaintext []byte) ([]byte, error)
}

type CryptoAESEntry added in v2.0.6

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

func NewCryptoAES added in v2.0.6

func NewCryptoAES(entryName string, key []byte) (*CryptoAESEntry, error)

func (*CryptoAESEntry) Bootstrap added in v2.0.6

func (s *CryptoAESEntry) Bootstrap(ctx context.Context)

func (*CryptoAESEntry) Decrypt added in v2.0.6

func (s *CryptoAESEntry) Decrypt(ciphertext []byte) ([]byte, error)

func (*CryptoAESEntry) Encrypt added in v2.0.6

func (s *CryptoAESEntry) Encrypt(plaintext []byte) ([]byte, error)

func (*CryptoAESEntry) GetDescription added in v2.0.6

func (s *CryptoAESEntry) GetDescription() string

func (*CryptoAESEntry) GetName added in v2.0.6

func (s *CryptoAESEntry) GetName() string

func (*CryptoAESEntry) GetType added in v2.0.6

func (s *CryptoAESEntry) GetType() string

func (*CryptoAESEntry) Interrupt added in v2.0.6

func (s *CryptoAESEntry) Interrupt(ctx context.Context)

func (*CryptoAESEntry) String added in v2.0.6

func (s *CryptoAESEntry) String() string

type DocsEntry

type DocsEntry struct {
	SpecPath string            `json:"-" yaml:"-"`
	Path     string            `json:"-" yaml:"-"`
	Headers  map[string]string `json:"-" yaml:"-"`
	Debug    bool              `yaml:"-" json:"-"`
	Style    struct {
		Theme string `yaml:"-" json:"-"`
	} `yaml:"-" json:"-"`
	// contains filtered or unexported fields
}

DocsEntry implements rkentry.Entry interface.

func RegisterDocsEntry

func RegisterDocsEntry(boot *BootDocs, opts ...DocsEntryOption) *DocsEntry

RegisterDocsEntry register DocsEntry

func (*DocsEntry) Bootstrap

func (entry *DocsEntry) Bootstrap(ctx context.Context)

Bootstrap Entry

func (*DocsEntry) ConfigFileHandler

func (entry *DocsEntry) ConfigFileHandler() http.HandlerFunc

ConfigFileHandler handler for swagger config files.

func (*DocsEntry) GetDescription

func (entry *DocsEntry) GetDescription() string

GetDescription get description of Entry

func (*DocsEntry) GetName

func (entry *DocsEntry) GetName() string

GetName get name of Entry

func (*DocsEntry) GetType

func (entry *DocsEntry) GetType() string

GetType get type of Entry

func (*DocsEntry) Interrupt

func (entry *DocsEntry) Interrupt(ctx context.Context)

Interrupt Entry

func (*DocsEntry) MarshalJSON

func (entry *DocsEntry) MarshalJSON() ([]byte, error)

MarshalJSON Marshal entry

func (*DocsEntry) String

func (entry *DocsEntry) String() string

String get string of Entry

func (*DocsEntry) UnmarshalJSON

func (entry *DocsEntry) UnmarshalJSON([]byte) error

UnmarshalJSON Unmarshal entry

type DocsEntryOption

type DocsEntryOption func(entry *DocsEntry)

DocsEntryOption option of DocsEntry

func WithNameDocsEntry

func WithNameDocsEntry(name string) DocsEntryOption

WithNameDocsEntry provide name of DocsEntry

type Entry

type Entry interface {
	// Bootstrap entry
	Bootstrap(context.Context)

	// Interrupt entry
	// Wait for shutdown signal and wait for draining incomplete procedure
	Interrupt(context.Context)

	// GetName returns name of entry
	GetName() string

	// GetType returns type of entry
	GetType() string

	// GetDescription returns description of entry
	GetDescription() string

	// String print entry as string
	String() string
}

Entry interface which must be implemented for bootstrapper to bootstrap

type EventEntry

type EventEntry struct {
	*rkquery.EventFactory
	*rkquery.EventHelper

	IsDefault        bool               `yaml:"-" json:"-"`
	LoggerConfig     *zap.Config        `yaml:"-" json:"-"`
	LumberjackConfig *lumberjack.Logger `yaml:"-" json:"-"`
	// contains filtered or unexported fields
}

EventEntry contains bellow fields.

func NewEventEntryNoop

func NewEventEntryNoop() *EventEntry

NewEventEntryNoop create event logger entry with noop event factory. Event factory and event helper will be created with noop zap logger. Since we don't need any log rotation in case of noop, lumberjack config will be nil.

func NewEventEntryStdout

func NewEventEntryStdout() *EventEntry

NewEventEntryStdout create event logger entry with stdout event factory.

func RegisterEventEntry

func RegisterEventEntry(boot *BootEvent) []*EventEntry

RegisterEventEntry create event logger entry with options.

func (*EventEntry) AddEntryLabelToLokiSyncer

func (entry *EventEntry) AddEntryLabelToLokiSyncer(e Entry)

AddEntryLabelToLokiSyncer add entry name entry type into loki syncer

func (*EventEntry) AddLabelToLokiSyncer

func (entry *EventEntry) AddLabelToLokiSyncer(k, v string)

AddLabelToLokiSyncer add key value pair as label into loki syncer

func (*EventEntry) Bootstrap

func (entry *EventEntry) Bootstrap(ctx context.Context)

Bootstrap entry.

func (*EventEntry) GetDescription

func (entry *EventEntry) GetDescription() string

GetDescription return description of entry.

func (*EventEntry) GetName

func (entry *EventEntry) GetName() string

GetName returns name of entry.

func (*EventEntry) GetType

func (entry *EventEntry) GetType() string

GetType returns type of entry.

func (*EventEntry) Interrupt

func (entry *EventEntry) Interrupt(ctx context.Context)

Interrupt entry.

func (*EventEntry) MarshalJSON

func (entry *EventEntry) MarshalJSON() ([]byte, error)

MarshalJSON marshal entry.

func (*EventEntry) String

func (entry *EventEntry) String() string

String convert entry into JSON style string.

func (*EventEntry) Sync

func (entry *EventEntry) Sync()

Sync underlying logger

func (*EventEntry) UnmarshalJSON

func (entry *EventEntry) UnmarshalJSON([]byte) error

UnmarshalJSON not supported.

type LivenessCheck

type LivenessCheck func(req *http.Request, resp http.ResponseWriter) bool

type LoggerEntry

type LoggerEntry struct {
	*zap.Logger

	IsDefault        bool               `yaml:"-" json:"-"`
	LoggerConfig     *zap.Config        `yaml:"-" json:"-"`
	LumberjackConfig *lumberjack.Logger `yaml:"-" json:"-"`
	// contains filtered or unexported fields
}

LoggerEntry contains bellow fields.

func NewLoggerEntryNoop

func NewLoggerEntryNoop() *LoggerEntry

NewLoggerEntryNoop create zap logger entry with noop.

func NewLoggerEntryStdout

func NewLoggerEntryStdout() *LoggerEntry

NewLoggerEntryStdout create zap logger entry with STDOUT.

func RegisterLoggerEntry

func RegisterLoggerEntry(boot *BootLogger) []*LoggerEntry

RegisterLoggerEntry create event logger entry with options.

func (*LoggerEntry) AddEntryLabelToLokiSyncer

func (entry *LoggerEntry) AddEntryLabelToLokiSyncer(e Entry)

AddEntryLabelToLokiSyncer add entry name entry type into loki syncer

func (*LoggerEntry) AddLabelToLokiSyncer

func (entry *LoggerEntry) AddLabelToLokiSyncer(k, v string)

AddLabelToLokiSyncer add key value pair as label into loki syncer

func (*LoggerEntry) Bootstrap

func (entry *LoggerEntry) Bootstrap(ctx context.Context)

Bootstrap entry.

func (*LoggerEntry) GetDescription

func (entry *LoggerEntry) GetDescription() string

GetDescription returns description of entry.

func (*LoggerEntry) GetName

func (entry *LoggerEntry) GetName() string

GetName returns name of entry.

func (*LoggerEntry) GetType

func (entry *LoggerEntry) GetType() string

GetType returns type of entry.

func (*LoggerEntry) Interrupt

func (entry *LoggerEntry) Interrupt(ctx context.Context)

Interrupt entry.

func (*LoggerEntry) MarshalJSON

func (entry *LoggerEntry) MarshalJSON() ([]byte, error)

MarshalJSON marshal entry.

func (*LoggerEntry) String

func (entry *LoggerEntry) String() string

String convert entry into JSON style string.

func (*LoggerEntry) Sync

func (entry *LoggerEntry) Sync()

Sync underlying logger

func (*LoggerEntry) UnmarshalJSON

func (entry *LoggerEntry) UnmarshalJSON([]byte) error

UnmarshalJSON not supported.

type PProfEntry added in v2.1.2

type PProfEntry struct {
	Path string `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

func RegisterPProfEntry added in v2.1.2

func RegisterPProfEntry(boot *BootPProf, opts ...PProfEntryOption) *PProfEntry

RegisterPProfEntry Create new pprof entry with config

func (*PProfEntry) Bootstrap added in v2.1.2

func (entry *PProfEntry) Bootstrap(ctx context.Context)

func (*PProfEntry) GetDescription added in v2.1.2

func (entry *PProfEntry) GetDescription() string

func (*PProfEntry) GetName added in v2.1.2

func (entry *PProfEntry) GetName() string

func (*PProfEntry) GetType added in v2.1.2

func (entry *PProfEntry) GetType() string

func (*PProfEntry) Interrupt added in v2.1.2

func (entry *PProfEntry) Interrupt(ctx context.Context)

func (*PProfEntry) MarshalJSON added in v2.1.2

func (entry *PProfEntry) MarshalJSON() ([]byte, error)

MarshalJSON Marshal entry

func (*PProfEntry) String added in v2.1.2

func (entry *PProfEntry) String() string

func (*PProfEntry) UnmarshalJSON added in v2.1.2

func (entry *PProfEntry) UnmarshalJSON([]byte) error

UnmarshalJSON Unmarshal entry

type PProfEntryOption added in v2.1.2

type PProfEntryOption func(entry *PProfEntry)

func WithNamePProfEntry added in v2.1.2

func WithNamePProfEntry(name string) PProfEntryOption

type ProcessInfo

type ProcessInfo struct {
	AppName     string          `json:"appName" yaml:"appName" example:"rk-app"`
	Version     string          `json:"version" yaml:"version" example:"dev"`
	Description string          `json:"description" yaml:"description" example:"RK application"`
	Keywords    []string        `json:"keywords" yaml:"keywords" example:""`
	HomeUrl     string          `json:"homeUrl" yaml:"homeUrl" example:"https://example.com"`
	DocsUrl     []string        `json:"docsUrl" yaml:"docsUrl" example:""`
	Maintainers []string        `json:"maintainers" yaml:"maintainers" example:"rk-dev"`
	UID         string          `json:"uid" yaml:"uid" example:"501"`
	GID         string          `json:"gid" yaml:"gid" example:"20"`
	Username    string          `json:"username" yaml:"username" example:"lark"`
	StartTime   string          `json:"startTime" yaml:"startTime" example:"2022-03-15T20:43:05+08:00"`
	UpTimeSec   int64           `json:"upTimeSec" yaml:"upTimeSec" example:"13"`
	Region      string          `json:"region" yaml:"region" example:"us-east-1"`
	AZ          string          `json:"az" yaml:"az" example:"us-east-1c"`
	Realm       string          `json:"realm" yaml:"realm" example:"rookie-ninja"`
	Domain      string          `json:"domain" yaml:"domain" example:"dev"`
	CpuInfo     *rkos.CpuInfo   `json:"cpuInfo" yaml:"cpuInfo"`
	MemInfo     *rkos.MemInfo   `json:"memInfo" yaml:"memInfo"`
	NetInfo     *rkos.NetInfo   `json:"netInfo" yaml:"netInfo"`
	OsInfo      *rkos.OsInfo    `json:"osInfo" yaml:"osInfo"`
	GoEnvInfo   *rkos.GoEnvInfo `json:"goEnvInfo" yaml:"goEnvInfo"`
}

ProcessInfo process information for a running application.

func NewProcessInfo

func NewProcessInfo() *ProcessInfo

NewProcessInfo creates a new ProcessInfo instance

type PromEntry

type PromEntry struct {
	*prometheus.Registry
	Registerer prometheus.Registerer
	Gatherer   prometheus.Gatherer

	Path   string             `json:"-" yaml:"-"`
	Pusher *PushGatewayPusher `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

PromEntry Prometheus entry which implements rkentry.Entry.

func RegisterPromEntry

func RegisterPromEntry(boot *BootProm, opts ...PromEntryOption) *PromEntry

RegisterPromEntry Create a prom entry with options and add prom entry to rkentry.GlobalAppCtx

func (*PromEntry) Bootstrap

func (entry *PromEntry) Bootstrap(ctx context.Context)

Bootstrap Start prometheus client

func (*PromEntry) GetDescription

func (entry *PromEntry) GetDescription() string

GetDescription Get description of entry

func (*PromEntry) GetName

func (entry *PromEntry) GetName() string

GetName Return name of prom entry

func (*PromEntry) GetType

func (entry *PromEntry) GetType() string

GetType Return type of prom entry

func (*PromEntry) Interrupt

func (entry *PromEntry) Interrupt(ctx context.Context)

Interrupt Shutdown prometheus client

func (*PromEntry) MarshalJSON

func (entry *PromEntry) MarshalJSON() ([]byte, error)

MarshalJSON Marshal entry

func (*PromEntry) RegisterCollectors

func (entry *PromEntry) RegisterCollectors(collectors ...prometheus.Collector)

RegisterCollectors Register collectors in default registry

func (*PromEntry) String

func (entry *PromEntry) String() string

String Stringfy prom entry

func (*PromEntry) UnmarshalJSON

func (entry *PromEntry) UnmarshalJSON([]byte) error

UnmarshalJSON Unmarshal entry

type PromEntryOption

type PromEntryOption func(entry *PromEntry)

func WithRegistryPromEntry

func WithRegistryPromEntry(registry *prometheus.Registry) PromEntryOption

WithRegistryPromEntry provide prometheus.Registry

type PushGatewayPusher

type PushGatewayPusher struct {
	Pusher        *push.Pusher  `json:"-" yaml:"-"`
	IntervalMs    time.Duration `json:"-" yaml:"-"`
	RemoteAddress string        `json:"-" yaml:"-"`
	JobName       string        `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

PushGatewayPusher is a pusher which contains bellow instances

func (*PushGatewayPusher) Bootstrap

func (pub *PushGatewayPusher) Bootstrap(ctx context.Context)

Bootstrap starts a periodic job

func (*PushGatewayPusher) Interrupt

func (pub *PushGatewayPusher) Interrupt(ctx context.Context)

Interrupt stops periodic job

type ReadinessCheck

type ReadinessCheck func(req *http.Request, resp http.ResponseWriter) bool

type RegFunc

type RegFunc func(raw []byte) map[string]Entry

RegFunc can be used to create an entry could be any kinds of services or pieces of codes which needs to be bootstrap/initialized while application starts.

A third party entry could be implemented and inject to rk-boot via rk-boot.yaml file

How to create a new custom entry? Please see example/ for details Step 1: Construct your own entry YAML struct as needed example: --- myEntry:

enabled: true
key: value

Step 2: Create a struct which implements Entry interface

Step 3: Implements EntryRegFunc

Step 4: Register your reg function in init() in order to register your entry while application starts

How entry interact with rk-boot.Bootstrapper? 1: Entry will be created and registered into rkentry.GlobalAppCtx 2: Bootstrap will be called from Bootstrapper.Bootstrap() function 3: Application will wait for shutdown signal 4: Interrupt will be called from Bootstrapper.Interrupt() function

func ListPluginEntryRegFunc added in v2.2.0

func ListPluginEntryRegFunc() []RegFunc

ListPluginEntryRegFunc list plugin registration functions.

func ListUserEntryRegFunc added in v2.2.0

func ListUserEntryRegFunc() []RegFunc

ListUserEntryRegFunc list web framework registration functions.

func ListWebFrameEntryRegFunc added in v2.2.0

func ListWebFrameEntryRegFunc() []RegFunc

ListWebFrameEntryRegFunc list web framework registration functions.

type SWEntry

type SWEntry struct {
	JsonPath string            `json:"-" yaml:"-"`
	Path     string            `json:"-" yaml:"-"`
	Headers  map[string]string `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

SWEntry implements rke.Entry interface.

func RegisterSWEntry

func RegisterSWEntry(boot *BootSW, opts ...SWEntryOption) *SWEntry

func (*SWEntry) Bootstrap

func (entry *SWEntry) Bootstrap(ctx context.Context)

func (*SWEntry) ConfigFileHandler

func (entry *SWEntry) ConfigFileHandler() http.HandlerFunc

ConfigFileHandler handler for swagger config files.

func (*SWEntry) GetDescription

func (entry *SWEntry) GetDescription() string

func (*SWEntry) GetName

func (entry *SWEntry) GetName() string

func (*SWEntry) GetType

func (entry *SWEntry) GetType() string

func (*SWEntry) Interrupt

func (entry *SWEntry) Interrupt(ctx context.Context)

func (*SWEntry) MarshalJSON

func (entry *SWEntry) MarshalJSON() ([]byte, error)

MarshalJSON Marshal entry

func (*SWEntry) String

func (entry *SWEntry) String() string

func (*SWEntry) UnmarshalJSON

func (entry *SWEntry) UnmarshalJSON([]byte) error

UnmarshalJSON Unmarshal entry

type SWEntryOption

type SWEntryOption func(entry *SWEntry)

func WithNameSWEntry

func WithNameSWEntry(name string) SWEntryOption

type ShutdownHook

type ShutdownHook func()

ShutdownHook defines interface of shutdown hook

type SignerJwt added in v2.0.5

type SignerJwt interface {
	Entry

	// SignJwt sign jwt.Token
	SignJwt(claim jwt.Claims) (string, error)

	// VerifyJwt verify jwt.Token
	VerifyJwt(token string) (*jwt.Token, error)

	// PubKey get public key
	PubKey() []byte

	// Algorithms supported algorithms
	Algorithms() []string
}

SignerJwt interface which must be implemented for JWT signer

type StaticFileHandlerEntry

type StaticFileHandlerEntry struct {
	Path     string             `yaml:"-" json:"-"`
	Template *template.Template `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

StaticFileHandlerEntry Static file handler entry supports web UI for downloading static files.

func RegisterStaticFileHandlerEntry

func RegisterStaticFileHandlerEntry(boot *BootStaticFileHandler, opts ...StaticFileHandlerEntryOption) *StaticFileHandlerEntry

RegisterStaticFileHandlerEntry Create new static file handler entry with config

func (*StaticFileHandlerEntry) Bootstrap

func (entry *StaticFileHandlerEntry) Bootstrap(context.Context)

Bootstrap entry.

func (*StaticFileHandlerEntry) GetDescription

func (entry *StaticFileHandlerEntry) GetDescription() string

GetDescription Get description of entry.

func (*StaticFileHandlerEntry) GetFileHandler

func (entry *StaticFileHandlerEntry) GetFileHandler() http.HandlerFunc

GetFileHandler handles requests sent from user.

func (*StaticFileHandlerEntry) GetName

func (entry *StaticFileHandlerEntry) GetName() string

GetName Get name of entry.

func (*StaticFileHandlerEntry) GetType

func (entry *StaticFileHandlerEntry) GetType() string

GetType Get entry type.

func (*StaticFileHandlerEntry) Interrupt

func (entry *StaticFileHandlerEntry) Interrupt(context.Context)

Interrupt entry.

func (*StaticFileHandlerEntry) MarshalJSON

func (entry *StaticFileHandlerEntry) MarshalJSON() ([]byte, error)

MarshalJSON Marshal entry.

func (*StaticFileHandlerEntry) String

func (entry *StaticFileHandlerEntry) String() string

String Stringfy entry.

func (*StaticFileHandlerEntry) UnmarshalJSON

func (entry *StaticFileHandlerEntry) UnmarshalJSON([]byte) error

UnmarshalJSON Not supported.

type StaticFileHandlerEntryOption

type StaticFileHandlerEntryOption func(entry *StaticFileHandlerEntry)

StaticFileHandlerEntryOption options for StaticFileHandlerEntry

func WithNameStaticFileHandlerEntry

func WithNameStaticFileHandlerEntry(name string) StaticFileHandlerEntryOption

WithNameStaticFileHandlerEntry provide entry name

Jump to

Keyboard shortcuts

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