core

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RequestIDKey = "X-Request-ID"
	UserIDKey    = "X-User-ID"
)

Variables

View Source
var MetaKeys = []string{

	RequestIDKey,

	UserIDKey,
}

Functions

func DecodeNatsResponseFunc

func DecodeNatsResponseFunc(ctx context.Context, msg *nats.Msg) (response interface{}, err error)

func DecodeResponseFunc

func DecodeResponseFunc(ctx context.Context, req micro.Request) (response interface{}, err error)

func GetContextFromNatsMicroRequest

func GetContextFromNatsMicroRequest(ctx context.Context, request micro.Request) context.Context

func GetContextFromNatsMsg

func GetContextFromNatsMsg(ctx context.Context, msg *nats.Msg) context.Context

func GetStringFromContext

func GetStringFromContext(ctx context.Context, key string) (result string, err error)

func MakeNatsClientEndpoint

func MakeNatsClientEndpoint(
	publisher *nats.Conn,
	sub string,
	options ...PublisherOption) endpoint.Endpoint

MakeNatsClientEndpoint make nats client endpoint

func MakeSubjectName

func MakeSubjectName(env, serviceName, endpointName string) string

func RegisterEndpointNode

func RegisterEndpointNode[REQ, RESP any](ec EndpointCollector, endpointName string, serviceFunc func(context.Context, REQ) (RESP, error), middlewares ...gokitendpoint.Middleware)

func SetNatsMsgFormContext

func SetNatsMsgFormContext(ctx context.Context, msg *nats.Msg) context.Context

func SetStringToContext

func SetStringToContext(ctx context.Context, k, v string) context.Context

Types

type EmptyReq

type EmptyReq struct {
}

type EmptyResp

type EmptyResp struct {
}

type EndpointCollector

type EndpointCollector interface {
	SetEndpointNode(key string, et EndpointMaker)
	GetEndpointNode(key string) EndpointMaker
	GetEndpointNodesMapper() map[string]EndpointMaker
	Middlewares() []gokitendpoint.Middleware
	RegisterMiddlewares(mws ...gokitendpoint.Middleware)
}

type EndpointMaker

type EndpointMaker interface {
	Name() string
	Request() interface{}
	Response() interface{}
	Middlewares() []gokitendpoint.Middleware
	Endpoint(mws ...gokitendpoint.Middleware) gokitendpoint.Endpoint
	RegisterMiddlewares(mws ...gokitendpoint.Middleware)
	GenerateHttpTransport() HttpTransportI
	GenerateNatsMicroTransport() NatsMicroTransportI
}

type EndpointNode

type EndpointNode[REQ, RESP any] struct {
	EndpointName string
	ServiceFunc  func(context.Context, REQ) (RESP, error)
	// contains filtered or unexported fields
}

func (*EndpointNode[REQ, RESP]) Endpoint

func (e *EndpointNode[REQ, RESP]) Endpoint(mws ...gokitendpoint.Middleware) gokitendpoint.Endpoint

func (*EndpointNode[REQ, RESP]) GenerateHttpTransport

func (e *EndpointNode[REQ, RESP]) GenerateHttpTransport() HttpTransportI

func (*EndpointNode[REQ, RESP]) GenerateNatsMicroTransport

func (e *EndpointNode[REQ, RESP]) GenerateNatsMicroTransport() NatsMicroTransportI

func (*EndpointNode[REQ, RESP]) Middlewares

func (e *EndpointNode[REQ, RESP]) Middlewares() []gokitendpoint.Middleware

func (*EndpointNode[REQ, RESP]) Name

func (e *EndpointNode[REQ, RESP]) Name() string

func (*EndpointNode[REQ, RESP]) RegisterMiddlewares

func (e *EndpointNode[REQ, RESP]) RegisterMiddlewares(mws ...gokitendpoint.Middleware)

func (*EndpointNode[REQ, RESP]) Request

func (e *EndpointNode[REQ, RESP]) Request() interface{}

func (*EndpointNode[REQ, RESP]) Response

func (e *EndpointNode[REQ, RESP]) Response() interface{}

type EndpointNodeMapper

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

func NewEndpointNodeMapper

func NewEndpointNodeMapper() EndpointNodeMapper

func (*EndpointNodeMapper) GetEndpointNode

