server

package module
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2025 License: Apache-2.0 Imports: 19 Imported by: 6

README

Obvious Service Framework

Contributor Covenant License GitHub release

A simple library for quickly developing web services. Supports HTTP, HTTPS, AWS Gateway Lambda, and AWS Lambda.

The goal is simple, enable a development of Service APIs - not the scaffolding.

How to Use

go get github.com/go-obvious/server
Example Usage

Check out the github.com/go-obvious/server-example for an example...

Documentation

Index

Constants

View Source
const (
	AwsGatewayLambda   = "aws-gateway-v1"
	AwsGatewayV2Lambda = "aws-gateway-v2"
	Https              = "https"
	Http               = "http"
)

Variables

This section is empty.

Functions

func AddFilter added in v0.1.15

func AddFilter(filter ConnectionLogFilter)

AddFilter allows adding a new logFilter to the filters slice. This can be used to dynamically add filters for log messages to ignore.

Types

type API

type API interface {
	Name() string
	Register(app Server) error
}

type ConnectionLogFilter added in v0.1.15

type ConnectionLogFilter func(string) bool

ConnectionLogFilter defines a function type that takes a string as input and returns a boolean. It is used to filter connection logs based on specific criteria, where the input string typically represents a log entry or a related identifier.

type ListenAndServeFunc added in v0.1.9

type ListenAndServeFunc func(addr string, router http.Handler) error

func AWSGatewayLambdaListener added in v0.1.9

func AWSGatewayLambdaListener() ListenAndServeFunc

func AWSGatewayV2LambdaListener added in v0.1.9

func AWSGatewayV2LambdaListener() ListenAndServeFunc

func HTTPListener added in v0.1.9

func HTTPListener() ListenAndServeFunc

func TLSListener added in v0.1.9

func TLSListener(readTimeout, writeTimeout, idleTimeout time.Duration, tlsProvider func() *tls.Config) ListenAndServeFunc

type Middleware added in v0.1.7

type Middleware func(next http.Handler) http.Handler

Middleware abstraction

type Server

type Server interface {
	// Router returns the underlying router instance used by the server.
	Router() interface{}

	// WithAddress sets the server's address and returns the updated Server instance.
	WithAddress(addr string) Server

	// WithListener sets a custom listener function for the server and returns the updated Server instance.
	WithListener(l ListenAndServeFunc) Server

	// WithMiddleware adds middleware to the server and returns the updated Server instance.
	// NOTE: Middlware must be added before APIs
	WithMiddleware(m ...Middleware) Server

	// WithAPIs registers APIs with the server and returns the updated Server instance.
	WithAPIs(apis ...API) Server

	// Run starts the server and blocks until the context is canceled.
	Run(ctx context.Context)
}

Server represents a configurable HTTP server interface. It provides methods to set up the server's address, listener, middleware, APIs, and to run the server.

func New

func New(
	ver *ServerVersion,
) Server

type ServerVersion

type ServerVersion = version.ServerVersion

Expose the Version struct

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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