winter

package module
v1.1.56 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: Apache-2.0 Imports: 48 Imported by: 3

README

winter

基于Gin、XORM、Nacos的Spring风格的基础框架

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidHex = errors.New("the provided hex string is not a valid ObjectID")

ErrInvalidHex indicates that a hex string cannot be converted to an ObjectID.

Functions

func ExternalIP added in v1.0.3

func ExternalIP() net.IP

func IsValidObjectID deprecated added in v1.0.3

func IsValidObjectID(s string) bool

IsValidObjectID returns true if the provided hex string represents a valid ObjectID and false if not.

Deprecated: Use ObjectIDFromHex and check the error instead.

func LocalIP added in v1.0.3

func LocalIP() string

func NewLogger added in v1.0.4

func NewLogger(viper *viper.Viper) *zap.Logger

func ReadFileFromUrl added in v1.0.11

func ReadFileFromUrl(url string) ([]byte, error)

func ReadFileFromUrlAsBase64 added in v1.0.11

func ReadFileFromUrlAsBase64(url string) (string, error)

func Recovery added in v1.0.8

func Recovery(logger *zap.Logger) gin.HandlerFunc

func RegisterDefaultMiddleware added in v1.0.14

func RegisterDefaultMiddleware(engine *gin.Engine, systemMiddleware *SystemMiddleware)

func RenderBadRequestResult added in v1.1.4

func RenderBadRequestResult(ctx *gin.Context, err error)

func RenderErrorResult added in v1.1.6

func RenderErrorResult(ctx *gin.Context, status int, err error)

func RenderForbiddenResult added in v1.1.4

func RenderForbiddenResult(ctx *gin.Context, err error)

func RenderInternalServerErrorResult added in v1.1.4

func RenderInternalServerErrorResult(ctx *gin.Context, err error)

func RenderNotFoundResult added in v1.1.4

func RenderNotFoundResult(ctx *gin.Context, err error)

func RenderResult added in v1.1.4

func RenderResult(ctx *gin.Context, status int, result any)

func RenderServiceUnavailableResult added in v1.1.4

func RenderServiceUnavailableResult(ctx *gin.Context, err error)

func RenderSuccessResult added in v1.1.14

func RenderSuccessResult(ctx *gin.Context, result any)

func RenderUnauthorizedResult added in v1.1.4

func RenderUnauthorizedResult(ctx *gin.Context, err error)

func SyncDB added in v1.0.9

func SyncDB(f func() error) gin.HandlerFunc

func SystemStats added in v1.0.7

func SystemStats(ctx *gin.Context)

func Url added in v1.1.0

func Url(baseUrl string, path string, urlValues url.Values) string

func Version added in v1.0.8

func Version(config *viper.Viper, version string) gin.HandlerFunc

Types

type Application

type Application struct {
	// contains filtered or unexported fields
}

func NewApplication

func NewApplication(
	metadata map[string]string,
	version string,
	syncDBFunc func() error,
) *Application

func (*Application) GetDatabase added in v1.1.8

func (m *Application) GetDatabase() *Database

func (*Application) GetEngine

func (m *Application) GetEngine() *gin.Engine

func (*Application) GetLogger added in v1.1.8

func (m *Application) GetLogger() *zap.Logger

func (*Application) GetNacos added in v1.1.8

func (m *Application) GetNacos() *Nacos

func (*Application) GetRedis added in v1.1.8

func (m *Application) GetRedis() *Redis

func (*Application) GetTencentEss added in v1.1.48

func (m *Application) GetTencentEss() *TencentEss

func (*Application) Jobs added in v1.1.16

func (m *Application) Jobs(scheduler *Scheduler) func(ctx *gin.Context)

func (*Application) RegisterScheduler added in v1.1.16

func (m *Application) RegisterScheduler(scheduler *Scheduler)

func (*Application) RemoveJobById added in v1.1.17

func (m *Application) RemoveJobById(scheduler *Scheduler) func(ctx *gin.Context)

func (*Application) Run

