contract

package
v0.0.0-...-7c51b95 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeDevelopment uint8 = iota
	ModeProduction
	ModeTesting
)
View Source
const (
	HttpMimeJson          = "application/json"
	HttpMimeHtml          = "text/html"
	HttpMimeXml           = "application/xml"
	HttpMimePlain         = "text/plain"
	HttpMimeForm          = "application/x-www-form-urlencoded"
	HttpMimeMultipartForm = "multipart/form-data"
	HttpMimeStream        = "application/octet-stream"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

type Application interface {
	Container
	Pool
	SetMode(mode uint8)
	Version() string
	Mode() uint8
	IsDevelopment() bool
	IsProduction() bool
	IsTesting() bool
	Resolve(abstract interface{}, params ...interface{}) interface{}
	Boot()
	Register(provider Provider, force bool)
	RegisterMultiple(providers []Provider, force bool)
	HasProvider(name string) bool
	GetProvider(name string) Provider
	Reset()
}

type BaseCommand

type BaseCommand interface {
	Application() Application

	Providers() []Provider

	AddCommand(commands ...Command)

	Run() error

	Root() *cobra.Command

	Resolve(abstract interface{}, params ...interface{}) interface{}
}

type Binding

type Binding interface {
	Protocol(protocol Protocol, v interface{}) error
}

type BindingFile

type BindingFile interface {
	Files(key string) []*multipart.FileHeader

	File(key string) *multipart.FileHeader

	Save(key string, option *UploadOption) ([]*FileInfo, error)

	SaveAll(option *UploadOption) (map[string][]*FileInfo, error)
}

type Cache

type Cache interface {
	Driver(driver string) CacheSerializable
	Register(driver string, store CacheStore)
	CacheStore
	CacheSerializable
}

type CacheSerializable

type CacheSerializable interface {
	Store() CacheStore

	GetDefault(key string, defaultValue interface{}) (interface{}, error)

	Pull(key string) (interface{}, error)

	PullDefault(key string, defaultValue interface{}) (interface{}, error)

	GetDecode(key string, to interface{}) (interface{}, error)

	AddEncode(key string, value interface{}, expire time.Time) error

	ForeverEncode(key string, value interface{}) error

	PutEncode(key string, value interface{}, expire time.Time) error
}

type CacheStore

type CacheStore interface {
	Get(key string) (interface{}, error)

	Add(key string, value interface{}, expire time.Time) error

	Put(key string, value interface{}, expire time.Time) error

	Forever(key string, value interface{}) error

	Forget(key string) error

	Increment(key string, steps ...int64) error

	Decrement(key string, steps ...int64) error

	Has(key string) bool

	Flush() error
}

type Command

type Command interface {
	CobraCmd() *cobra.Command

	Run(root BaseCommand, cmd *cobra.Command, args []string)
}

type Configuration

type Configuration interface {
	Bind(key string, val interface{}) error
	Get(key string) interface{}
	GetBool(key string) bool
	GetFloat(key string) float64
	GetInt(key string) int
	GetIntSlice(key string) []int
	GetString(key string) string
	GetStringMap(key string) map[string]interface{}
	GetStringMapString(key string) map[string]string
	GetStringSlice(key string) []string
	GetTime(key string) time.Time
	GetDuration(key string) time.Duration
	Exists(key string) bool
	Set(key string, value interface{})
	SetDefault(key string, value interface{})
	Clone() Configuration
}

type Container

type Container interface {
	Has(name string) bool
	Get(name string, params ...interface{}) interface{}
	Bind(name string, prototype interface{}, options ...support.Option)
	Make(abstract interface{}, params ...interface{}) interface{}
	Remove(name string)
	Flush()
}

type Context

type Context interface {
	context.Context

	Application() Application

	Protocol() Protocol

	Next()

	Handlers() []ContextHandler

	AddEntity(key string, value interface{})

	Entity(key string) *ContextEntity

	Abort()

	Current() int

	Error(status int, err ...interface{})

	Bind(v interface{}) error

	BindValidate(v interface{}) error

	BindWith(b Binding, v interface{}) error

	BindWithValidate(b Binding, v interface{}) error

	Get(key string) interface{}

	Render(status int, v interface{}) error

	RenderWith(status int, r Render, v interface{}) error

	Clone() Context

	// application make method
	Resolve(abstract interface{}, params ...interface{}) interface{}
}

type ContextEntity

type ContextEntity struct {
	Key   string
	Value interface{}
}

type ContextHandler

type ContextHandler func(c Context)

type ContextPool

type ContextPool interface {
	New(application Application) Context

	Get() Context

	Release(Context)
}

type Cron

type Cron interface {
	Start()

	Stop()

	// Perform tasks at a custom time
	RunWithFunc(spec string, job func())
	RunWithJob(spec string, job CronJob)

	// Execute task in specified seconds
	SecondsWithFunc(seconds int, job func())
	SecondsWithJob(seconds int, job CronJob)

	// Perform a task every second
	EverySecondWithFunc(job func())
	EverySecondWithJob(job CronJob)

	// Execute task in specified minutes
	MinutesWithFunc(minutes int, job func())
	MinutesWithJob(minutes int, job CronJob)

	// Perform a task every minute
	EveryMinuteWithFunc(job func())
	EveryMinuteWithJob(job CronJob)

	// Execute task in specified hours
	HoursWithFunc(hours int, job func())
	HoursWithJob(hours int, job CronJob)

	// Perform a task every hour
	EveryHourWithFunc(job func())
	EveryHourWithJob(job CronJob)

	// Run at a specified time every day
	DayAtWithFunc(hour int, job func())
	DayAtWithJob(hour int, job CronJob)

	// Every day at 0 o'clock
	EveryDayWithFunc(job func())
	EveryDayWithJob(job CronJob)

	// Perform the task at 0:00 every Sunday
	EveryWeeklyWithFunc(job func())
	EveryWeeklyWithJob(job CronJob)

	// Perform a task at N points of N every week
	WeeklyOnWithFunc(week, hour int, job func())
	WeeklyOnWithJob(week, hour int, job CronJob)
}

type CronJob

type CronJob interface {
	cron.Job
}

type Error

type Error interface {
	fmt.Stringer

	error

	Equal(err error) bool

	Unwrap() error

	Meta() map[string]interface{}

	SetMeta(key string, value interface{}) Error

	Code() int

	SetCode(code int) Error

	Stack() []uintptr

	StackString() string

	Prev() error
}

type ErrorRender

type ErrorRender interface {
	Render(status int, ctx Context) error
}

type ErrorStack

type ErrorStack interface {
	Stack() []uintptr

	StackString() string
}

type Event

type Event interface {
	Listen(name string, handlers ...EventHandler)
	Dispatch(name string, params ...interface{}) []interface{}
	Has(name string) bool
}

type EventHandler

type EventHandler interface {
	Handle(application Application, params ...interface{}) (interface{}, error)
}

type FileInfo

type FileInfo struct {
	Name         string
	OriginalName string
	Mime         string
	Extension    string
	Size         int64
	Path         string
	FullPath     string
	MD5          string
}

type GORMQueryMagic

type GORMQueryMagic interface {
	Query(db *gorm.DB) *gorm.DB
}

type HttpProtocol

type HttpProtocol interface {
	Protocol

	Request() *http.Request

	ResponseWriter() HttpWrapResponseWriter

	SetHeader(key, value string)

	SetParams(params []httprouter.Param)

	Params() []httprouter.Param

	Param(key string) httprouter.Param

	SetRoute(route HttpRoute)

	Route() HttpRoute

	Header(key string) string

	SetSession(session Session)

	Session() Session

	SessionValue(key string) interface{}

	IsContentType(key string) bool

	IsAccept(key string) bool

	IsMethod(key string) bool

	ContentType() string

	Accept() []string

	SetStatus(status int)

	SetCookie(cookie *http.Cookie)

	Cookie(name string) (string, error)

	Redirect(status int, location string)

	ClientIP() string
}

type HttpRoute

type HttpRoute interface {
	Name(name string) HttpRoute

	Use(handlers ...ContextHandler) HttpRoute

	Handlers() []ContextHandler
}

type HttpRouteGroup

type HttpRouteGroup interface {
	Prefix(prefix string) HttpRouteGroup

	Use(handlers ...ContextHandler) HttpRouteGroup

	GET(path string, handler ContextHandler) HttpRoute

	POST(path string, handler ContextHandler) HttpRoute

	PUT(path string, handler ContextHandler) HttpRoute

	PATCH(path string, handler ContextHandler) HttpRoute

	DELETE(path string, handler ContextHandler) HttpRoute

	OPTIONS(path string, handler ContextHandler) HttpRoute

	Group(prefix string) HttpRouteGroup

	Handler(method, path string, handler http.HandlerFunc)
}

type HttpRouter

type HttpRouter interface {
	GET(path string, handler ContextHandler) HttpRoute

	POST(path string, handler ContextHandler) HttpRoute

	PUT(path string, handler ContextHandler) HttpRoute

	PATCH(path string, handler ContextHandler) HttpRoute

	DELETE(path string, handler ContextHandler) HttpRoute

	OPTIONS(path string, handler ContextHandler) HttpRoute

	// serve static files
	Static(path string, root string) HttpRouter

	Handler(method, path string, handler http.HandlerFunc)

	HttpRouter() *httprouter.Router

	Group(prefix string) HttpRouteGroup

	ServeHTTP(w http.ResponseWriter, req *http.Request)
}

type HttpWrapResponseWriter

type HttpWrapResponseWriter interface {
	http.ResponseWriter

	StatusCode() int
}

type Jwt

type Jwt interface {
	Create(audience JwtAudience) (*Token, error)

	Parse(token string) (*jwt.StandardClaims, error)

	Refresh(token string) (*Token, error)

	Invalidate(token string) error

	Valid(token string) (bool, error)
}

type JwtAudience

type JwtAudience interface {
	Audience() string
}

type JwtStore

type JwtStore interface {
	Has(id string) bool

	Put(id string, audience JwtAudience, lifetime time.Time) error

	Forget(audience JwtAudience) error
}

type Loggable

type Loggable interface {
	Writer(channel string) io.Writer
	With(...interface{}) Loggable
	Debug(...interface{})
	Info(...interface{})
	Warn(...interface{})
	Error(...interface{})
	Fatal(...interface{})
	Panic(...interface{})
}

type Notify

type Notify func(blockCount int, info *NotifyInfo, err error)

type NotifyInfo

type NotifyInfo struct {
	Block int
	Size  int
	Extra interface{}
}

type Pool

type Pool interface {
	RegisterPool(name string, poolNew PoolFunc) error

	PoolValue(name string) (interface{}, bool)

	ReleasePool(name string, value func() interface{})
}

type PoolFunc

type PoolFunc func(application Application) interface{}

type Protocol

type Protocol interface {
	io.Reader
	io.Writer

	Application() Application

	Name() string

	// Protocol metadata
	Metadata() map[string][]string

	// Full protocol message
	Message() ([]byte, error)

	Values() map[string][]string

	Clone() Protocol
}

整个协议的生命周期 包括,协议名称,本身详情,数据完整的数据报,普通value,文件生成,以及协议返回的输出

type Provider

type Provider interface {
	Name() string
	Register()
	Boot()
}

type Render

type Render interface {
	Render(protocol Protocol, status int, v interface{}) error
}

type ResourceCollectionData

type ResourceCollectionData interface {
	CollectionData() ResourceDataCollection
}

type ResourceData

type ResourceData map[string]interface{}

type ResourceDataCollection

type ResourceDataCollection []ResourceData

type ResourceDatable

type ResourceDatable interface {
	Data() ResourceData
}

type ResourceFields

type ResourceFields []string
type ResourceLink interface {
	SetLink(links ResourceLinkData)
	Link() ResourceLinkData
}

type ResourceLinkData

type ResourceLinkData map[string]string

type ResourceMeta

type ResourceMeta interface {
	SetMeta(meta ResourceMetaData)
	Meta() ResourceMetaData
}

type ResourceMetaData

type ResourceMetaData map[string]interface{}

type ResourceResolveData

type ResourceResolveData map[string]interface{}

type ResourceResolver

type ResourceResolver interface {
	Resolve() interface{}
}

type ResourceTransformer

type ResourceTransformer interface {
	Resource() interface{}
	SetResource(resource interface{})
}

type Scheduler

type Scheduler interface {
	Send(message *SchedulerMessage) error
	Run() error
	Close() error
	Decrement(workerNum int32)
	Increment(workerNum int32) error
	RegisterHandler(name string, handler SchedulerHandler)
}

type SchedulerFailed

type SchedulerFailed interface {
	Failed(err error)
}

type SchedulerHandler

type SchedulerHandler interface {
	Handle(message *SchedulerMessage) error
}

type SchedulerMessage

type SchedulerMessage struct {
	Worker  int32
	Handler string
	Message interface{}
}

type Server

type Server interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
	Restart(ctx context.Context) error
}

