intermediate

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package intermediate serves as the foundation of the directory.example microservice.

The directory microservice exposes a RESTful API for persisting personal records in a SQL database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Intermediate

type Intermediate struct {
	*connector.Connector
	// contains filtered or unexported fields
}

Intermediate extends and customizes the generic base connector. Code generated microservices then extend the intermediate.

func NewService

func NewService(impl ToDo, version int) *Intermediate

NewService creates a new intermediate service.

func (*Intermediate) SQL

func (svc *Intermediate) SQL() (dsn string)

SQL is the connection string to the database.

func (*Intermediate) SetSQL

func (svc *Intermediate) SetSQL(dsn string) error

SetSQL sets the value of the configuration property.

SQL is the connection string to the database.

type Mock

type Mock struct {
	*Intermediate
	// contains filtered or unexported fields
}

Mock is a mockable version of the directory.example microservice, allowing functions, event sinks and web handlers to be mocked.

func NewMock

func NewMock() *Mock

NewMock creates a new mockable version of the microservice.

func (*Mock) Create

func (svc *Mock) Create(ctx context.Context, httpRequestBody *directoryapi.Person) (key directoryapi.PersonKey, err error)

Create runs the mock handler set by MockCreate.

func (*Mock) Delete

func (svc *Mock) Delete(ctx context.Context, key directoryapi.PersonKey) (err error)

Delete runs the mock handler set by MockDelete.

func (*Mock) List

func (svc *Mock) List(ctx context.Context) (httpResponseBody []directoryapi.PersonKey, err error)

List runs the mock handler set by MockList.

func (*Mock) Load

func (svc *Mock) Load(ctx context.Context, key directoryapi.PersonKey) (httpResponseBody *directoryapi.Person, err error)

Load runs the mock handler set by MockLoad.

func (*Mock) LoadByEmail

func (svc *Mock) LoadByEmail(ctx context.Context, email string) (httpResponseBody *directoryapi.Person, err error)

LoadByEmail runs the mock handler set by MockLoadByEmail.

func (*Mock) MockCreate

func (svc *Mock) MockCreate(handler func(ctx context.Context, httpRequestBody *directoryapi.Person) (key directoryapi.PersonKey, err error)) *Mock

MockCreate sets up a mock handler for the Create endpoint.

func (*Mock) MockDelete

func (svc *Mock) MockDelete(handler func(ctx context.Context, key directoryapi.PersonKey) (err error)) *Mock

MockDelete sets up a mock handler for the Delete endpoint.

func (*Mock) MockList

func (svc *Mock) MockList(handler func(ctx context.Context) (httpResponseBody []directoryapi.PersonKey, err error)) *Mock

MockList sets up a mock handler for the List endpoint.

func (*Mock) MockLoad

func (svc *Mock) MockLoad(handler func(ctx context.Context, key directoryapi.PersonKey) (httpResponseBody *directoryapi.Person, err error)) *Mock

MockLoad sets up a mock handler for the Load endpoint.

func (*Mock) MockLoadByEmail

func (svc *Mock) MockLoadByEmail(handler func(ctx context.Context, email string) (httpResponseBody *directoryapi.Person, err error)) *Mock

MockLoadByEmail sets up a mock handler for the LoadByEmail endpoint.

func (*Mock) MockUpdate

func (svc *Mock) MockUpdate(handler func(ctx context.Context, key directoryapi.PersonKey, httpRequestBody *directoryapi.Person) (err error)) *Mock

MockUpdate sets up a mock handler for the Update endpoint.

func (*Mock) MockWebUI

func (svc *Mock) MockWebUI(handler func(w http.ResponseWriter, r *http.Request) (err error)) *Mock

MockWebUI sets up a mock handler for the WebUI endpoint.

func (*Mock) OnShutdown

func (svc *Mock) OnShutdown(ctx context.Context) (err error)

OnShutdown is a no op.

func (*Mock) OnStartup

func (svc *Mock) OnStartup(ctx context.Context) (err error)

OnStartup makes sure that the mock is not executed in a non-dev environment.

func (*Mock) Update

func (svc *Mock) Update(ctx context.Context, key directoryapi.PersonKey, httpRequestBody *directoryapi.Person) (err error)

Update runs the mock handler set by MockUpdate.

func (*Mock) WebUI

func (svc *Mock) WebUI(w http.ResponseWriter, r *http.Request) (err error)

WebUI runs the mock handler set by MockWebUI.

type ToDo

type ToDo interface {
	OnStartup(ctx context.Context) (err error)
	OnShutdown(ctx context.Context) (err error)
	Create(ctx context.Context, httpRequestBody *directoryapi.Person) (key directoryapi.PersonKey, err error)
	Load(ctx context.Context, key directoryapi.PersonKey) (httpResponseBody *directoryapi.Person, err error)
	Delete(ctx context.Context, key directoryapi.PersonKey) (err error)
	Update(ctx context.Context, key directoryapi.PersonKey, httpRequestBody *directoryapi.Person) (err error)
	LoadByEmail(ctx context.Context, email string) (httpResponseBody *directoryapi.Person, err error)
	List(ctx context.Context) (httpResponseBody []directoryapi.PersonKey, err error)
	WebUI(w http.ResponseWriter, r *http.Request) (err error)
}

ToDo defines the interface that the microservice must implement. The intermediate delegates handling to this interface.

Jump to

Keyboard shortcuts

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