func (m *Application) Run(funcs ...ApplicationFunc)

func (*Application) Start added in v1.1.16

func (m *Application) Start(scheduler *Scheduler) func(ctx *gin.Context)

func (*Application) StopJobs added in v1.1.16

func (m *Application) StopJobs(scheduler *Scheduler) func(ctx *gin.Context)

type ApplicationFunc

type ApplicationFunc func()

type Banlancer

type Banlancer interface {
	GetUri(serviceName string) (string, error)
}

type BusinessError added in v1.0.16

type BusinessError struct {
	Status  int    `json:"status"`
	Code    string `json:"code"`
	Message string `json:"message"`
}

func NewBadRequestBusinessError added in v1.0.17

func NewBadRequestBusinessError(message string) *BusinessError

func NewBusinessError added in v1.0.17

func NewBusinessError(status int, code string, message string) *BusinessError

func NewForbiddenBusinessError added in v1.1.4

func NewForbiddenBusinessError(message string) *BusinessError

func NewInternalServerErrorBusinessError added in v1.0.17

func NewInternalServerErrorBusinessError(message string) *BusinessError

func NewNotFoundBusinessError added in v1.0.17

func NewNotFoundBusinessError(message string) *BusinessError

func NewServiceUnavailableBusinessError added in v1.1.4

func NewServiceUnavailableBusinessError(message string) *BusinessError

func NewUnauthorizedBusinessError added in v1.1.4

func NewUnauthorizedBusinessError(message string) *BusinessError

func (*BusinessError) Error added in v1.0.16

func (m *BusinessError) Error() string

type Database

type Database struct {
	// contains filtered or unexported fields
}

func NewDatabase

func NewDatabase(config *viper.Viper) *Database

func (*Database) GetDatabase added in v1.1.46

func (m *Database) GetDatabase(key string) *xorm.Engine

func (*Database) GetDatabases

func (m *Database) GetDatabases() map[string]*xorm.Engine

func (*Database) Init

func (m *Database) Init()

type EncodingFunc added in v1.0.18

type EncodingFunc func(v any) ([]byte, error)

type IdName added in v1.1.44

type IdName struct {
	Id   int64  `json:"id"`
	Name string `json:"name"`
}

func NewIdName added in v1.1.44

func NewIdName(id int64, name string) *IdName

type Job added in v1.1.11

type Job struct {
	Id          string     `json:"id"`
	Tags        []string   `json:"tags"`
	LastRunTime string     `json:"last_run_time"`
	NextRunTime string     `json:"next_run_time"`
	InnerJob    gocron.Job `json:"-"`
}

func NewJob added in v1.1.13

func NewJob(innerJob gocron.Job) *Job

type JsonResult added in v1.1.3

type JsonResult struct {
	Status        int
	BusinessError *BusinessError
	Text          string
}

func ResponseToJsonResult added in v1.1.3

func ResponseToJsonResult(status int, bytes []byte, result ...any) (*JsonResult, error)

type KeyValue added in v1.1.18

type KeyValue struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

func NewKeyValue added in v1.1.18

func NewKeyValue(key string, value string) *KeyValue

type Nacos

type Nacos struct {
	// contains filtered or unexported fields
}

func NewNacos

func NewNacos(
	metadata map[string]string,
) *Nacos

func (*Nacos) BuildDefaultServiceClient added in v1.1.9

func (m *Nacos) BuildDefaultServiceClient(webClient *WebClient) *ServiceClient

func (*Nacos) BuildServiceClientWithConfigKey added in v1.1.10

func (m *Nacos) BuildServiceClientWithConfigKey(webClient *WebClient, configKey string) *ServiceClient

func (*Nacos) GetConfig

func (m *Nacos) GetConfig() *viper.Viper

func (*Nacos) GetDefaultNameingClient

func (m *Nacos) GetDefaultNameingClient() naming_client.INamingClient

func (*Nacos) GetMetadata

func (m *Nacos) GetMetadata() map[string]string

func (*Nacos) GetServiceNamingClient

