rkgin

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2022 License: Apache-2.0 Imports: 43 Imported by: 4

Documentation

Overview

Package rkgin an implementation of rkentry.Entry which could be used start restful server with gin framework

Index

Constants

View Source
const (
	// GinEntryType type of entry
	GinEntryType = "GinEntry"
)

Variables

This section is empty.

Functions

func RegisterGinEntryYAML

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

RegisterGinEntryYAML register gin 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 BootGin

type BootGin struct {
	Gin []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"`
		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"`
		CertEntry     string                        `yaml:"certEntry" json:"certEntry"`
		LoggerEntry   string                        `yaml:"loggerEntry" json:"loggerEntry"`
		EventEntry    string                        `yaml:"eventEntry" json:"eventEntry"`
		Static        rkentry.BootStaticFileHandler `yaml:"static" json:"static"`
		PProf         rkentry.BootPProf             `yaml:"pprof" json:"pprof"`
		Middleware    struct {
			Ignore     []string                `yaml:"ignore" json:"ignore"`
			ErrorModel string                  `yaml:"errorModel" json:"errorModel"`
			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"`
			Timeout    rkmidtimeout.BootConfig `yaml:"timeout" json:"timeout"`
			Trace      rkmidtrace.BootConfig   `yaml:"trace" json:"trace"`
			Gzip       struct {
				Enabled bool     `yaml:"enabled" json:"enabled"`
				Ignore  []string `yaml:"ignore" json:"ignore"`
				Level   string   `yaml:"level" json:"level"`
			} `yaml:"gzip" json:"gzip"`
		} `yaml:"middleware" json:"middleware"`
	} `yaml:"gin" json:"gin"`
}

BootGin boot config which is for gin entry.

type GinEntry

type GinEntry struct {
	Router             *gin.Engine                     `json:"-" yaml:"-"`
	Server             *http.Server                    `json:"-" yaml:"-"`
	Port               uint64                          `json:"-" yaml:"-"`
	LoggerEntry        *rkentry.LoggerEntry            `json:"-" yaml:"-"`
	EventEntry         *rkentry.EventEntry             `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:"-"`
	CertEntry          *rkentry.CertEntry              `json:"-" yaml:"-"`
	PProfEntry         *rkentry.PProfEntry             `json:"-" yaml:"-"`
	// contains filtered or unexported fields
}

GinEntry implements rkentry.Entry interface.

func GetGinEntry

func GetGinEntry(name string) *GinEntry

GetGinEntry Get GinEntry from rkentry.GlobalAppCtx.

func RegisterGinEntry

func RegisterGinEntry(opts ...GinEntryOption) *GinEntry

RegisterGinEntry register GinEntry with options.

func (*GinEntry) AddMiddleware

func (entry *GinEntry) AddMiddleware(mids ...gin.HandlerFunc)

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

func (*GinEntry) Bootstrap

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

Bootstrap GinEntry.

func (*GinEntry) GetDescription

func (entry *GinEntry) GetDescription() string

GetDescription Get description of entry.

func (*GinEntry) GetName

func (entry *GinEntry) GetName() string

GetName Get entry name.

func (*GinEntry) GetType

func (entry *GinEntry) GetType() string

GetType Get entry type.

func (*GinEntry) Interrupt

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

Interrupt GinEntry.

func (*GinEntry) IsCommonServiceEnabled

func (entry *GinEntry) IsCommonServiceEnabled() bool

IsCommonServiceEnabled Is common service entry enabled?

func (*GinEntry) IsDocsEnabled

func (entry *GinEntry) IsDocsEnabled() bool

IsDocsEnabled Is docs entry enabled?

func (*GinEntry) IsPProfEnabled added in v2.1.0

func (entry *GinEntry) IsPProfEnabled() bool

IsPProfEnabled Is pprof entry enabled?

func (*GinEntry) IsPromEnabled

func (entry *GinEntry) IsPromEnabled() bool

IsPromEnabled Is prometheus entry enabled?

func (*GinEntry) IsStaticFileHandlerEnabled

func (entry *GinEntry) IsStaticFileHandlerEnabled() bool

IsStaticFileHandlerEnabled Is static file handler entry enabled?

func (*GinEntry) IsSwEnabled

func (entry *GinEntry) IsSwEnabled() bool

IsSwEnabled Is swagger entry enabled?

func (*GinEntry) IsTlsEnabled

func (entry *GinEntry) IsTlsEnabled() bool

IsTlsEnabled Is TLS enabled?

func (*GinEntry) MarshalJSON

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

MarshalJSON Marshal entry.

func (*GinEntry) SetLivenessCheck

func (entry *GinEntry) SetLivenessCheck(f rkentry.LivenessCheck)

SetLivenessCheck set liveness check into rkentry.GlobalAppCtx

func (*GinEntry) SetReadinessCheck

func (entry *GinEntry) SetReadinessCheck(f rkentry.ReadinessCheck)

SetReadinessCheck set readiness check into rkentry.GlobalAppCtx

func (*GinEntry) String

func (entry *GinEntry) String() string

String Stringfy gin entry.

func (*GinEntry) UnmarshalJSON

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

UnmarshalJSON Not supported.

type GinEntryOption

type GinEntryOption func(*GinEntry)

GinEntryOption Gin entry option.

func WithCertEntry

func WithCertEntry(certEntry *rkentry.CertEntry) GinEntryOption

WithCertEntry provide rkentry.CertEntry.

func WithCommonServiceEntry

func WithCommonServiceEntry(commonServiceEntry *rkentry.CommonServiceEntry) GinEntryOption

WithCommonServiceEntry provide CommonServiceEntry.

func WithDescription

func WithDescription(description string) GinEntryOption

WithDescription provide name.

func WithDocsEntry

func WithDocsEntry(docs *rkentry.DocsEntry) GinEntryOption

WithDocsEntry provide SwEntry.

func WithEventEntry

func WithEventEntry(eventLogger *rkentry.EventEntry) GinEntryOption

WithEventEntry provide rkentry.EventLoggerEntry.

func WithLoggerEntry

func WithLoggerEntry(logger *rkentry.LoggerEntry) GinEntryOption

WithLoggerEntry provide rkentry.LoggerEntry.

func WithName

func WithName(name string) GinEntryOption

WithName provide name.

func WithPProfEntry added in v2.1.0

func WithPProfEntry(p *rkentry.PProfEntry) GinEntryOption

func WithPort

func WithPort(port uint64) GinEntryOption

WithPort provide port.

func WithPromEntry

func WithPromEntry(prom *rkentry.PromEntry) GinEntryOption

WithPromEntry provide PromEntry.

func WithStaticFileHandlerEntry

func WithStaticFileHandlerEntry(staticEntry *rkentry.StaticFileHandlerEntry) GinEntryOption

WithStaticFileHandlerEntry provide StaticFileHandlerEntry.

func WithSwEntry

func WithSwEntry(sw *rkentry.SWEntry) GinEntryOption

WithSwEntry provide SwEntry.

Jump to

Keyboard shortcuts

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