napodate

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: 8 Imported by: 0

README

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeGetEndpoint

func MakeGetEndpoint(srv Service) endpoint.Endpoint

MakeGetEndpoint 返回 「get」服务的响应

func MakeStatusEndpoint

func MakeStatusEndpoint(srv Service) endpoint.Endpoint

MakeStatusEndpoint 返回 「status」服务的响应

func MakeValidateEndpoint

func MakeValidateEndpoint(srv Service) endpoint.Endpoint

MakeValidateEndpoint 返回「validate」服务的响应

func NewHTTPServer

func NewHTTPServer(ctx context.Context, endpoints Endpoints) http.Handler

NewHTTPServer 是一个很好的服务器

Types

type Endpoints

type Endpoints struct {
	GetEndpoint      endpoint.Endpoint // Get方法的端点
	StatusEndpoint   endpoint.Endpoint // Status方法的端点
	ValidateEndpoint endpoint.Endpoint // Validate方法的端点
}

Endpoints 公开端点

func (Endpoints) Get

func (e Endpoints) Get(ctx context.Context) (string, error)

Get get 端点映射

func (Endpoints) Status

func (e Endpoints) Status(ctx context.Context) (string, error)

Status Status 端点映射

func (Endpoints) Validate

func (e Endpoints) Validate(ctx context.Context, date string) (bool, error)

Validate Validate 端点映射

type Service

type Service interface {
	Status(ctx context.Context) (string, error)              // 状态
	Get(ctx context.Context) (string, error)                 // 获取
	Validate(ctx context.Context, date string) (bool, error) // 校验
}

Service 服务为您的应用程序提供了一些「日期功能」 在这里,我们为服务定义了「蓝图」:在 Go kit 中,您必须将服务建模为接口 如上所述,我们将需要三个端点,这些端点将被映射到此接口。 为什么我们要使用 context 包?请阅读 https://blog.golang.org/context 在 Google,我们开发了一个上下文包,可轻松将跨 API 边界的请求范围的值,取消信号和截止日期传递给处理请求的所有协程 基本上,这是必需的,因为我们的微服务应该从一开始就处理并发请求,并且必须为每个请求提供上下文。 不要把事情搞混。本教程后面的内容将对此进行详细介绍。我们现在用的不多,但要习惯它! 现在我们有了微服务接口。

func NewService

func NewService() Service

NewService 创建一个新的服务

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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