Documentation ¶
Index ¶
- func AddRoute(name, method, pattern string, handler http.HandlerFunc)
- func IsAdminGroup(username string) bool
- func PAMAuthenAndAuthor(r *http.Request, rc *RequestContext) error
- func Process(w http.ResponseWriter, r *http.Request)
- func RequestValidate(payload []byte, ctype *MediaType, rc *RequestContext) ([]byte, error)
- type MediaType
- type MediaTypes
- type NameMap
- type RequestContext
- type Router
- type RouterConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddRoute ¶
func AddRoute(name, method, pattern string, handler http.HandlerFunc)
AddRoute appends specified routes to the routes collection. Called by init functions of swagger generated router.go files.
func IsAdminGroup ¶
func PAMAuthenAndAuthor ¶
func PAMAuthenAndAuthor(r *http.Request, rc *RequestContext) error
func Process ¶
func Process(w http.ResponseWriter, r *http.Request)
Process function is the common landing place for all REST requests. Swagger code-gen should be configured to invoke this function from all generated stub functions.
func RequestValidate ¶
func RequestValidate(payload []byte, ctype *MediaType, rc *RequestContext) ([]byte, error)
RequestValidate performas payload validation of request body.
Types ¶
type MediaType ¶
type MediaType struct { Type string Params map[string]string TypePrefix string TypeSuffix string TypeMiddle string }
MediaType represents the parsed media type value. Includes a MIME type string and optional parameters.
type MediaTypes ¶
type MediaTypes []MediaType
MediaTypes is a collection of parsed media type values
func (*MediaTypes) Add ¶
func (m *MediaTypes) Add(mimeType string) error
Add function parses and adds a media type to the MediaTypes object. Any parameters in the media type value are ignored.
func (*MediaTypes) Contains ¶
func (m *MediaTypes) Contains(mimeType string) bool
Contains function checks if a given media type value is present in the ContentTypes. Ignores the media type parameters.
func (*MediaTypes) GetMatching ¶
func (m *MediaTypes) GetMatching(mimeType string) MediaTypes
GetMatching returns registered full content type value matching a given hint.
func (MediaTypes) String ¶
func (m MediaTypes) String() string
type RequestContext ¶
type RequestContext struct { // Unique reqiest id ID string // Name represents the operationId from OpenAPI spec Name string // "consumes" and "produces" data from OpenAPI spec Consumes MediaTypes Produces MediaTypes // Model holds pointer to the OpenAPI data model object for // the body. When set, the request handler can validate the // request payload by loading the body into this model object. Model interface{} // PMap is the mapping of URI parameter names to actual yang // leaf names. Yang xpaths can have duplicate parameter names, // which is not supported by swagger and mux libraries. We // work around it by assigning different parameter names in // swagger and map them back to yang names while converting // REST paths to TransLib paths. PMap NameMap }
RequestContext holds metadata about REST request.
func GetContext ¶
func GetContext(r *http.Request) (*RequestContext, *http.Request)
GetContext function returns the RequestContext object for a HTTP request. RequestContext is maintained as a context value of the request. Creates a new RequestContext object is not already available; in which case this function also creates a copy of the HTTP request object with new context.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router dispatches http request to corresponding handlers.
func NewRouter ¶
func NewRouter(config RouterConfig) *Router
NewRouter creates a new http router instance for the REST server. Includes all routes registered via AddRoute API as well as few internal service API routes. Router instance specific configurations are accepted through a RouterConfig object.
type RouterConfig ¶
type RouterConfig struct { // AuthEnable indicates if client authentication is enabled AuthEnable bool // ServerAddr is the address to contact main server. Will be used to // advertise the server's address (like yang download path).. Optional ServerAddr string }
RouterConfig holds runtime configurations for a Router instance.