service

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractHttp

func ExtractHttp(r *http.Request) func() *model.SpanContext

ExtractHttp 解包http头为SpanContext

func Wrapper

func Wrapper(f HandlerFunc) gin.HandlerFunc

Types

type BaseService

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

func (*BaseService) Call

func (s *BaseService) Call(ctx context.Context, service string, method string, args interface{}, replay interface{}) error

Call 调用其它服务方法 params:

@method: get请求: get get:id get@action
		post请求: post post@action
		put请求: put:id
		delete请求: delete delete:id
@args: 调用方法的入参
@replay: 调用发放的返回

func (*BaseService) Client

func (s *BaseService) Client() *httpclient.ReqClient

func (*BaseService) CustomContext

func (s *BaseService) CustomContext(key string) interface{}

func (*BaseService) Delete

func (s *BaseService) Delete(handler *Handler) HandlerFunc

func (*BaseService) DeleteBatch

func (s *BaseService) DeleteBatch(handler *Handler) HandlerFunc

func (*BaseService) Get

func (s *BaseService) Get(handler *Handler) HandlerFunc

func (*BaseService) GetList

func (s *BaseService) GetList(handler *Handler) HandlerFunc

func (*BaseService) Head

func (s *BaseService) Head(handler *Handler) HandlerFunc

func (*BaseService) Interceptor

func (s *BaseService) Interceptor() *Interceptor

func (*BaseService) Mongo

func (s *BaseService) Mongo() *mongo.MgoClient

func (*BaseService) Node

func (s *BaseService) Node() *NodeInfo

func (*BaseService) Options

func (s *BaseService) Options(handler *Handler) HandlerFunc

func (*BaseService) Patch

func (s *BaseService) Patch(handler *Handler) HandlerFunc

func (*BaseService) Post

func (s *BaseService) Post(handler *Handler) HandlerFunc

func (*BaseService) Put

func (s *BaseService) Put(handler *Handler) HandlerFunc

func (*BaseService) Redis

func (s *BaseService) Redis() *redis.RdClient

func (*BaseService) Reg

func (s *BaseService) Reg() *Registry

func (*BaseService) Repo

func (s *BaseService) Repo() *repo.Repository

func (*BaseService) SetClient

func (s *BaseService) SetClient(client *httpclient.ReqClient)

func (*BaseService) SetCustomContext

func (s *BaseService) SetCustomContext(key string, value interface{})

func (*BaseService) SetInterceptor

func (s *BaseService) SetInterceptor(op *Interceptor)

func (*BaseService) SetMongo

func (s *BaseService) SetMongo(client *mongo.MgoClient)

func (*BaseService) SetNode

func (s *BaseService) SetNode(node *NodeInfo)

func (*BaseService) SetRedis

func (s *BaseService) SetRedis(redisClient *redis.RdClient)

func (*BaseService) SetReg

func (s *BaseService) SetReg(reg *Registry)

func (*BaseService) SetRepo

func (s *BaseService) SetRepo(repository *repo.Repository)

func (*BaseService) Use

func (s *BaseService) Use(handler *Handler)

type Ctx

type Ctx struct {
	*gin.Context
}

func (*Ctx) Csv

func (c *Ctx) Csv(data []byte, filename string)

func (*Ctx) Failure

func (c *Ctx) Failure(code int, err error, actual ...bool)

func (*Ctx) FileStream

func (c *Ctx) FileStream(data []byte, filename string)

func (*Ctx) Pdf

func (c *Ctx) Pdf(data []byte, filename string)

func (*Ctx) Response

func (c *Ctx) Response(code int, data interface{}, err error)

func (*Ctx) SetUser

func (c *Ctx) SetUser(user interface{})

func (*Ctx) SetUserGUID

func (c *Ctx) SetUserGUID(guid uuid.GUID)

func (*Ctx) SetUserID

func (c *Ctx) SetUserID(id int)

func (*Ctx) SetUserInfo

func (c *Ctx) SetUserInfo(userInfo string)

func (*Ctx) Success

func (c *Ctx) Success(data interface{})

func (*Ctx) User

func (c *Ctx) User() interface{}

func (*Ctx) UserGUID

func (c *Ctx) UserGUID() (uuid.GUID, bool)

func (*Ctx) UserID

func (c *Ctx) UserID() (int, bool)

func (*Ctx) UserInfo

func (c *Ctx) UserInfo() (string, bool)

type Handler

type Handler struct {
	Middleware    []Middleware
	GinMiddleware []gin.HandlerFunc
	RelativePath  string
	HttpMethod    string
}

func (*Handler) Delete

func (h *Handler) Delete(path string)

