server

package
v0.0.0-...-2248203 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

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 IsAdminGroup(username string) bool

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.

func (*MediaType) Format

func (m *MediaType) Format() string

Format function returns the full media type string - including MIME type and parameters.

func (*MediaType) Matches

func (m *MediaType) Matches(other *MediaType) bool

Matches verifies if this Mediatype matches the another MediaType.

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 NameMap

type NameMap map[string]string

NameMap is a simple mapping of names (string to string)

func (*NameMap) Get

func (m *NameMap) Get(name string) string

Get function returns the mapped name for a given name. Returns given name itself if no mapping exists.

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.

func (*Router) ServeHTTP

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

ServeHTTP resolves and invokes the handler for http request r. RESTCONF paths are served from the routeTree; rest from mux router.

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.

Jump to

Keyboard shortcuts

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