docrouter

package module
v0.0.0-...-9a84141 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2021 License: MIT Imports: 9 Imported by: 0

README

docrouter

Golang router for a web server with builtin OpenAPI documentation

Router vs Server

docrouter is a router not a server has following implications:

  • no ListenAndServe method - serving exposed http.Handler is not this package responsibility
  • should I remove middleware functionality completely? Or add router-level middleware?

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	Title:   "Default Title",
	Version: "1.0",
	Servers: []ServerDoc{
		{"https://www.example.com/v3", "Production environment API"},
		{"https://test.example.com/v3", "Test environment API"},
	},
}

Functions

func DecodeParams

func DecodeParams(structPtr interface{}, req *http.Request) error

Types

type Options

type Options struct {
	Title   string
	Version string

	// ServerURLs are used purely for generating OpenAPI schema.
	// It doesn't have any effect on a request host matching.
	Servers []ServerDoc
}

type Route

type Route struct {
	Path         string
	Methods      []string
	RequestBody  interface{}
	ResponseBody interface{}
	Parameters   interface{}
	// Middlewares are route level middlewares executed for this particular route only
	Middlewares []func(http.Handler) http.Handler
	Handler     http.Handler

	// Short summary
	Summary string
	// Optional description. Should use CommonMark syntax
	Description string
}

Route collects all the information for handler and documentation generator.

The router matches the handler based on defined Path and Methods only.

type Router

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

func New

func New(opts Options) *Router

func (*Router) AddRoute

func (srv *Router) AddRoute(route Route) error

func (*Router) ServeHTTP

func (srv *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ServerDoc

type ServerDoc struct {
	URL         string
	Description string
}

Jump to

Keyboard shortcuts

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