contract

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2020 License: MIT Imports: 5 Imported by: 9

Documentation

Index

Constants

View Source
const (
	// EnvProduction represent the environment which build for production
	EnvProduction = "production"
	// EnvTesting represent the environment which build for test
	EnvTesting = "testing"
	// EnvDevelopment represent the environment which build for development
	EnvDevelopment = "development"

	// EnvKey is the key in container
	EnvKey = "hade:env"
)
View Source
const (
	TraceKeyTraceID  = "trace_id"
	TraceKeySpanID   = "span_id"
	TraceKeyCspanID  = "cspan_id"
	TraceKeyParentID = "parent_id"
	TraceKeyMethod   = "method"
	TraceKeyCaller   = "caller"
	TraceKeyTime     = "time"
)
View Source
const AppKey = "hade:app"

AppKey is the key in container

View Source
const CacheKey = "hade:cache"
View Source
const (
	// ConfigKey is config key in container
	ConfigKey = "hade:config"
)
View Source
const IDKey = "hade:id"
View Source
const KernelKey = "hade:kernel"
View Source
const LogKey = "hade:log"
View Source
const SSHKey = "hade:ssh"
View Source
const TraceKey = "hade:trace"

Variables

Functions

This section is empty.

Types

type App

type App interface {
	// application version
	Version() string
	// base path which is the base folder
	BasePath() string
	// app path which is the app folder
	AppPath() string
	// app/http
	HttpPath() string
	// app/http/swagger
	SwaggerPath() string
	// app/console
	ConsolePath() string
	// config folder which contains config
	ConfigPath() string
	// environmentPath which contain .env
	EnvironmentPath() string
	// storagePath define storage folder
	StoragePath() string
	// logPath define logPath
	LogPath() string

	PidPath() string

	CachePath() string
	// load config
	LoadAppConfig(map[string]string)
}

App define application structure

type Cache

type Cache interface {
	// Get value by key
	Get(key string) []byte
	// Pull get and delete
	Pull(key string) []byte
	// Check key exists
	Has(key string) bool
	// Set value to key
	Put(key string, val []byte, duration time.Duration) error
	// Forever Put
	Forever(key string, val []byte) error
	// Delete key
	Delete(key string) error
	// increment
	Increment(key string) int
	// decrement
	Decrement(key string) int
}

type Config

type Config interface {
	// IsExist check setting is exist
	IsExist(key string) bool

	// Get a new interface
	Get(key string) interface{}
	// GetBool get bool type
	GetBool(key string) bool
	// GetInt get Int type
	GetInt(key string) int
	// GetFloat64 get float64
	GetFloat64(key string) float64
	// GetTime get time type
	GetTime(key string) time.Time
	// GetString get string typen
	GetString(key string) string

	// GetIntSlice get int slice type
	GetIntSlice(key string) []int
	// GetStringSlice get string slice type
	GetStringSlice(key string) []string

	// GetStringMap get map which key is string, value is interface
	GetStringMap(key string) map[string]interface{}
	// GetStringMapString get map which key is string, value is string
	GetStringMapString(key string) map[string]string
	// GetStringMapStringSlice get map which key is string, value is string slice
	GetStringMapStringSlice(key string) map[string][]string

	// Load a config to a struct, val should be an pointer
	Load(key string, val interface{}) error
}

Config define setting from files, it support key contains dov。 for example: .Get("user.name") suggest use yaml format, https://yaml.org/spec/1.2/spec.html

type ConsoleLog

type ConsoleLog interface {
	Log
}

type CtxFielder

type CtxFielder func(ctx context.Context) map[string]interface{}

CtxFielder define ctx field which add to log field

type Env

type Env interface {
	// AppEnv get current environment
	AppEnv() string

	// IsExist check setting is exist
	IsExist(string) bool
	// Get environment setting, if not exist, return ""
	Get(string) string
	// All return all settings
	All() map[string]string
}