type Session

type Session interface {
	Id() string

	Get(key string) interface{}

	GetString(key string) string
	GetInt(key string) int
	GetBool(key string) bool
	GetFloat(key string) float64

	Put(key string, value interface{}) error

	Flush()

	Delete(key string)
}

type Storage

type Storage interface {
	Url(key string, params url.Values) string

	FormUpload(ctx context.Context, metadata *StorageMetadata) (*StorageInfo, error)

	PartUpload(ctx context.Context, metadata *StorageMetadata, notify Notify) (*StorageInfo, error)

	Token() string

	Callback(req *http.Request) (*StorageInfo, error)
}

type StorageInfo

type StorageInfo struct {
	Driver       string
	Hash         string
	Name         string
	OriginalName string
	Mime         string
	Extension    string
	Size         int64
	Path         string
	Extra        map[string]interface{}
}

type StorageMetadata

type StorageMetadata struct {
	Path string
	Name string
	Mime string
	Data []byte
	Size int64
	File io.Reader
}

得到的上传元数据

func (*StorageMetadata) GenerateNewName

func (a *StorageMetadata) GenerateNewName() string

type Token

type Token struct {
	Lifetime int64  `json:"lifetime"`
	Token    string `json:"token"`
	Type     string `json:"type"`
}

type UploadOption

type UploadOption struct {
	Path            string
	AllowMimes      []string
	AllowExtensions []string
	MaxSize         int64
	MinSize         int64
	Grading         bool //多层级
	Rename          bool
}

type Validator

type Validator interface {
	Validate(val interface{}) error
}

Jump to

Keyboard shortcuts

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