Documentation
¶
Overview ¶
Package platforms Examples
Appengine:
import ( "gitlab.com/TheDarkula/jsonrouter/http" "gitlab.com/TheDarkula/jsonrouter/platforms/appengine" ht "net/http" "gitlab.com/TheDarkula/jsonrouter/openapi/v2" "gitlab.com/TheDarkula/jsonrouter//validation" ) func TestServer() { spec := openapiv2.New("localhost", "TITLE") service, err = jsonrouter.New(spec) if (err != nil){ // Handle Error // } api := service.Add("/api") apiProduct := api.Add("/product") apiProduct.Param(validation.StringExact(30), "productID").GET( app.api_product_get, ).Description( "Gets the specified product", ).Response( Product{}, ) apiProduct.Add("/new").POST( app.api_product_new, ).Required( &validation.Payload{ "name": validation.String(), }.Description( "Creates new product", ).Response( Product{}, ) panic( ht.ListenAndServe( fmt.Sprintf( ":%d", PORT, ), service, ), ) } func (app *App) api_product_get(req http.Request) *http.Status { id := req.Param("productID").(string) product := getProduct(id) return req.Respond(product) } func (app *App) api_product_new(req http.Request) *http.Status { product := newProduct() name := req.BodyParam("name").(string) product.name = name return req.Respond(product) }
Fasthttp:
import ( "gitlab.com/TheDarkula/jsonrouter/http" "gitlab.com/TheDarkula/jsonrouter/logging/testing" "gitlab.com/TheDarkula/jsonrouter/platforms/fasthttp" "gitlab.com/TheDarkula/jsonrouter/openapi/v2" "gitlab.com/TheDarkula/jsonrouter//validation" ) func TestServer() { log := logs.NewClient().NewLogger() spec := openapiv2.New("localhost", "TITLE") _, service = jsonrouter.New(log, spec) api := service.Add("/api") apiProduct := api.Add("/product") apiProduct.Param(validation.StringExact(30), "productID").GET( app.api_product_get, ).Description( "Gets the specified product", ).Response( Product{}, ) apiProduct.Add("/new").POST( app.api_product_new, ).Required( &validation.Payload{ "name": validation.String(), }.Description( "Creates new product", ).Response( Product{}, ) panic( service.Serve(PORT), ) } func (app *App) api_product_get(req http.Request) *http.Status { id := req.Param("productID").(string) product := getProduct(id) return req.Respond(product) } func (app *App) api_product_new(req http.Request) *http.Status { product := newProduct() name := req.BodyParam("name").(string) product.name = name return req.Respond(product) }
Standard:
import ( "gitlab.com/TheDarkula/jsonrouter/http" "gitlab.com/TheDarkula/jsonrouter/logging/testing" "gitlab.com/TheDarkula/jsonrouter/platforms/standard" "gitlab.com/TheDarkula/jsonrouter/openapi/v2" "gitlab.com/TheDarkula/jsonrouter//validation" ht "net/http" ) type Product struct { name string } func TestServer() { log := logs.NewClient().NewLogger() spec := openapiv2.New("localhost", "TITLE") service, err = jsonrouter.New(log, spec) if (err != nil){ // Handle error } api := service.Add("/api") apiProduct := api.Add("/product") apiProduct.Param(validation.StringExact(30), "productID").GET( app.api_product_get, ).Description( "Gets the specified product", ).Response( Product{}, ) apiProduct.Add("/new").POST( app.api_product_new, ).Required( &validation.Payload{ "name": validation.String(), }.Description( "Creates new product", ).Response( Product{}, ) panic( ht.ListenAndServe( fmt.Sprintf( ":%d", PORT, ), service, ), ) } func (app *App) api_product_get(req http.Request) *http.Status { id := req.Param("productID").(string) product := getProduct(id) return req.Respond(product) } func (app *App) api_product_new(req http.Request) *http.Status { product := newProduct() name := req.BodyParam("name").(string) product.name = name return req.Respond(product) }
Index ¶
- Constants
- func AddMetricsEndpoints(root *tree.Node)
- func AddSpecEndpoints(root *tree.Node)
- func RunStandardTests(t *testing.T, req http.Request)
- func StandardTests_headers(t *testing.T, req http.Request)
- func StandardTests_parameters(t *testing.T, req http.Request)
- type Router
- type WildcardRouter
- func (router *WildcardRouter) HandleFunc(pattern *regexp.Regexp, handler func(http.ResponseWriter, *http.Request))
- func (router *WildcardRouter) Handler(pattern *regexp.Regexp, handler http.Handler)
- func (router *WildcardRouter) Serve(port int) error
- func (router *WildcardRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)
Constants ¶
View Source
const ( CONST_SPEC_PATH_V2 = "/openapi.spec.v2.json" CONST_SPEC_PATH_V3 = "/openapi.spec.v3.json" )
Variables ¶
This section is empty.
Functions ¶
func AddMetricsEndpoints ¶
func AddSpecEndpoints ¶
Types ¶
type WildcardRouter ¶
type WildcardRouter struct {
// contains filtered or unexported fields
}
func (*WildcardRouter) HandleFunc ¶
func (router *WildcardRouter) HandleFunc(pattern *regexp.Regexp, handler func(http.ResponseWriter, *http.Request))
func (*WildcardRouter) Handler ¶
func (router *WildcardRouter) Handler(pattern *regexp.Regexp, handler http.Handler)
func (*WildcardRouter) Serve ¶
func (router *WildcardRouter) Serve(port int) error
func (*WildcardRouter) ServeHTTP ¶
func (router *WildcardRouter) ServeHTTP(w http.ResponseWriter, r *http.Request)
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package jsonrouter implements the http-router for net/http projects
|
Package jsonrouter implements the http-router for net/http projects |
Click to show internal directories.
Click to hide internal directories.