rkgin

package
v1.2.22 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2022 License: Apache-2.0 Imports: 40 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 = "Gin"
	// GinEntryDescription description of entry
	GinEntryDescription = "Internal RK entry which helps to bootstrap with Gin framework."
)

Variables

This section is empty.

Functions

func RegisterGinEntriesWithConfig added in v1.2.0

func RegisterGinEntriesWithConfig(configFilePath string) map[string]rkentry.Entry

RegisterGinEntriesWithConfig 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 BootConfig added in v1.2.15

type BootConfig 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"`
		CertEntry     string                          `yaml:"certEntry" json:"certEntry"`
		SW            rkentry.BootConfigSw            `yaml:"sw" json:"sw"`
		CommonService rkentry.BootConfigCommonService `yaml:"commonService" json:"commonService"`
		TV            rkentry.BootConfigTv            `yaml:"tv" json:"tv"`
		Prom          rkentry.BootConfigProm          `yaml:"prom" json:"prom"`
		Static        rkentry.BootConfigStaticHandler `yaml:"static" json:"static"`
		Interceptors  struct {
			LoggingZap  rkmidlog.BootConfig     `yaml:"loggingZap" json:"loggingZap"`
			MetricsProm rkmidmetrics.BootConfig `yaml:"metricsProm" json:"metricsProm"`
			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"`
			Gzip        struct {
				Enabled bool   `yaml:"enabled" json:"enabled"`
				Level   string `yaml:"level" json:"level"`
			} `yaml:"gzip" json:"gzip"`
			Timeout          rkmidtimeout.BootConfig `yaml:"timeout" json:"timeout"`
			TracingTelemetry rkmidtrace.BootConfig   `yaml:"tracingTelemetry" json:"tracingTelemetry"`
		} `yaml:"interceptors" json:"interceptors"`
		Logger struct {
			ZapLogger   string `yaml:"zapLogger" json:"zapLogger"`
			EventLogger string `yaml:"eventLogger" json:"eventLogger"`
		} `yaml:"logger" json:"logger"`
	} `yaml:"gin" json:"gin"`
}

BootConfig boot config which is for gin entry.

type GinEntry

type GinEntry struct {
	EntryName          string                          `json:"entryName" yaml:"entryName"`
	EntryType          string                          `json:"entryType" yaml:"entryType"`
	EntryDescription   string                          `json:"-" yaml:"-"`
	ZapLoggerEntry     *rkentry.ZapLoggerEntry         `json:"-" yaml:"-"`
	EventLoggerEntry   *rkentry.EventLoggerEntry       `json:"-" yaml:"-"`
	Router             *gin.Engine                     `json:"-" yaml:"-"`
	Server             *http.Server                    `json:"-" yaml:"-"`
	Port               uint64                          `json:"port" yaml:"port"`
	SwEntry            *rkentry.SwEntry                `json:"-" yaml:"-"`
	CertEntry          *rkentry.CertEntry              `json:"-" yaml:"-"`
	CommonServiceEntry *rkentry.CommonServiceEntry     `json:"-" yaml:"-"`
	PromEntry          *rkentry.PromEntry              `json:"-" yaml:"-"`
	StaticFileEntry    *rkentry.StaticFileHandlerEntry `json:"-" yaml:"-"`
	TvEntry            *rkentry.TvEntry                `json:"-" yaml:"-"`
}

GinEntry implements rkentry.Entry interface.

func GetGinEntry added in v1.2.0

func GetGinEntry(name string) *GinEntry

GetGinEntry Get GinEntry from rkentry.GlobalAppCtx.

func RegisterGinEntry added in v1.2.0

func RegisterGinEntry(opts ...GinEntryOption) *GinEntry

RegisterGinEntry register GinEntry with options.

func (*GinEntry) AddInterceptor added in v1.2.0

func (entry *GinEntry) AddInterceptor(inters ...gin.HandlerFunc)

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

func (*GinEntry) Apis added in v1.2.15

func (entry *GinEntry) Apis(ctx *gin.Context)

Apis list apis from gin.Router

