server

package module
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 3 Imported by: 8

README

go-server

This repository implements a "monolithic generic task server", which can serve requests over HTTP and FastCGI. There is a "plugin architecture" which can be embedded within the server at compile time, or dynamically loaded as plugins at runtime.

Standard plugins provided include:

  • httpserver which provides a simple HTTP server and routing of requests to plugins;
  • router to route requests to different handlers;
  • nginx to manage a running nginx reverse proxy instance;
  • static to serve static files;
  • certmanager to manage trust and certificates.

The motivation for this module is to provide a generic server which can be developed and scaled over time. Ultimately the running process is a large "monolith" server which can be composed of many smaller "plugins", which can be connected together loosely.

Requirements and Building

Any modern go compiler should be able to build the server command, 1.22 and above. It has been tested on MacOS and Linux. To build the server and plugins, run:

git clone git@github.com:mutablelogic/go-server.git
cd go-server && make

This places all the binaries in the build directory. There are several other make targets:

  • make clean to remove all build artifacts;
  • make test to run all tests;
  • ARCH=<arm64|amd64> OS=<linux|darwin> make to cross-compile the binary;
  • DOCKER_REPOSITORY=docker.io/user make docker to build a docker image.
  • DOCKER_REPOSITORY=docker.io/user make docker-push to push a docker image.

Running the Server

You can run the server:

  1. With a HTTP server over network: You can specify TSL key and certificate to serve requests over a secure connection;
  2. With a HTTP server with FastCGI over a unix socket: You would want to do this if the server is behind a reverse proxy such as nginx.
  3. In a docker container, and expose the port outside the container. The docker container targets amd64 and arm64 architectures on Linux.

Project Status

This module is currently in development and is not yet ready for any production environment.

Community & License

File an issue or question on github.

Licensed under Apache 2.0, please read that license about using and forking. The main conditions require preservation of copyright and license notices. Contributors provide an express grant of patent rights. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	// Print logging message
	Print(context.Context, ...any)

	// Print formatted logging message
	Printf(context.Context, string, ...any)
}

Logger interface

type Middleware

type Middleware interface {
	Task

	// Wrap a handler function
	Wrap(context.Context, http.HandlerFunc) http.HandlerFunc
}

Middleware represents an interceptor for HTTP requests

type Plugin

type Plugin interface {
	// Return the unique name for the plugin
	Name() string

	// Return a description of the plugin
	Description() string

	// Create a task from a plugin
	New() (Task, error)
}

Plugin represents a plugin that can create a task

type Provider

type Provider interface {
	Task
	Logger
}

Provider interface

type Router

type Router interface {
	Task

	// Add a handler to the router, with the given path
	// and methods. The context is used to pass additional
	// parameters to the handler. If no methods are provided, then
	// all methods are allowed.
	AddHandler(context.Context, string, http.Handler, ...string)

	// Add a handler function to the router, with the given path
	// and methods. The context is used to pass additional
	// parameters to the handler. If no methods are provided, then
	// all methods are allowed.
	AddHandlerFunc(context.Context, string, http.HandlerFunc, ...string)

	// Add a handler to the router, with the given regular expression
	// path and methods. The context is used to pass additional
	// parameters to the handler. If no methods are provided, then
	// all methods are allowed.
	AddHandlerRe(context.Context, *regexp.Regexp, http.Handler, ...string)

	// Add a handler function to the router, with the given regular expression
	// path and methods. The context is used to pass additional
	// parameters to the handler. If no methods are provided, then
	// all methods are allowed.
	AddHandlerFuncRe(context.Context, *regexp.Regexp, http.HandlerFunc, ...string)
}

Router represents a router to which you can add requests

type ServiceEndpoints added in v1.4.2

type ServiceEndpoints interface {
	Task

	// Add the endpoints to the router, with the given middleware
	AddEndpoints(context.Context, Router)
}

ServiceEndpoints represents a set of http service endpoints to route requests to

type Task added in v1.0.48

type Task interface {
	// Return the label for the task
	Label() string

	// Run the task until the context is cancelled and return any errors
	Run(context.Context) error
}

Task represents a task that can be run

Directories

Path Synopsis
cmd
pkg
handler/nginx
The `nginx` task spawns an nginx server, and can test and reload the nginx configuration programmatically or through the API gateway.
The `nginx` task spawns an nginx server, and can test and reload the nginx configuration programmatically or through the API gateway.
handler/nginx/client
Implements an API client for the nginx API (https://github.com/mutablelogic/go-server/pkg/handler/nginx)
Implements an API client for the nginx API (https://github.com/mutablelogic/go-server/pkg/handler/nginx)
handler/nginx/folders
Manages the lifecycle of configuration folders for nginx
Manages the lifecycle of configuration folders for nginx
httpserver
The `httpserver` task implements a server which can serve requests over HTTP, HTTPS and FCGI
The `httpserver` task implements a server which can serve requests over HTTP, HTTPS and FCGI
httpserver/fcgi
Package fcgi implements the FastCGI protocol.
Package fcgi implements the FastCGI protocol.

Jump to

Keyboard shortcuts

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