messaging

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: MIT Imports: 12 Imported by: 0

README

messaging

This example illustrates how to specify multiple HTTP request operations.

Generate the code

$ go generate

Test the server

Run the server:

$ go run cmd/main.go
2022/02/26 17:45:20 transport=HTTP addr=:8080

Get a message:

$ curl -XGET 'http://localhost:8080/messages/123456'
{"text":"user[]: message[123456]"}

Get a message from a specific user:

$ curl -XGET 'http://localhost:8080/users/me/messages/123456'
{"text":"user[me]: message[123456]"}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeEndpointOfGetMessage

func MakeEndpointOfGetMessage(s Service) endpoint.Endpoint

MakeEndpointOfGetMessage creates the endpoint for s.GetMessage.

func NewHTTPRouter

func NewHTTPRouter(svc Service, codecs httpcodec.Codecs, opts ...httpoption.Option) chi.Router

func OASv2APIDoc

func OASv2APIDoc(schema oas2.Schema) string

func ValidateGetMessageRequest

func ValidateGetMessageRequest(newSchema func(*GetMessageRequest) validating.Schema) httpoption.Validator

ValidateGetMessageRequest creates a validator for GetMessageRequest.

Types

type GetMessageRequest

type GetMessageRequest struct {
	UserID    string `json:"-"`
	MessageID string `json:"-"`
}

type GetMessageResponse

type GetMessageResponse struct {
	Text string `json:"text"`
	Err  error  `json:"-"`
}

func (*GetMessageResponse) Body

func (r *GetMessageResponse) Body() interface{}

func (*GetMessageResponse) Failed

func (r *GetMessageResponse) Failed() error

Failed implements endpoint.Failer.

type HTTPClient

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

func NewHTTPClient

func NewHTTPClient(codecs httpcodec.Codecs, httpClient *http.Client, baseURL string) (*HTTPClient, error)

func (*HTTPClient) GetMessage

func (c *HTTPClient) GetMessage(ctx context.Context, userID string, messageID string) (text string, err error)

type Messaging

type Messaging struct{}

func (*Messaging) GetMessage

func (m *Messaging) GetMessage(ctx context.Context, userID string, messageID string) (string, error)

type Service

type Service interface {
	//kun:op GET /messages/{messageID}
	//kun:op GET /users/{userID}/messages/{messageID}
	GetMessage(ctx context.Context, userID string, messageID string) (text string, err error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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