endpoint

package
v0.0.0-...-cda3813 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package endpoint contains offers for configuring and constructing github.com/go-kit/kit/endpoint.Endpoint.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

Config is a group of options for a endpoint Set.

func NewConfig

func NewConfig(opts ...Option) Config

NewConfig applies all the options to a returned Config.

func (Config) Middleware

func (c Config) Middleware() endpoint.Middleware

Middleware returns a composed middlewares. Requests will traverse them in the order they're declared.

type Option

type Option interface {
	// contains filtered or unexported methods
}

A Option sets options to config.

func WithMiddlewares

func WithMiddlewares(
	middlewares ...endpoint.Middleware,
) Option

WithMiddlewares returns an Option that appends middlewares to the configured endpoint.

Example
package main

import (
	"context"
	"fmt"

	kitendpoint "github.com/go-kit/kit/endpoint"

	"github.com/gorhythm/concerto/endpoint"
)

func main() {
	cfg := endpoint.NewConfig(
		endpoint.WithMiddlewares(
			annotate("first"),
			annotate("second"),
			annotate("third"),
		),
	)

	e := cfg.Middleware()(myEndpoint)
	if _, err := e(context.Background(), struct{}{}); err != nil {
		panic(err)
	}

}

func annotate(s string) kitendpoint.Middleware {
	return func(next kitendpoint.Endpoint) kitendpoint.Endpoint {
		return func(ctx context.Context, req any) (any, error) {
			fmt.Println(s, "pre")
			defer fmt.Println(s, "post")
			return next(ctx, req)
		}
	}
}

func myEndpoint(context.Context, any) (any, error) {
	fmt.Println("my endpoint!")
	return struct{}{}, nil
}
Output:

first pre
second pre
third pre
my endpoint!
third post
second post
first post

Directories

Path Synopsis
middleware
callmeta
Package callmeta provides middleware for setting CallMeta (service name, method name, transport) to the context of the request.
Package callmeta provides middleware for setting CallMeta (service name, method name, transport) to the context of the request.

Jump to

Keyboard shortcuts

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