oracle

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: BSD-3-Clause Imports: 33 Imported by: 2

Documentation

Overview

Package oracle defines a simple system for http middleware built around functions with the following signature:

func Wrap(h http.Handler) http.Handler

The middleware are chained together using the middlewareChain type which can wrap the grpc-gateway to augment how it serves the API.

Package oracle is a framework that provides a REST/JSON API defined using a GRPC spec, that communicates with the phylum.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call[K proto.Message, R proto.Message](s *Oracle, ctx context.Context, methodName string, req K, resp R, config ...shiroclient.Config) (R, error)

Call calls the phylum.

Types

type Config

type Config struct {

	// ListenAddress is an address the oracle HTTP listens on.
	ListenAddress string `yaml:"listen-address"`
	// PhylumPath is the the path for the business logic.
	PhylumPath string `yaml:"phylum-path"`
	// GatewayEndpoint is an address to the shiroclient gateway.
	GatewayEndpoint string `yaml:"gateway-endpoint"`
	// PhylumServiceName is the app-specific name of the conneted phylum.
	PhylumServiceName string `yaml:"phylum-service-name"`
	// ServiceName is the app-specific name of the Oracle.
	ServiceName string `yaml:"service-name"`
	// RequestIDHeader is the HTTP header encoding the request ID.
	RequestIDHeader string `yaml:"request-id-header"`
	// Version is the oracle version.
	Version string `yaml:"version"`
	// TraceOpts are tracing options.
	TraceOpts []opttrace.Option
	// Verbose increases logging.
	Verbose bool `yaml:"verbose"`
	// EmulateCC emulates chaincode in memory (for testing).
	EmulateCC bool `yaml:"emulate-cc"`
	// contains filtered or unexported fields
}

Config configures an oracle.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default config.

func (*Config) SetOTLPEndpoint

func (c *Config) SetOTLPEndpoint(endpoint string)

SetOTLPEndpoint is a helper to set the OTLP trace endpoint.

func (*Config) SetSwaggerHandler

func (c *Config) SetSwaggerHandler(h http.Handler)

SetSwaggerHandler configures an endpoint to serve the swagger API.

func (*Config) Valid

func (c *Config) Valid() error

Valid validates an oracle configuration.

type GrpcGatewayConfig

type GrpcGatewayConfig interface {
	// RegisterServiceServer is required to be overidden by the implementation.
	RegisterServiceServer(grpcServer *grpc.Server)
	// RegisterServiceClient is required to be overidden by the implementation.
	RegisterServiceClient(ctx context.Context, grpcCon *grpc.ClientConn, mux *runtime.ServeMux) error
}

GrpcGatewayConfig configures the grpc gateway used by the oracle.

type Oracle

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

Oracle provides services.

func NewOracle

func NewOracle(config *Config) (*Oracle, error)

NewOracle allocates an oracle

func NewTestOracle

func NewTestOracle(t *testing.T, cfg *Config, testOpts ...TestOpt) (*Oracle, func())

NewTestOracle is used to create an oracle for testing.

func (*Oracle) GetHealthCheck

GetHealthCheck checks this service and all dependent services to construct a health report. Returns a grpc error code if a service is down.

func (*Oracle) Snapshot

func (orc *Oracle) Snapshot(t *testing.T) []byte

Snapshot takes a snapshot of the current oracle.

func (*Oracle) StartGateway

func (orc *Oracle) StartGateway(ctx context.Context, grpcConfig GrpcGatewayConfig) error

type TestOpt

type TestOpt func(*testCfg)

TestOpt configures a test oracle.

func WithSnapshot

func WithSnapshot(b []byte) TestOpt

WithSnapshot restores the test oracle from a snapshot.

Jump to

Keyboard shortcuts

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