contract

package
v0.0.0-...-41a006c Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvKey         = "gogin:env"
	EnvProduction  = "production"
	EnvDevelopment = "development"
	EnvTesting     = "testing"
)
View Source
const (
	TraceKeyTraceID   = "trace_id"
	TraceKeyParentID  = "parent_id"
	TraceKeySpanID    = "span_id"
	TraceKeySubSpanID = "sub_span_id"
	TraceKeyMethod    = "method"
	TraceKeyCaller    = "caller"
	TraceKeyTime      = "time"
)
View Source
const AppKey = "gogin:app"
View Source
const CacheKey = "gogin:cache"
View Source
const DcsKey = "gogin:dcs"
View Source
const EtcKey = "gogin:etc"
View Source
const KernelKey = "gogin:kernel"
View Source
const LogKey = "gogin:log"
View Source
const OrmKey = "gogin:orm"
View Source
const RedisKey = "gogin:redis"
View Source
const TraceKey = "gogin:trace"
View Source
const UidKey = "gogin:uid"

Variables

This section is empty.

Functions

This section is empty.

Types

type DbConfig

type DbConfig struct {
	WriterTimeout string `yaml:"writer_timeout"`
	ReaderTimeout string `yaml:"reader_timeout"`
	ParseTime     bool   `yaml:"parse_time"`
	Loc           string `yaml:"loc"`
	Dsn           string `yaml:"dsn"`

	Host      string `ymal:"host"`
	Port      int    `yaml:"port"`
	Driver    string `yaml:"driver"`
	Charset   string `yaml:"charset"`
	Timeout   string `yaml:"timeout"`
	Protocol  string `yaml:"protocol"`
	Database  string `yaml:"database"`
	Collation string `yaml:"collation"`

	AllowNativePasswords bool `yaml:"allow_native_passwords"`

	Username string `yaml:"username"`
	Password string `yaml:"password"`

	ConnMaxIdle     int    `ymal:"conn_max_idle"`
	ConnMaxOpen     int    `ymal:"conn_max_open"`
	ConnMaxIdletime string `yaml:"conn_max_idletime"`
	ConnMaxLifetime string `yaml:"conn_max_lifetime"`

	*gorm.Config
}

func (*DbConfig) FormatDsn

func (c *DbConfig) FormatDsn() (string, error)

type DbOption

type DbOption func(container goframe.IContainer, config *DbConfig) error

type Formatter

type Formatter func(level LogLevel, t time.Time, msg string, data map[string]any) ([]byte, error)

type Handler

type Handler func(ctx context.Context) map[string]any

type IApp

type IApp interface {
	AppID() string
	Version() string

	AppDir() string
	EtcDir() string
	LogDir() string
	RunDir() string
	WorkDir() string
	HttpDir() string
	TestDir() string
	TmpDir() string
	ProviderDir() string
	DeployDir() string
	MiddlewareDir() string

	Load(kv map[string]string)
}

type ICache

type ICache interface {
	Set(ctx context.Context, key string, val string, timeout time.Duration) error
	SetObject(ctx context.Context, key string, val any, timeout time.Duration) error
	SetMany(ctx context.Context, data map[string]string, timeout time.Duration) error
	SetForever(ctx context.Context, key string, val string) error
	SetForeverObject(ctx context.Context, key string, val any) error

	Get(ctx context.Context, key string) (string, error)
	GetObject(ctx context.Context, key string, model any) error
	GetMany(ctx context.Context, keys []string) (map[string]string, error)

	SetTTL(ctx context.Context, key string, timeout time.Duration) error
	GetTTL(ctx context.Context, key string) error

	Remember(ctx context.Context, key string, timeout time.Duration, fn RememberFunc, model any) error

	Calc(ctx context.Context, key string, step int64) (int64, error)
	Increment(ctx context.Context, key string) (int64, error)
	Decrement(ctx context.Context, key string) (int64, error)

	Del(ctx context.Context, key string) error
	DelMany(ctx context.Context, keys []string) error
}

type IDcs

type IDcs interface {
	Select(name string, id string, hold time.Duration) (string, error)
}

type IEnv

type IEnv interface {
	Env() string
	Get(string) string
	All() map[string]string

	Exist(string) bool
}

type IEtc

type IEtc interface {
	Get(key string) any
	GetBool(key string) bool
	GetInt(key string) int
	GetInt64(key string) int64
	GetFloat32(key string) float32
	GetFloat64(key string) float64
	GetString(key string) string
	GetIntSlice(key string) []int
	GetStringSlice(key string) []string
	GetStringMap(key string) map[string]any
	GetStringMapString(key string) map[string]string
	GetStringMapStringSlice(key string) map[string][]string

	Load(key string, val any) error

	Exist(key string) bool
}

type IKernel

type IKernel interface {
	GrpcHandler() *grpc.Server
	HttpHandler() http.Handler
}

type ILog

type ILog interface {
	Panic(ctx context.Context, msg string, data map[string]any)
	Fatal(ctx context.Context, msg string, data map[string]any)
	Error(ctx context.Context, msg string, data map[string]any)
	Warn(ctx context.Context, msg string, data map[string]any)
	Info(ctx context.Context, msg string, data map[string]any)
	Debug(ctx context.Context, msg string, data map[string]any)
	Trace(ctx context.Context, msg string, data map[string]any)

	SetLevel(level LogLevel)
	SetWriter(writer io.Writer)
	SetHandler(handler Handler)
	SetFormatter(formatter Formatter)
}

type IOrm

type IOrm interface {
	Get(option ...DbOption) (*gorm.DB, error)
	GetTables(ctx context.Context, db *gorm.DB) ([]string, error)
	HasTable(ctx context.Context, db *gorm.DB, table string) (bool, error)
	GetTableColumns(ctx context.Context, db *gorm.DB, table string) ([]TableColumn, error)
}

type IRedis

type IRedis interface {
	GetClient(option ...RedisOption) (*redis.Client, error)
}

type ITrace

type ITrace interface {
	NewTrace() *TraceContext
	GetTrace(ctx context.Context) *TraceContext
	WithTrace(ctx context.Context, tcx *TraceContext) context.Context
	StartSpan(tcx *TraceContext) *TraceContext
	ToMap(tcx *TraceContext) map[string]string
	ExtractHttp(req *http.Request) *TraceContext
	InjectHttp(req *http.Request, tcx *TraceContext) *http.Request
}

type IUid

type IUid interface {
	NewUid() string
}

type LogLevel

type LogLevel uint32
const (
	UnknownLevel LogLevel = iota
	PanicLevel
	FatalLevel
	ErrorLevel
	WarnLevel
	InfoLevel
	DebugLevel
	TraceLevel
)

type RedisConfig

type RedisConfig struct {
	*redis.Options
}

func (*RedisConfig) UniqueKey

func (c *RedisConfig) UniqueKey() string

type RedisOption

type RedisOption func(container goframe.IContainer, config *RedisConfig) error

type RememberFunc

type RememberFunc func(ctx context.Context, container goframe.IContainer) (any, error)

type TableColumn

type TableColumn struct {
	Key     string `gorm:"column:Key"`
	Type    string `gorm:"column:Type"`
	Null    string `gorm:"column:Null"`
	Field   string `gorm:"column:Field"`
	Extra   string `gorm:"column:Extra"`
	Default string `gorm:"column:Default"`
}

type TraceContext

type TraceContext struct {
	TraceID    string
	ParentID   string
	SpanID     string
	SubSpanID  string
	Annotation map[string]string
}

Jump to

Keyboard shortcuts

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