string_service

package
v0.0.0-...-31e44ea Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StrMaxSize = 1024
)

Service constants

Variables

View Source
var (
	ErrMaxSize = errors.New("maximum size of 1024 bytes exceeded")

	ErrStrValue = errors.New("maximum size of 1024 bytes exceeded")
)

Service errors

View Source
var (
	ErrInvalidRequestType = errors.New("RequestType has only two type: Concat, Diff")
)
View Source
var (
	ErrorBadRequest = errors.New("invalid request parameter")
)

Functions

func DecodeConcatStringRequest

func DecodeConcatStringRequest(ctx context.Context, r interface{}) (interface{}, error)

func DecodeDiffStringRequest

func DecodeDiffStringRequest(ctx context.Context, r interface{}) (interface{}, error)

func EncodeStringResponse

func EncodeStringResponse(_ context.Context, r interface{}) (interface{}, error)

func MakeHealthCheckEndpoint

func MakeHealthCheckEndpoint(svc Service) endpoint.Endpoint

MakeHealthCheckEndpoint 创建健康检查Endpoint

func MakeStringEndpoint

func MakeStringEndpoint(svc Service) endpoint.Endpoint

MakeStringEndpoint 创建字符串服务的endpoint

func NewStringServer

func NewStringServer(ctx context.Context, endpoints StringEndpoints) pb.StringServiceServer

Types

type HealthRequest

type HealthRequest struct{}

HealthRequest 健康检查请求结构

type HealthResponse

type HealthResponse struct {
	Status bool `json:"status"`
}

HealthResponse 健康检查响应结构

type Service

type Service interface {
	// Concat a and b
	Concat(ctx context.Context, a, b string) (string, error)

	// a,b pkg string value
	Diff(ctx context.Context, a, b string) (string, error)
}

Service Define a service interface

type ServiceMiddleware

type ServiceMiddleware func(Service) Service

ServiceMiddleware define service middleware

func LoggingMiddleware

func LoggingMiddleware(logger log.Logger) ServiceMiddleware

LoggingMiddleware make logging middleware

type StringEndpoints

type StringEndpoints struct {
	StringEndpoint      endpoint.Endpoint
	HealthCheckEndpoint endpoint.Endpoint
}

CalculateEndpoint define endpoint

func (StringEndpoints) Concat

func (ue StringEndpoints) Concat(ctx context.Context, a string, b string) (string, error)

func (StringEndpoints) Diff

func (ue StringEndpoints) Diff(ctx context.Context, a string, b string) (string, error)

type StringRequest

type StringRequest struct {
	RequestType string `json:"request_type"`
	A           string `json:"a"`
	B           string `json:"b"`
}

StringRequest define request struct

type StringResponse

type StringResponse struct {
	Result string `json:"result"`
	Error  error  `json:"error"`
}

StringResponse define response struct

type StringService

type StringService struct {
}

ArithmeticService implement Service interface

func (StringService) Concat

func (s StringService) Concat(ctx context.Context, a, b string) (string, error)

func (StringService) Diff

func (s StringService) Diff(ctx context.Context, a, b string) (string, error)

Jump to

Keyboard shortcuts

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