func (m *Nacos) GetServiceNamingClient(configKey string) naming_client.INamingClient

func (*Nacos) GetServiceNamingClients

func (m *Nacos) GetServiceNamingClients() map[string]naming_client.INamingClient

func (*Nacos) Init

func (m *Nacos) Init()

type NacosBanlancer added in v1.0.15

type NacosBanlancer struct {
	// contains filtered or unexported fields
}

func (*NacosBanlancer) GetUri added in v1.0.15

func (m *NacosBanlancer) GetUri(serviceName string) (string, error)

type ObjectID added in v1.0.3

type ObjectID [12]byte

ObjectID is the BSON ObjectID type.

var NilObjectID ObjectID

NilObjectID is the zero value for ObjectID.

func NewObjectID added in v1.0.3

func NewObjectID() ObjectID

NewObjectID generates a new ObjectID.

func NewObjectIDFromTimestamp added in v1.0.3

func NewObjectIDFromTimestamp(timestamp time.Time) ObjectID

NewObjectIDFromTimestamp generates a new ObjectID based on the given time.

func ObjectIDFromHex added in v1.0.3

func ObjectIDFromHex(s string) (ObjectID, error)

ObjectIDFromHex creates a new ObjectID from a hex string. It returns an error if the hex string is not a valid ObjectID.

func (ObjectID) Hex added in v1.0.3

func (id ObjectID) Hex() string

Hex returns the hex encoding of the ObjectID as a string.

func (ObjectID) IsZero added in v1.0.3

func (id ObjectID) IsZero() bool

IsZero returns true if id is the empty ObjectID.

func (ObjectID) MarshalJSON added in v1.0.3

func (id ObjectID) MarshalJSON() ([]byte, error)

MarshalJSON returns the ObjectID as a string

func (ObjectID) MarshalText added in v1.0.3

func (id ObjectID) MarshalText() ([]byte, error)

MarshalText returns the ObjectID as UTF-8-encoded text. Implementing this allows us to use ObjectID as a map key when marshalling JSON. See https://pkg.go.dev/encoding#TextMarshaler

func (ObjectID) String added in v1.0.3

func (id ObjectID) String() string

func (ObjectID) Timestamp added in v1.0.3

func (id ObjectID) Timestamp() time.Time

Timestamp extracts the time part of the ObjectId.

func (*ObjectID) UnmarshalJSON added in v1.0.3

func (id *ObjectID) UnmarshalJSON(b []byte) error

UnmarshalJSON populates the byte slice with the ObjectID. If the byte slice is 24 bytes long, it will be populated with the hex representation of the ObjectID. If the byte slice is twelve bytes long, it will be populated with the BSON representation of the ObjectID. This method also accepts empty strings and decodes them as NilObjectID. For any other inputs, an error will be returned.

func (*ObjectID) UnmarshalText added in v1.0.3

func (id *ObjectID) UnmarshalText(b []byte) error

UnmarshalText populates the byte slice with the ObjectID. Implementing this allows us to use ObjectID as a map key when unmarshalling JSON. See https://pkg.go.dev/encoding#TextUnmarshaler

type PageParam added in v1.0.5

type PageParam struct {
	PageIndex int `json:"pageIndex" form:"pageIndex"`
	PageSize  int `json:"pageSize" form:"pageSize"`
}

func (*PageParam) ParamLength added in v1.0.10

func (pageParam *PageParam) ParamLength() int

func (*PageParam) Start added in v1.0.5

func (pageParam *PageParam) Start() int

type PageResult added in v1.0.5

type PageResult struct {
	Total      int64 `json:"total"`
	TotalPages int64 `json:"totalPages"`
	Data       []any `json:"data"`
}

func NewPageResult added in v1.0.5

func NewPageResult() *PageResult

func NewPageResultWithTotalAndDataLen added in v1.1.3

func NewPageResultWithTotalAndDataLen(total int64, l int) *PageResult

func NewPatgeResultWithTotal added in v1.1.3

func NewPatgeResultWithTotal(total int64) *PageResult