func (*GinEntry) Bootstrap

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

Bootstrap GinEntry.

func (*GinEntry) GetDescription added in v1.2.0

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 added in v1.1.3

func (entry *GinEntry) GetType() string

GetType Get entry type.

func (*GinEntry) Interrupt added in v1.2.0

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

Interrupt GinEntry.

func (*GinEntry) IsCommonServiceEnabled added in v1.2.0

func (entry *GinEntry) IsCommonServiceEnabled() bool

IsCommonServiceEnabled Is common service entry enabled?

func (*GinEntry) IsPromEnabled added in v1.2.0

func (entry *GinEntry) IsPromEnabled() bool

IsPromEnabled Is prometheus entry enabled?

func (*GinEntry) IsStaticFileHandlerEnabled added in v1.2.11

func (entry *GinEntry) IsStaticFileHandlerEnabled() bool

IsStaticFileHandlerEnabled Is static file handler entry enabled?

func (*GinEntry) IsSwEnabled added in v1.2.0

func (entry *GinEntry) IsSwEnabled() bool

IsSwEnabled Is swagger entry enabled?

func (*GinEntry) IsTlsEnabled added in v1.1.3

func (entry *GinEntry) IsTlsEnabled() bool

IsTlsEnabled Is TLS enabled?

func (*GinEntry) IsTvEnabled added in v1.2.0

func (entry *GinEntry) IsTvEnabled() bool

IsTvEnabled Is TV entry enabled?

func (*GinEntry) MarshalJSON added in v1.2.0

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

MarshalJSON Marshal entry.

func (*GinEntry) Req added in v1.2.15

func (entry *GinEntry) Req(ctx *gin.Context)

Req handler

func (*GinEntry) String added in v1.1.3

func (entry *GinEntry) String() string

String Stringfy gin entry.

func (*GinEntry) TV added in v1.2.15

func (entry *GinEntry) TV(ctx *gin.Context)

TV handler

func (*GinEntry) UnmarshalJSON added in v1.2.0

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

UnmarshalJSON Not supported.

type GinEntryOption

type GinEntryOption func(*GinEntry)

GinEntryOption Gin entry option.

func WithCertEntry added in v1.2.15

func WithCertEntry(certEntry *rkentry.CertEntry) GinEntryOption

WithCertEntry provide rkentry.CertEntry.

func WithCommonServiceEntry added in v1.2.15

func WithCommonServiceEntry(commonServiceEntry *rkentry.CommonServiceEntry) GinEntryOption

WithCommonServiceEntry provide CommonServiceEntry.

func WithDescription added in v1.2.15

func WithDescription(description string) GinEntryOption

WithDescription provide name.

func WithEventLoggerEntry added in v1.2.15

func WithEventLoggerEntry(eventLogger *rkentry.EventLoggerEntry) GinEntryOption

WithEventLoggerEntry provide rkentry.EventLoggerEntry.

func WithName

func WithName(name string) GinEntryOption

WithName provide name.

func WithPort

func WithPort(port uint64) GinEntryOption

WithPort provide port.

func WithPromEntry added in v1.2.15

func WithPromEntry(prom *rkentry.PromEntry) GinEntryOption

WithPromEntry provide PromEntry.

func WithStaticFileHandlerEntry added in v1.2.15

func WithStaticFileHandlerEntry(staticEntry *rkentry.StaticFileHandlerEntry) GinEntryOption

WithStaticFileHandlerEntry provide StaticFileHandlerEntry.

func WithSwEntry added in v1.2.15

func WithSwEntry(sw *rkentry.SwEntry) GinEntryOption

WithSwEntry provide SwEntry.

func WithTvEntry added in v1.2.15

func WithTvEntry(tvEntry *rkentry.TvEntry) GinEntryOption

WithTvEntry provide TvEntry.

func WithZapLoggerEntry added in v1.2.15

func WithZapLoggerEntry(zapLogger *rkentry.ZapLoggerEntry) GinEntryOption

WithZapLoggerEntry provide rkentry.ZapLoggerEntry.

Jump to

Keyboard shortcuts

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