Documentation ¶
Overview ¶
Package server implements the HTTP server that will respond to the requests for URLs, sending the user to the appropriate location (or rejecting the response)
Index ¶
- Constants
- Variables
- func Error(next http.Handler) http.Handler
- func Intercept(matches MatcherFunc, intercept http.Handler) func(next http.Handler) http.Handler
- func IsGRPC(r *http.Request) bool
- func IsH2C(r *http.Request) bool
- func New(opts ...Option) (*http.Server, error)
- func WireServer() (*http.Server, error)
- func WithError(r *http.Request, err error)
- type MatcherFunc
- type Option
Constants ¶
const (
CtxErrors key = "error"
)
Ctx* are context value keys
Variables ¶
var ( ErrFailedToApplyOption = errors.New("failed to apply option") ErrFailedToStart = errors.New("failed to start server") )
Err* are sentinel errors
var ErrDependencyFailure = errors.New("dependency failure")
ErrDependencyFailure just means there was a failure resolving a dependency
var ( ProblemUnknown = problem.New( problem.Status(http.StatusInternalServerError), problem.Title("An unexpected error has occurred"), problem.Detail("The server has encountered an unexpected error. There's nothing, as a user, you can do. Please try again later")) )
Problem* are common types of problems
Functions ¶
func Intercept ¶
Intercept is a type of middleware that offloads messages that are destined for the "default" handler and instead redirects them to some other handler.
This allows using more complex matching logic. See IsGRPCGateway for an example.
func IsGRPC ¶
IsGRPC offloads requests to the gRPC mux. Note: This does not use a bunch of GRPC features; that's fine.
See - https://github.com/philips/grpc-gateway-example/blob/master/cmd/serve.go#L51-L61 - https://ahmet.im/blog/grpc-http-mux-go/
func IsH2C ¶
IsH2C does the detection of the initial message. The message looks like:
PRI * HTTP/2.0 SM <Byte Data>
(At least, as reproduced by $ curl --http2-prior-knowledge). See: 1. https://www.rfc-editor.org/rfc/rfc7540#section-4.1
func WireServer ¶
func WithError ¶
WithError adds the error to the current request. Middleware later picks it out, and writes out the status.
https://cs.opensource.google/go/go/+/refs/tags/go1.21.6:src/net/http/server.go;l=2141-2150 https://github.com/go-chi/render/blob/14f1cb3d5c2969d6e462632a205eacb6421eb4dc/responder.go#L25-L26
Types ¶
type MatcherFunc ¶
MatcherFunc is a function that can be used by the interceptor to match requests.
func AllOf ¶
func AllOf(matchers ...MatcherFunc) MatcherFunc
AllOf combines multiple matchers into a single matcher func
func IsHost ¶
func IsHost(host string) MatcherFunc
IsHost matches whether or not a request matches a specific host
type Option ¶
Option is a function type that modifies the behavior of the server
func ResolveOptions ¶
ResolveOptions generates a server with the appropriate configuration, based on Viper and other required dependencies
func WithH2C ¶
func WithH2C() Option
WithH2C allows piping the connection to a HTTP/2 server, which will hijack the request to use the HTTP/2 protocol but over the initially supplied connection.
func WithListenAddress ¶
WithListenAddress indicates the server should start on the specific address
func WithMiddleware ¶
WithMiddleware appends middleware to the default handler
func WithStorage ¶
WithStorage allows starting the service with a specific storage engine.