rkzero

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2022 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

Package rkzero an implementation of rkentry.Entry which could be used start restful server with go-zero framework

Index

Constants

View Source
const (
	// ZeroEntryType type of entry
	ZeroEntryType = "ZeroEntry"
)

Variables

This section is empty.

Functions

func RegisterZeroEntryYAML

func RegisterZeroEntryYAML(raw []byte) map[string]rkentry.Entry

RegisterZeroEntryYAML register zero entries with provided config file (Must YAML file).

Currently, support two ways to provide config file path. 1: With function parameters 2: With command line flag "--rkboot" described in rkcommon.BootConfigPathFlagKey (Will override function parameter if exists) Command line flag has high priority which would override function parameter

Error handling: Process will shutdown if any errors occur with rkcommon.ShutdownWithError function

Override elements in config file: We learned from HELM source code which would override elements in YAML file with "--set" flag followed with comma separated key/value pairs.

We are using "--rkset" described in rkcommon.BootConfigOverrideKey in order to distinguish with user flags Example of common usage: ./binary_file --rkset "key1=val1,key2=val2" Example of nested map: ./binary_file --rkset "outer.inner.key=val" Example of slice: ./binary_file --rkset "outer[0].key=val"

Types

type BootZero

type BootZero struct {
	Zero []struct {
		Enabled       bool                          `yaml:"enabled" json:"enabled"`
		Name          string                        `yaml:"name" json:"name"`
		Port          uint64                        `yaml:"port" json:"port"`
		Description   string                        `yaml:"description" json:"description"`
		CertEntry     string                        `yaml:"certEntry" json:"certEntry"`
		LoggerEntry   string                        `yaml:"loggerEntry" json:"loggerEntry"`
		EventEntry    string                        `yaml:"eventEntry" json:"eventEntry"`
		SW            rkentry.BootSW                `yaml:"sw" json:"sw"`
		Docs          rkentry.BootDocs              `yaml:"docs" json:"docs"`
		CommonService rkentry.BootCommonService     `yaml:"commonService" json:"commonService"`
		Prom          rkentry.BootProm              `yaml:"prom" json:"prom"`
		Static        rkentry.BootStaticFileHandler `yaml:"static" json:"static"`
		Middleware    struct {
			Ignore    []string              `yaml:"ignore" json:"ignore"`
			Logging   rkmidlog.BootConfig   `yaml:"logging" json:"logging"`
			Prom      rkmidprom.BootConfig  `yaml:"prom" json:"prom"`
			Auth      rkmidauth.BootConfig  `yaml:"auth" json:"auth"`
			Cors      rkmidcors.BootConfig  `yaml:"cors" json:"cors"`
			Meta      rkmidmeta.BootConfig  `yaml:"meta" json:"meta"`
			Jwt       rkmidjwt.BootConfig   `yaml:"jwt" json:"jwt"`
			Secure    rkmidsec.BootConfig   `yaml:"secure" json:"secure"`
			RateLimit rkmidlimit.BootConfig `yaml:"rateLimit" json:"rateLimit"`
			Csrf      rkmidcsrf.BootConfig  `yaml:"csrf" yaml:"csrf"`
			Trace     rkmidtrace.BootConfig `yaml:"trace" json:"trace"`
		} `yaml:"middleware" json:"middleware"`
	} `yaml:"zero" json:"zero"`
}

BootZero boot config which is for zero entry.

type ZeroEntry