Env define golang run enviornment it set some config which want ignored in git

type Formatter

type Formatter func(level LogLevel, t time.Time, msg string, fields map[string]interface{}) ([]byte, error)

Formatter define fields format handler to string

type IDService

type IDService interface {
	NewID() string
}

type Kernel

type Kernel interface {
	HttpEngine() *gin.Engine
}

type Log

type Log interface {
	// Panic will call panic(fields) for debug
	Panic(ctx context.Context, msg string, fields map[string]interface{})
	// Fatal will add fatal record which contains msg and fields
	Fatal(ctx context.Context, msg string, fields map[string]interface{})
	// Error will add error record which contains msg and fields
	Error(ctx context.Context, msg string, fields map[string]interface{})
	// Warn will add warn record which contains msg and fields
	Warn(ctx context.Context, msg string, fields map[string]interface{})
	// Info will add info record which contains msg and fields
	Info(ctx context.Context, msg string, fields map[string]interface{})
	// Debug will add debug record which contains msg and fields
	Debug(ctx context.Context, msg string, fields map[string]interface{})
	// Trace will add trace info which contains msg and fields
	Trace(ctx context.Context, msg string, fields map[string]interface{})

	// SetLevel set log level, and higher level will be recorded
	SetLevel(level LogLevel)
	// SetCxtFielder will get fields from context
	SetCxtFielder(handler CtxFielder)
	// SetFormatter will set formatter handler will covert data to string for recording
	SetFormatter(formatter Formatter)
	// SetOutput will set output writer
	SetOutput(out io.Writer)
}

Log define interface for log

type LogLevel

type LogLevel uint32
const (
	// Unknownlevel is default level, which will design by provider
	UnknownLevel LogLevel = iota
	// PanicLevel level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel
)

type RotatingFileLog

type RotatingFileLog interface {
	Log
	SetFolder(folder string)
	SetFile(file string)
	SetMaxFiles(maxFiles int)
	SetDateFormat(dateFormat string)
}

type SSH

type SSH interface {
	// 运行shell,并输出结果
	Run(shell string) ([]byte, error)
	// 将本地文件放到远端
	Upload(src, dist string) error
	// 将远端文件放到本地
	Download(src, dist string) error
	// 将本地文件夹放到远端
	UploadDir(src, dist string) error

	DownloadDir(src, dist string) error
}

SSH 相关接口

type SSHConfig

type SSHConfig struct {
	User     string
	Password string
	Host     string
	Port     string
	RsaKey   string
	Timeout  int
}

SSH的连接配置 如果设置了Password,优先走Password模式,否则走RSAKey 密码模式和rsa key模式必须至少有一个

type SingleFileLog

type SingleFileLog interface {
	Log
	SetFile(file string)
	SetFolder(folder string)
}

FileLog define interface which fileLogger should satisfied

type Trace

type Trace interface {

	// WithContext register new trace to context
	WithTrace(c context.Context, trace *TraceContext) context.Context
	// GetTrace From trace context
	GetTrace(c context.Context) *TraceContext
	// NewTrace generate a new trace
	NewTrace() *TraceContext
	// StartSpan generate cspan for child call
	StartSpan(trace *TraceContext) *TraceContext

	// traceContext to map for logger
	ToMap(trace *TraceContext) map[string]string

	// GetTrace By Http
	ExtractHTTP(req *http.Request) *TraceContext
	// Set Trace to Http
	InjectHTTP(req *http.Request, trace *TraceContext) *http.Request
}

type TraceContext

type TraceContext struct {
	TraceID  string // traceID global unique
	ParentID string // 父节点SpanID
	SpanID   string // 当前节点SpanID
	CspanID  string // 子节点调用的SpanID, 由调用方指定

	Annotation map[string]string // 标记各种信息
}

Trace define struct according Google Dapper

Jump to

Keyboard shortcuts

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