server

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: BSD-2-Clause Imports: 37 Imported by: 2

Documentation

Index

Constants

View Source
const AllMethodsWildcard = "*" // every method, open the gates!
View Source
const RANCH_SERVER_ONLINE_CHANNEL = bus.RANCH_INTERNAL_CHANNEL_PREFIX + "ranch-online-notify"

Variables

This section is empty.

Functions

func CreateConfigJsonForTest

func CreateConfigJsonForTest() (string, error)

CreateConfigJsonForTest creates and returns the path to a file containing the plank configuration in JSON format

func GetTestPort

func GetTestPort() int

GetTestPort returns an available port for use by Plank tests

func RunWhenServerReady

func RunWhenServerReady(t *testing.T, eventBus bus.EventBus, fn func(*testing.T))

RunWhenServerReady runs test function fn after Plank has booted up

func SetupPlankTestSuiteForTest

func SetupPlankTestSuiteForTest(suite *PlankIntegrationTestSuite, test PlankIntegrationTest)

SetupPlankTestSuiteForTest will copy over everything from the newly set up test suite, to a suite being run.

Types

type FabricBrokerConfig

type FabricBrokerConfig struct {
	FabricEndpoint string              `json:"fabric_endpoint"` // URI to WebSocket endpoint
	UseTCP         bool                `json:"use_tcp"`         // Use TCP instead of WebSocket
	TCPPort        int                 `json:"tcp_port"`        // TCP port to use if UseTCP is true
	EndpointConfig *bus.EndpointConfig `json:"endpoint_config"` // STOMP configuration
}

FabricBrokerConfig defines the endpoint for WebSocket as well as detailed endpoint configuration

func GetTestFabricBrokerConfig

func GetTestFabricBrokerConfig() *FabricBrokerConfig

GetTestFabricBrokerConfig returns a basic fabric broker config.

type MessageBridge

type MessageBridge struct {
	ServiceListenStream bus.MessageHandler // message handler returned by bus.ListenStream responsible for relaying back messages as HTTP responses
	// contains filtered or unexported fields
}

MessageBridge is a conduit used for returning service responses as HTTP responses

type NoDirFileSystem

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

func (NoDirFileSystem) Open

func (nd NoDirFileSystem) Open(name string) (http.File, error)

type PlankIntegrationTest

type PlankIntegrationTest interface {
	SetPlatformServer(PlatformServer)
	SetSysChan(chan os.Signal)
	SetChannelManager(bus.ChannelManager)
	SetBus(eventBus bus.EventBus)
}

PlankIntegrationTest allows test suites that use PlankIntegrationTestSuite as an embedded struct to set everything we need on our test. This is the only contract required to use this harness.

type PlankIntegrationTestSuite

type PlankIntegrationTestSuite struct {

	// suite.Suite is a reference to a testify test suite.
	suite.Suite

	// server.PlatformServer is a reference to plank
	PlatformServer

	// os.Signal is the signal channel passed into plan for OS level notifications.
	Syschan chan os.Signal

	// bus.ChannelManager is a reference to the Transport's Channel Manager.
	bus.ChannelManager

	// bus.EventBus is a reference to Transport.
	bus.EventBus
}

PlankIntegrationTestSuite makes it easy to set up integration tests for services, that use plank and transport In a realistic manner. This is a convenience mechanism to avoid having to rig this harnessing up yourself.

func SetupPlankTestSuite

func SetupPlankTestSuite(service svc.FabricService, serviceChannel string, port int,
	config *PlatformServerConfig) (*PlankIntegrationTestSuite, error)

SetupPlankTestSuite will boot a new instance of plank on your chosen port and will also fire up your service Ready to be tested. This always runs on localhost.

type PlatformServer

type PlatformServer interface {
	StartServer(syschan chan os.Signal)                                         // start server
	StopServer()                                                                // stop server
	GetRouter() *mux.Router                                                     // get *mux.Router instance
	RegisterService(svc service.FabricService, svcChannel string) error         // register a new service at given channel
	SetHttpChannelBridge(bridgeConfig *service.RESTBridgeConfig)                // set up a REST bridge for a service
	SetStaticRoute(prefix, fullpath string, middlewareFn ...mux.MiddlewareFunc) // set up a static content route
	SetHttpPathPrefixChannelBridge(bridgeConfig *service.RESTBridgeConfig)      // set up a REST bridge for a path prefix for a service.
	CustomizeTLSConfig(tls *tls.Config) error                                   // used to replace default tls.Config for HTTP server with a custom config
	GetRestBridgeSubRoute(uri, method string) (*mux.Route, error)               // get *mux.Route that maps to the provided uri and method
	GetMiddlewareManager() middleware.MiddlewareManager                         // get middleware manager

}