type ZeroEntry struct {
	LoggerEntry        *rkentry.LoggerEntry            `json:"-" yaml:"-"`
	EventEntry         *rkentry.EventEntry             `json:"-" yaml:"-"`
	Port               uint64                          `json:"port" yaml:"port"`
	CertEntry          *rkentry.CertEntry              `json:"-" yaml:"-"`
	SwEntry            *rkentry.SWEntry                `json:"-" yaml:"-"`
	DocsEntry          *rkentry.DocsEntry              `json:"-" yaml:"-"`
	CommonServiceEntry *rkentry.CommonServiceEntry     `json:"-" yaml:"-"`
	PromEntry          *rkentry.PromEntry              `json:"-" yaml:"-"`
	StaticFileEntry    *rkentry.StaticFileHandlerEntry `json:"-" yaml:"-"`
	Server             *rest.Server                    `json:"-" yaml:"-"`
	ServerConf         *rest.RestConf                  `json:"-" yaml:"-"`
	ServerRunOption    []rest.RunOption                `json:"-" yaml:"-"`
	TlsConfig          *tls.Config                     `json:"-" yaml:"-"`
	Middlewares        []rest.Middleware               `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

ZeroEntry implements rkentry.Entry interface.

func GetZeroEntry

func GetZeroEntry(name string) *ZeroEntry

GetZeroEntry Get ZeroEntry from rkentry.GlobalAppCtx.

func RegisterZeroEntry

func RegisterZeroEntry(opts ...ZeroEntryOption) *ZeroEntry

RegisterZeroEntry register ZeroEntry with options.

func (*ZeroEntry) AddMiddleware

func (entry *ZeroEntry) AddMiddleware(inters ...rest.Middleware)

AddMiddleware Add interceptors. This function should be called before Bootstrap() called.

func (*ZeroEntry) Bootstrap

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

Bootstrap ZeroEntry.

func (*ZeroEntry) GetDescription

func (entry *ZeroEntry) GetDescription() string

GetDescription Get description of entry.

func (*ZeroEntry) GetName

func (entry *ZeroEntry) GetName() string

GetName Get entry name.

func (*ZeroEntry) GetType

func (entry *ZeroEntry) GetType() string

GetType Get entry type.

func (*ZeroEntry) Interrupt

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

Interrupt ZeroEntry.

func (*ZeroEntry) IsCommonServiceEnabled

func (entry *ZeroEntry) IsCommonServiceEnabled() bool

IsCommonServiceEnabled Is common service entry enabled?

func (*ZeroEntry) IsDocsEnabled

func (entry *ZeroEntry) IsDocsEnabled() bool

IsDocsEnabled Is TV entry enabled?

func (*ZeroEntry) IsPromEnabled

func (entry *ZeroEntry) IsPromEnabled() bool

IsPromEnabled Is prometheus entry enabled?

func (*ZeroEntry) IsStaticFileHandlerEnabled

func (entry *ZeroEntry) IsStaticFileHandlerEnabled() bool

IsStaticFileHandlerEnabled Is static file handler entry enabled?

func (*ZeroEntry) IsSwEnabled

func (entry *ZeroEntry) IsSwEnabled() bool

IsSwEnabled Is swagger entry enabled?

func (*ZeroEntry) IsTlsEnabled

func (entry *ZeroEntry) IsTlsEnabled() bool

IsTlsEnabled Is TLS enabled?

func (*ZeroEntry) MarshalJSON

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

MarshalJSON Marshal entry.

func (*ZeroEntry) String

func (entry *ZeroEntry) String() string

String Stringfy entry.

func (*ZeroEntry) UnmarshalJSON

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

UnmarshalJSON Not supported.

type ZeroEntryOption

type ZeroEntryOption func(*ZeroEntry)

ZeroEntryOption zero entry option.

func WithCertEntry

func WithCertEntry(certEntry *rkentry.CertEntry) ZeroEntryOption

WithCertEntry provide rkentry.CertEntry.

func WithCommonServiceEntry

func WithCommonServiceEntry(commonServiceEntry *rkentry.CommonServiceEntry) ZeroEntryOption

WithCommonServiceEntry provide CommonServiceEntry.

func WithDescription

func WithDescription(description string) ZeroEntryOption

WithDescription provide name.

func WithDocsEntry

func WithDocsEntry(docsEntry *rkentry.DocsEntry) ZeroEntryOption

WithDocsEntry provide TvEntry.

func WithEventEntry

func WithEventEntry(eventLogger *rkentry.EventEntry) ZeroEntryOption

WithEventEntry provide rkentry.EventEntry.

func WithLoggerEntry

func WithLoggerEntry(logger *rkentry.LoggerEntry) ZeroEntryOption

WithLoggerEntry provide rkentry.LoggerEntry.

func WithMiddlewares

func WithMiddlewares(inters ...rest.Middleware) ZeroEntryOption

WithMiddlewares provide user middlewares.

func WithName

func WithName(name string) ZeroEntryOption

WithName provide name.

func WithPort

func WithPort(port uint64) ZeroEntryOption

WithPort provide port.

func WithPromEntry

func WithPromEntry(prom *rkentry.PromEntry) ZeroEntryOption

WithPromEntry provide PromEntry.

func WithServerConf

func WithServerConf(conf *rest.RestConf) ZeroEntryOption

WithServerConf provide *rest.RestConf.

func WithServerRunOption

func WithServerRunOption(opts ...rest.RunOption) ZeroEntryOption

WithServerRunOption provide *rest.RestConf.

func WithStaticFileHandlerEntry

func WithStaticFileHandlerEntry(static *rkentry.StaticFileHandlerEntry) ZeroEntryOption

WithStaticFileHandlerEntry provide CommonServiceEntry.

func WithSwEntry

func WithSwEntry(sw *rkentry.SWEntry) ZeroEntryOption

WithSwEntry provide SwEntry.

Jump to

Keyboard shortcuts

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