func (e *EndpointNodeMapper) GetEndpointNode(key string) EndpointMaker

func (*EndpointNodeMapper) GetEndpointNodesMapper

func (e *EndpointNodeMapper) GetEndpointNodesMapper() map[string]EndpointMaker

func (*EndpointNodeMapper) Middlewares

func (e *EndpointNodeMapper) Middlewares() []gokitendpoint.Middleware

func (*EndpointNodeMapper) RegisterMiddlewares

func (e *EndpointNodeMapper) RegisterMiddlewares(mws ...gokitendpoint.Middleware)

func (*EndpointNodeMapper) SetEndpointNode

func (e *EndpointNodeMapper) SetEndpointNode(key string, et EndpointMaker)

type ErrDetail

type ErrDetail struct {
	Detail string `json:"detail"` // 错误详细信息
}

type GenericCommonResponse

type GenericCommonResponse[T any] struct {
	Code int    `json:"code" default:"200"` // 业务Code
	Msg  string `json:"msg"`                // 消息
	Data T      `json:"data"`               // 数据
}

type GenericModelList

type GenericModelList[T any] struct {
	List []T `json:"list"`
}

type GenericResponse

type GenericResponse[T any] struct {
	Code int    `json:"code" default:"0"`
	Msg  string `json:"msg"`
	Data T      `json:"data"`
}

func ErrResp

func ErrResp(msg string, err error) GenericResponse[interface{}]

func NewResponse

func NewResponse(code int, msg string, data interface{}) GenericResponse[interface{}]

func SuccessResp

func SuccessResp(msg string, data interface{}) GenericResponse[interface{}]

type HttpTransport

type HttpTransport[REQ, RESP any] struct {
	EndpointName string
}

func (*HttpTransport[REQ, RESP]) MakeDecodeRequestFunc

func (t *HttpTransport[REQ, RESP]) MakeDecodeRequestFunc() coder.DecodeHttpRequestFunc

func (*HttpTransport[REQ, RESP]) MakeDecodeResponseFunc

func (t *HttpTransport[REQ, RESP]) MakeDecodeResponseFunc() coder.DecodeHttpResponseFunc

func (*HttpTransport[REQ, RESP]) MakeEncodeRequestFunc

func (t *HttpTransport[REQ, RESP]) MakeEncodeRequestFunc() coder.EncodeHttpRequestFunc

func (*HttpTransport[REQ, RESP]) MakeEncodeResponseFunc

func (t *HttpTransport[REQ, RESP]) MakeEncodeResponseFunc() coder.EncodeHttpResponseFunc

type HttpTransportI

type HttpTransportI interface {
	MakeDecodeRequestFunc() coder.DecodeHttpRequestFunc
	MakeEncodeRequestFunc() coder.EncodeHttpRequestFunc
	MakeDecodeResponseFunc() coder.DecodeHttpResponseFunc
	MakeEncodeResponseFunc() coder.EncodeHttpResponseFunc
}

type IdPathReq

type IdPathReq struct {
	Id string `json:"id" form:"id" uri:"id"` // ID
}

type IdReq

type IdReq struct {
	Id string `json:"id" form:"id" uri:"id"` // ID
}

type IdsReq

type IdsReq struct {
	Ids []string `json:"ids"` // ID 列表
}

type MapReq

type MapReq map[string]interface{}

type NatsMicroTransport

type NatsMicroTransport[REQ, RESP any] struct {
	EndpointName string
}

func (*NatsMicroTransport[REQ, RESP]) MakeDecodeRequestFunc

func (t *NatsMicroTransport[REQ, RESP]) MakeDecodeRequestFunc() coder.DecodeNatsMicroRequestFunc

func (*NatsMicroTransport[REQ, RESP]) MakeDecodeResponseFunc

func (t *NatsMicroTransport[REQ, RESP]) MakeDecodeResponseFunc() coder.DecodeNatsMicroResponseFunc

func (*NatsMicroTransport[REQ, RESP]) MakeEncodeRequestFunc

func (t *NatsMicroTransport[REQ, RESP]) MakeEncodeRequestFunc() coder.EncodeNatsMicroRequestFunc

func (*NatsMicroTransport[REQ, RESP]) MakeEncodeResponseFunc