func (*Handler) Get

func (h *Handler) Get(path string)

func (*Handler) Head

func (h *Handler) Head(path string)

func (*Handler) Options

func (h *Handler) Options(path string)

func (*Handler) Patch

func (h *Handler) Patch(path string)

func (*Handler) Post

func (h *Handler) Post(path string)

func (*Handler) Put

func (h *Handler) Put(path string)

func (*Handler) Route

func (h *Handler) Route(httpMethod string, path string)

func (*Handler) Use

func (h *Handler) Use(handlerFunc ...gin.HandlerFunc)

func (*Handler) UseMiddleware

func (h *Handler) UseMiddleware(m ...Middleware)

type HandlerFunc

type HandlerFunc func(*Ctx)

type IBaseService

type IBaseService interface {
	Get(*Handler) HandlerFunc
	GetList(*Handler) HandlerFunc
	Post(*Handler) HandlerFunc
	Delete(*Handler) HandlerFunc
	DeleteBatch(*Handler) HandlerFunc
	Put(*Handler) HandlerFunc
	Head(*Handler) HandlerFunc
	Patch(*Handler) HandlerFunc
	Options(*Handler) HandlerFunc

	Use(*Handler)

	Repo() *repo.Repository
	SetRepo(*repo.Repository)
	Redis() *redis.RdClient
	SetRedis(*redis.RdClient)
	Mongo() *mongo.MgoClient
	SetMongo(*mongo.MgoClient)
	Client() *httpclient.ReqClient
	SetClient(*httpclient.ReqClient)
	Node() *NodeInfo
	SetNode(*NodeInfo)
	Reg() *Registry
	SetReg(*Registry)
	Interceptor() *Interceptor
	SetInterceptor(*Interceptor)

	CustomContext(string) interface{}
	SetCustomContext(string, interface{})
}

func NewService

func NewService(service IBaseService, option ...Option) IBaseService

type Interceptor

type Interceptor struct {
	Metric  *metric.Metric
	Tracer  *tracing.Tracer
	Limiter *limit.Limiter
	Cb      *breaker.CircuitBreaker
}

type Middleware

type Middleware func(IBaseService) HandlerFunc

Middleware 中间件

func AuthMiddleware

func AuthMiddleware() Middleware

func BreakerMiddleware

func BreakerMiddleware(cb *breaker.CircuitBreaker) Middleware

BreakerMiddleware 断路器中间件

func DelayLimiterMiddleware

func DelayLimiterMiddleware(limiter *limit.Limiter) Middleware

DelayLimiterMiddleware 频率延迟中间件

func ExtractHttpMiddleware

func ExtractHttpMiddleware() Middleware

func MetricMiddleware

func MetricMiddleware(m *metric.Metric) Middleware

MetricMiddleware 指标监控中间件

func RateLimiterMiddleware

func RateLimiterMiddleware(limiter *limit.Limiter) Middleware

RateLimiterMiddleware 频率限制中间件

func ReserveLimiterMiddleware

func ReserveLimiterMiddleware(limiter *limit.Limiter) Middleware

func TracerMiddleware

func TracerMiddleware(t *tracing.Tracer, name string) Middleware

TracerMiddleware 服务跟踪中间件

type NodeInfo

type NodeInfo struct {
	Id         string
	ServerName string
	Name       string
	Port       string
	Address    string
}

type Option

type Option func(service IBaseService)

func Cb

func Cb(circuitBreaker *breaker.CircuitBreaker) Option

func CustomContext

func CustomContext(key string, value interface{}) Option

func Limiter

func Limiter(limiter *limit.Limiter) Option

func Metric

func Metric(m *metric.Metric) Option

func MongoClient

func MongoClient(client *mongo.MgoClient) Option

func RedisClient

func RedisClient(redisClient *redis.RdClient) Option

func Repository

func Repository(repository *repo.Repository) Option

func Tracer

func Tracer(tracer *tracing.Tracer) Option

type Registry

type Registry struct {
	sync.Mutex
	*consul.Client
	Services []*NodeInfo
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry(addr string, s ...selector.Selector) *Registry

func (*Registry) Deregister

func (r *Registry) Deregister(node *NodeInfo, group *sync.WaitGroup, errChan chan error)

func (*Registry) GetService

func (r *Registry) GetService(name string) (*NodeInfo, error)

func (*Registry) Inject

func (r *Registry) Inject(service IBaseService)

func (*Registry) InjectSlice

func (r *Registry) InjectSlice(services ...IBaseService)

func (*Registry) Register

func (r *Registry) Register(node *NodeInfo, group *sync.WaitGroup, errChan chan error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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