restful

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2019 License: Apache-2.0 Imports: 21 Imported by: 12

Documentation

Index

Constants

View Source
const (
	//Name is a variable of type string which indicates the protocol being used
	Name              = "rest"
	DefaultMetricPath = "metrics"
	MimeFile          = "application/octet-stream"
	MimeMult          = "multipart/form-data"
)

constants for metric path and name

View Source
const (
	Path  = "path"
	Query = "query"
)

const for doc

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Ctx context.Context
	// contains filtered or unexported fields
}

Context is a struct which has both request and response objects

func NewBaseServer

func NewBaseServer(ctx context.Context) *Context

NewBaseServer is a function which return context

func (*Context) AddHeader

func (bs *Context) AddHeader(header string, value string)

AddHeader is a function used to add header to a response

func (*Context) ReadBodyParameter

func (bs *Context) ReadBodyParameter(name string) (string, error)

ReadBodyParameter used to read body parameter of a request

func (*Context) ReadEntity

func (bs *Context) ReadEntity(schema interface{}) (err error)

ReadEntity is request reader

func (*Context) ReadHeader

func (bs *Context) ReadHeader(name string) string

ReadHeader is used to read header of request

func (*Context) ReadPathParameter

func (bs *Context) ReadPathParameter(name string) string

ReadPathParameter is used to read path parameter of a request

func (*Context) ReadPathParameters

func (bs *Context) ReadPathParameters() map[string]string

ReadPathParameters used to read multiple path parameters of a request

func (*Context) ReadQueryParameter

func (bs *Context) ReadQueryParameter(name string) string

ReadQueryParameter is used to read query parameter of a request

func (*Context) ReadRequest

func (bs *Context) ReadRequest() *http.Request

ReadRequest return a native net/http request

func (*Context) ReadResponseWriter

func (bs *Context) ReadResponseWriter() http.ResponseWriter

ReadResponseWriter return a native net/http ResponseWriter

func (*Context) ReadRestfulRequest added in v0.7.1

func (bs *Context) ReadRestfulRequest() *restful.Request

ReadRestfulRequest return a native go-restful request

func (*Context) ReadRestfulResponse added in v0.7.1

func (bs *Context) ReadRestfulResponse() *restful.Response

ReadRestfulResponse return a native go-restful Response

func (*Context) Write

func (bs *Context) Write(body []byte)

write is the response writer.

func (*Context) WriteError

func (bs *Context) WriteError(httpStatus int, err error) error

WriteError is a function used to write error into a response

func (*Context) WriteHeader

func (bs *Context) WriteHeader(httpStatus int)

WriteHeader is the response head writer

func (*Context) WriteHeaderAndJSON

func (bs *Context) WriteHeaderAndJSON(status int, value interface{}, contentType string) error

WriteHeaderAndJSON used to write head and JSON file in to response

func (*Context) WriteJSON

func (bs *Context) WriteJSON(value interface{}, contentType string) error

WriteJSON used to write a JSON file into response

type Parameters added in v1.2.2

type Parameters struct {
	Name      string //parameter name
	DataType  string // string, int etc
	ParamType int    //restful.QueryParameterKind or restful.PathParameterKind
	Desc      string
}

Parameters describe parameters in url path or query params

type Returns added in v1.2.2

type Returns struct {
	Code    int // http response code
	Message string
	Model   interface{} // response body structure
}

Returns describe response doc

type Route

type Route struct {
	Method           string        //Method is one of the following: GET,PUT,POST,DELETE. required
	Path             string        //Path contains a path pattern. required
	ResourceFuncName string        //the func this API calls. required
	FuncDesc         string        //tells what this route is all about. Optional.
	Parameters       []*Parameters //Parameters is a slice of request parameters for a single endpoint Optional.
	Returns          []*Returns    //what kind of response this API returns. Optional.
	Read             interface{}   //Read tells what resource type will be read from the request payload. Optional.
}

Route describe http route path and swagger specifications for API

func GetRouteSpecs added in v0.7.1

func GetRouteSpecs(schema interface{}) ([]Route, error)

GetRouteSpecs is to return a rest API specification of a go struct

Jump to

Keyboard shortcuts

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