httpserver

package module
Version: v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2020 License: MIT Imports: 13 Imported by: 0

README

httpserver

Another HTTP Server use handler with context & Response Render.

Quick Start

package main

import (
	"context"
	"log"
	"net/http"

	"github.com/x-mod/httpserver"
)

func main() {
	srv := httpserver.NewServer(
		httpserver.Address(":8080"),
	)
	srv.Route(
		httpserver.Pattern("/hello"),
		httpserver.Handler(http.HandlerFunc(Hello)),
	)
	log.Println("httpserver:", srv.Serve(context.TODO()))
}

func Hello(wr http.ResponseWriter, req *http.Request) {
	wr.WriteHeader(http.StatusOK)
	_, _ = wr.Write([]byte("I'm OK"))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MiddlewareFunc added in v1.0.7

type MiddlewareFunc func(http.Handler) http.Handler

type RouteCfg

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

type RouteOpt

type RouteOpt func(cf *RouteCfg)

func Handler

func Handler(h http.Handler) RouteOpt
func Header(headers ...string) RouteOpt

func Host

func Host(host string) RouteOpt

func Method

func Method(methods ...string) RouteOpt

func Pattern

func Pattern(pattern string) RouteOpt

func Prefix

func Prefix(prefix string) RouteOpt

func Query

func Query(queries ...string) RouteOpt

func Schema

func Schema(schemas ...string) RouteOpt

type Server

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

func New added in v1.0.3

func New(opts ...ServerOpt) *Server

func NewServer

func NewServer(opts ...ServerOpt) *Server

func (*Server) Close added in v1.0.4

func (srv *Server) Close() <-chan struct{}

func (*Server) Route

func (srv *Server) Route(opts ...RouteOpt)

func (*Server) Serve

func (srv *Server) Serve(ctx context.Context) error

func (*Server) ServeHTTP added in v1.0.5

func (srv *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP Implement http.Handler interface

func (*Server) Serving added in v1.0.9

func (srv *Server) Serving() <-chan struct{}

func (*Server) Shutdown added in v0.4.0

func (srv *Server) Shutdown(ctx context.Context) error

type ServerOpt

type ServerOpt func(*Server)

func Address added in v0.3.1

func Address(addr string) ServerOpt

func HTTPHandler added in v1.0.2

func HTTPHandler(handler http.Handler) ServerOpt

func Middleware added in v1.0.7

func Middleware(m MiddlewareFunc) ServerOpt

func Name added in v1.0.0

func Name(name string) ServerOpt

func NetTrace added in v1.0.0

func NetTrace(flag bool) ServerOpt

func TLSConfig added in v0.3.0

func TLSConfig(cf *tls.Config) ServerOpt

Source Files

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL