bff

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectGDS

func ConnectGDS(conf config.DirectoryConfig) (_ gds.TRISADirectoryClient, err error)

ConnectGDS creates a gRPC client to the TRISA Directory Service specified in the configuration. This method is used to connect to both the TestNet and the MainNet and to connect to mock GDS services in testing using buffconn.

func FlattenErrs

func FlattenErrs(in []error) (out []error)

FlattenErrs removes nil errors from the slice (exported for testing purposes).

func FlattenResults

func FlattenResults(in []proto.Message) (out []proto.Message)

FlattenResults removes nil proto messages from the slice (exported for testing purposes).

Types

type RPCFunc

type RPCFunc func(ctx context.Context, client gds.TRISADirectoryClient, network string) (proto.Message, error)

RPCFunc allows the BFF to issue arbitrary GDS client methods in parallel to both the testnet and the mainnet. The GDS client and network are passed into the function, allowing the RPC to make any GDS RPC call and log with the associated network.

type Server

type Server struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New(conf config.Config) (s *Server, err error)

New creates a new BFF server from the specified configuration.

func (*Server) Available

func (s *Server) Available() gin.HandlerFunc

Available is middleware that uses the healthy boolean to return a service unavailable http status code if the server is shutting down. This middleware must be first in the chain to ensure that complex handling to slow the shutdown of the server.

func (*Server) GetConf

func (s *Server) GetConf() config.Config

GetConf returns a copy of the current configuration.

func (*Server) GetMainNet

func (s *Server) GetMainNet() gds.TRISADirectoryClient

GetMainNet returns the MainNet directory client for testing purposes.

func (*Server) GetRouter

func (s *Server) GetRouter() http.Handler

GetRouter returns the Gin API router for testing purposes.

func (*Server) GetTestNet

func (s *Server) GetTestNet() gds.TRISADirectoryClient

GetTestNet returns the TestNet directory client for testing purposes.

func (*Server) GetURL

func (s *Server) GetURL() string

GetURL returns the URL that the server can be reached if it has been started. This accessor is primarily used to create a test client.

func (*Server) Lookup

func (s *Server) Lookup(c *gin.Context)

Lookup makes a request on behalf of the user to both the TestNet and MainNet GDS servers, returning 1-2 results (e.g. either or both GDS responses). If no results are returned, Lookup returns a 404 not found error. If one of the GDS requests fails, the error is logged, but the valid response is returned. If both GDS requests fail, a 500 error is returned. This endpoint passes through the response from GDS as JSON, the result should contain a registered_directory field that identifies which network the record is associated with.

func (*Server) ParallelGDSRequests

func (s *Server) ParallelGDSRequests(ctx context.Context, rpc RPCFunc, flatten bool) (results []proto.Message, errs []error)

ParallelGDSRequest makes concurrent requests to both the testnet and the mainnet, storing the results and errors in a slice of length 2 ([testnet, mainnet]). If the flatten bool is true, then nil values are removed from the slice (though this will make which network returned the result ambiguous).

func (*Server) Register

func (s *Server) Register(c *gin.Context)

Register makes a request on behalf of the user to either the TestNet or the MainNet GDS server based on the URL endpoint. This method is essentially a passthrough conversion of a JSON request to a gRPC request to GDS.

func (*Server) Serve

func (s *Server) Serve() (err error)

Serve API requests on the specified address.

func (*Server) SetClients

func (s *Server) SetClients(testnet, mainnet gds.TRISADirectoryClient)

SetClients allows tests to set a bufconn client to a mock GDS server.

func (*Server) SetDB

func (s *Server) SetDB(db *db.DB)

SetDB allows tests to set a bufconn client to a mock trtl server.

func (*Server) SetHealth

func (s *Server) SetHealth(health bool)

func (*Server) SetURL

func (s *Server) SetURL(url string)

func (*Server) Shutdown

func (s *Server) Shutdown() (err error)

func (*Server) Status

func (s *Server) Status(c *gin.Context)

func (*Server) TrackPerformance added in v1.4.1

func (s *Server) TrackPerformance() gin.HandlerFunc

Middleware that tracks request performance with Sentry.

func (*Server) VerifyContact

func (s *Server) VerifyContact(c *gin.Context)

VerifyContact is currently a passthrough helper that forwards the verify contact request from the user interface to the GDS that needs contact verification.

Directories

Path Synopsis
api
v1

Jump to

Keyboard shortcuts

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