PlatformServer exposes public API methods that control the behavior of the Plank instance.

func CreateTestServer

func CreateTestServer(config *PlatformServerConfig) (baseUrl, logFile string, s PlatformServer)

CreateTestServer consumes *server.PlatformServerConfig and returns a new instance of PlatformServer along with its base URL and log file name

func NewPlatformServer

func NewPlatformServer(config *PlatformServerConfig) PlatformServer

NewPlatformServer configures and returns a new platformServer instance

func NewPlatformServerFromConfig

func NewPlatformServerFromConfig(configPath string) (PlatformServer, error)

NewPlatformServerFromConfig returns a new instance of PlatformServer based on the config JSON file provided as configPath

type PlatformServerConfig

type PlatformServerConfig struct {
	RootDir           string              `json:"root_dir"`                       // root directory the server should base itself on
	StaticDir         []string            `json:"static_dir"`                     // static content folders that HTTP server should serve
	SpaConfig         *SpaConfig          `json:"spa_config"`                     // single page application configuration
	Host              string              `json:"host"`                           // hostname for the server
	Port              int                 `json:"port"`                           // port for the server
	Logger            *slog.Logger        `json:"-"`                              // logger instance
	FabricConfig      *FabricBrokerConfig `json:"fabric_config"`                  // Fabric (websocket) configuration
	TLSCertConfig     *TLSCertConfig      `json:"tls_config"`                     // TLS certificate configuration
	Debug             bool                `json:"debug"`                          // enable debug logging
	NoBanner          bool                `json:"no_banner"`                      // start server without displaying the banner
	ShutdownTimeout   time.Duration       `json:"shutdown_timeout_in_minutes"`    // graceful server shutdown timeout in minutes
	RestBridgeTimeout time.Duration       `json:"rest_bridge_timeout_in_minutes"` // rest bridge timeout in minutes
}

PlatformServerConfig holds all the core configuration needed for the functionality of Plank

func CreateServerConfig

func CreateServerConfig() (*PlatformServerConfig, error)

CreateServerConfig creates a new instance of PlatformServerConfig and returns the pointer to it.

func GetBasicTestServerConfig

func GetBasicTestServerConfig(rootDir, outLog, accessLog, errLog string, port int, noBanner bool) *PlatformServerConfig

GetBasicTestServerConfig will generate a simple platform server config, ready to use in a test.

type ServerAvailability

type ServerAvailability struct {
	Http   bool // Http server availability
	Fabric bool // stomp broker availability
}

ServerAvailability contains boolean fields to indicate what components of the system are available or not

type SpaConfig

type SpaConfig struct {
	RootFolder        string            `json:"root_folder"`         // location where Plank will serve SPA
	BaseUri           string            `json:"base_uri"`            // base URI for the SPA
	StaticAssets      []string          `json:"static_assets"`       // locations for static assets used by the SPA
	CacheControlRules map[string]string `json:"cache_control_rules"` // map holding glob pattern - cache-control header value
	// contains filtered or unexported fields
}

SpaConfig shorthand for SinglePageApplication Config is used to configure routes for your SPAs like Angular or React. for example if your app index.html is served at /app and static contents like JS/CSS are served from /app/static, BaseUri can be set to /app and StaticAssets to "/app/assets". see config.json for details.

func NewSpaConfig

func NewSpaConfig(input string) (spaConfig *SpaConfig, err error)

NewSpaConfig takes location to where the SPA content is as an input and returns a sanitized instance of *SpaConfig.

func (*SpaConfig) CacheControlMiddleware

func (s *SpaConfig) CacheControlMiddleware() mux.MiddlewareFunc

CacheControlMiddleware returns the middleware func to be used in route configuration

func (*SpaConfig) CollateCacheControlRules

func (s *SpaConfig) CollateCacheControlRules()

CollateCacheControlRules compiles glob patterns and stores them as an array.

type TLSCertConfig

type TLSCertConfig struct {
	CertFile                  string `json:"cert_file"`                   // path to certificate file
	KeyFile                   string `json:"key_file"`                    // path to private key file
	SkipCertificateValidation bool   `json:"skip_certificate_validation"` // whether to skip certificate validation (useful for self-signed cert)
}

TLSCertConfig wraps around key information for TLS configuration

func GetTestTLSCertConfig

func GetTestTLSCertConfig(testRootPath string) *TLSCertConfig

GetTestTLSCertConfig returns a new &TLSCertConfig for testing.

Jump to

Keyboard shortcuts

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