func (t *NatsMicroTransport[REQ, RESP]) MakeEncodeResponseFunc() coder.EncodeNatsMicroResponseFunc

type NatsMicroTransportI

type NatsMicroTransportI interface {
	MakeDecodeRequestFunc() coder.DecodeNatsMicroRequestFunc
	MakeEncodeRequestFunc() coder.EncodeNatsMicroRequestFunc
	MakeDecodeResponseFunc() coder.DecodeNatsMicroResponseFunc
	MakeEncodeResponseFunc() coder.EncodeNatsMicroResponseFunc
}

type NatsTransport

type NatsTransport[REQ, RESP any] struct {
	EndpointName string
}

func (*NatsTransport[REQ, RESP]) MakeDecodeRequestFunc

func (t *NatsTransport[REQ, RESP]) MakeDecodeRequestFunc() natstransport.DecodeRequestFunc

func (*NatsTransport[REQ, RESP]) MakeDecodeResponseFunc

func (t *NatsTransport[REQ, RESP]) MakeDecodeResponseFunc() natstransport.DecodeResponseFunc

func (*NatsTransport[REQ, RESP]) MakeEncodeRequestFunc

func (t *NatsTransport[REQ, RESP]) MakeEncodeRequestFunc() natstransport.EncodeRequestFunc

func (*NatsTransport[REQ, RESP]) MakeEncodeResponseFunc

func (t *NatsTransport[REQ, RESP]) MakeEncodeResponseFunc() natstransport.EncodeResponseFunc

type NatsTransportI

type NatsTransportI interface {
	MakeDecodeRequestFunc() natstransport.DecodeRequestFunc
	MakeEncodeRequestFunc() natstransport.EncodeRequestFunc
	MakeDecodeResponseFunc() natstransport.DecodeResponseFunc
	MakeEncodeResponseFunc() natstransport.EncodeResponseFunc
}

type PageReq

type PageReq struct {
	Page     int64 `json:"page" form:"page"`         // 页码
	PageSize int64 `json:"pageSize" form:"pageSize"` // 页长
}

type PageResp

type PageResp struct {
	Total    int64 `json:"total"`    // 记录总数
	Page     int64 `json:"page"`     // 页码
	PageSize int64 `json:"pageSize"` // 页长
}

type Publisher

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

Publisher wraps a URL and provides a method that implements endpoint.Endpoint.

func NewNatsPublisher

func NewNatsPublisher(
	publisher *nats.Conn,
	subject string,
	enc natstransport.EncodeRequestFunc,
	dec natstransport.DecodeResponseFunc,
	options ...PublisherOption,
) *Publisher

NewNatsPublisher constructs a usable Publisher for a single remote method.

func NewPublisher

func NewPublisher(
	publisher *nats.Conn,
	sub string,
	options ...PublisherOption) *Publisher

func (Publisher) Endpoint

func (p Publisher) Endpoint() endpoint.Endpoint

Endpoint returns a usable endpoint that invokes the remote endpoint.

type PublisherOption

type PublisherOption func(*Publisher)

PublisherOption sets an optional parameter for clients.

func PublisherAfter

func PublisherAfter(after ...natstransport.PublisherResponseFunc) PublisherOption

PublisherAfter sets the ClientResponseFuncs applied to the incoming NATS request prior to it being decoded. This is useful for obtaining anything off of the response and adding onto the context prior to decoding.

func PublisherBefore

func PublisherBefore(before ...natstransport.RequestFunc) PublisherOption

PublisherBefore sets the RequestFuncs that are applied to the outgoing NATS request before it's invoked.

func PublisherTimeout

func PublisherTimeout(timeout time.Duration) PublisherOption

PublisherTimeout sets the available timeout for NATS request.

type RequestFunc

type RequestFunc[T any] func(ctx context.Context, req any) (resp GenericResponse[T], err error)

func NewNatsClientRequest

func NewNatsClientRequest[T any](
	nc *nats.Conn,
	envGroup string,
	serviceName string,
	endpointName string,
	options ...PublisherOption) RequestFunc[T]

NewNatsClientRequest make nats client Request func

type Response

type Response struct {
	Code int         `json:"code" default:"0"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

type SearchReq

type SearchReq struct {
	Search string `json:"search" form:"search"` // 搜索字符串
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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