func (*PageResult) GetTotalPages added in v1.0.5

func (m *PageResult) GetTotalPages(pageSize int) int64

type Redis

type Redis struct {
	// contains filtered or unexported fields
}

func NewRedis

func NewRedis(config *viper.Viper) *Redis

func (*Redis) GetRedisClient added in v1.1.3

func (m *Redis) GetRedisClient() *redis.Client

func (*Redis) GetRedisClients

func (m *Redis) GetRedisClients() map[string]*redis.Client

func (*Redis) Init

func (m *Redis) Init()

type RequestHeaderFunc added in v1.0.18

type RequestHeaderFunc func(http.Header)

type RestResult added in v1.0.5

type RestResult struct {
	Status  int    `json:"status"`
	Code    string `json:"code"`
	Data    any    `json:"data"`
	Message string `json:"message"`
}

func NewBadRequestRestResult added in v1.0.18

func NewBadRequestRestResult(data any, message string) *RestResult

func NewForbiddenRestResult added in v1.1.4

func NewForbiddenRestResult(data any, message string) *RestResult

func NewInternalServerErrorRestResult added in v1.0.18

func NewInternalServerErrorRestResult(data any, message string) *RestResult

func NewNotFoundRestResult added in v1.0.18

func NewNotFoundRestResult(data any, message string) *RestResult

func NewRestResult added in v1.0.17

func NewRestResult(
	status int,
	code string,
	data any,
	message string,
) *RestResult

func NewServiceUnavailableRestResult added in v1.1.4

func NewServiceUnavailableRestResult(data any, message string) *RestResult

func NewSuccessRestResult added in v1.0.18

func NewSuccessRestResult(data any, message string) *RestResult

func NewUnauthorizedRestResult added in v1.1.4

func NewUnauthorizedRestResult(data any, message string) *RestResult

type Scheduler added in v1.1.11

type Scheduler struct {
	Id             string           `json:"id"`
	Name           string           `json:"name"`
	InnerScheduler gocron.Scheduler `json:"-"`
}

func NewScheduler added in v1.1.13

func NewScheduler(
	innerScheduler gocron.Scheduler,
	id string,
	name string,
) *Scheduler

func (*Scheduler) GetJobs added in v1.1.15

func (m *Scheduler) GetJobs() []Job

func (*Scheduler) JobsWaitingInQueue added in v1.1.15

func (m *Scheduler) JobsWaitingInQueue() int

func (*Scheduler) RemoveByTags added in v1.1.15

func (m *Scheduler) RemoveByTags(tags ...string)

func (*Scheduler) RemoveJob added in v1.1.15

func (m *Scheduler) RemoveJob(id uuid.UUID) error

func (*Scheduler) Start added in v1.1.15

func (m *Scheduler) Start()

func (*Scheduler) StopJobs added in v1.1.15

func (m *Scheduler) StopJobs()

type ServiceClient

type ServiceClient struct {
	// contains filtered or unexported fields
}

func NewServiceClient

func NewServiceClient(
	namingClient naming_client.INamingClient,
	webClient *WebClient,
	banlancer Banlancer) *ServiceClient

func (*ServiceClient) Delete

func (m *ServiceClient) Delete(
	serviceName string,
	path string,
	urlValues url.Values,
	bodyValue any,
	encodingFunc EncodingFunc,
	funcs ...RequestHeaderFunc,
) (int, []byte, error)

func (*ServiceClient) Do

func (m *ServiceClient) Do(
	serviceName string,
	method string,
	path string,
	urlValues url.Values,
	bodyValue any,
	encodingFunc EncodingFunc,
	funcs ...RequestHeaderFunc,
) (*http.Response, int, []byte, error)

func (*ServiceClient) Get

func (m *ServiceClient) Get(
	serviceName string,
	path string,
	urlValues url.Values,
	encodingFunc EncodingFunc,
	funcs ...RequestHeaderFunc,
) (int, []byte, error)

func (*ServiceClient) Post

func (m *ServiceClient) Post(
	serviceName string,
	path string,
	urlValues url.Values,
	bodyValue any,
	encodingFunc EncodingFunc,
	funcs ...RequestHeaderFunc,
) (int, []byte, error)

func (*ServiceClient) Put

func (m *ServiceClient) Put(
	serviceName string,
	path string,
	urlValues url.Values,
	bodyValue any,
	encodingFunc EncodingFunc,
	funcs ...RequestHeaderFunc,
) (int, []byte, error)

type SystemMiddleware added in v1.0.14

type SystemMiddleware struct {
	Logger     *zap.Logger
	Config     *viper.Viper
	Version    string
	SyncDBFunc func() error
}

type SystemVersion added in v1.0.6

type SystemVersion struct {
	ApplicationName string `json:"applicationName"`
	Version         string `json:"version"`
	Profile         string `json:"profile"`
	GoVersion       string `json:"goVersion"`
	CurrentTime     string `json:"currentTime"`
}

func NewSystemVersion added in v1.0.6

func NewSystemVersion(version string, config *viper.Viper) *SystemVersion

type TencentEss added in v1.1.45

type TencentEss struct {
	// contains filtered or unexported fields
}

func NewTencentEss added in v1.1.45

func NewTencentEss(config *viper.Viper) *TencentEss

func (*TencentEss) GetEssClient added in v1.1.45

func (m *TencentEss) GetEssClient() *ess.Client

func (*TencentEss) GetEssClients added in v1.1.45

func (m *TencentEss) GetEssClients() map[string]*TencentEssClient

func (*TencentEss) GetEssFileClient added in v1.1.50

func (m *TencentEss) GetEssFileClient() *ess.Client

func (*TencentEss) Init added in v1.1.45

func (m *TencentEss) Init()

type TencentEssClient added in v1.1.50

type TencentEssClient struct {
	// contains filtered or unexported fields
}

func (*TencentEssClient) GetEssClient added in v1.1.50

func (m *TencentEssClient) GetEssClient() *ess.Client

func (*TencentEssClient) GetEssFileClient added in v1.1.50

func (m *TencentEssClient) GetEssFileClient() *ess.Client

type UpdateLog added in v1.1.39

type UpdateLog struct {
	Property string `json:"property"`
	OldValue string `json:"oldValue"`
	NewValue string `json:"newValue"`
}

func NewUpdateLog added in v1.1.39

func NewUpdateLog(property, oldValue, newValue string) *UpdateLog

type WebClient

type WebClient struct {
	Client *http.Client
}

func NewWebClient

func NewWebClient(client *http.Client) *WebClient

func (*WebClient) Delete

func (m *WebClient) Delete(
	baseUrl string,
	path string,
	urlValues url.Values,
	bodyValue any,
	encodingFunc EncodingFunc,
	funcs ...RequestHeaderFunc,
) (int, []byte, error)

func (*WebClient) Do

func (m *WebClient) Do(
	method string,
	baseUrl string,
	path string,
	urlValues url.Values,
	bodyValue any,
	encodingFunc EncodingFunc,
	funcs ...RequestHeaderFunc,
) (*http.Response, int, []byte, error)

func (*WebClient) DoRequest added in v1.0.18

func (m *WebClient) DoRequest(req *http.Request) (*http.Response, int, []byte, error)

func (*WebClient) Get

func (m *WebClient) Get(
	baseUrl string,
	path string,
	urlValues url.Values,
	encodingFunc EncodingFunc,
	funcs ...RequestHeaderFunc,
) (int, []byte, error)

func (*WebClient) Post

func (m *WebClient) Post(
	baseUrl string,
	path string,
	urlValues url.Values,
	bodyValue any,
	encodingFunc EncodingFunc,
	funcs ...RequestHeaderFunc,
) (int, []byte, error)

func (*WebClient) Put

func (m *WebClient) Put(
	baseUrl string,
	path string,
	urlValues url.Values,
	bodyValue any,
	encodingFunc EncodingFunc,
	funcs ...RequestHeaderFunc,
) (int, []byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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