contracts

package
v0.0.0-...-8f9ebe2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING Autogenerated by rest_tool -t BasicAuthCredentials -m validator

DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING Autogenerated by rest_tool -t BearerAuthCredentials -m validator

DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING Autogenerated by goscinny extractor -t CreateDataPointRequest DO NOT EDIT

DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING Autogenerated by rest_tool -t CreateDataPointRequest -m validator

DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING Autogenerated by goscinny extractor -t CreateMetricsRequest DO NOT EDIT

DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING Autogenerated by rest_tool -t CreateMetricsRequest -m validator

DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING Autogenerated by rest_tool -t Request -m validator

DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING Autogenerated by rest_tool -t SingleResponse -m validator

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound                    = errorFunc(http.StatusNotFound, 1000, "")
	ErrBadRequestParametersMissing = errorFunc(http.StatusBadRequest, 1001, "Mandatory Parameter missing")
	ErrBadRequestInvalidParameter  = errorFunc(http.StatusBadRequest, 1002, "Invalid parameter")
	ErrBadRequestInvalidBody       = errorFunc(http.StatusBadRequest, 1007, "Invalid request body,failed parsing ")
	ErrForbidden                   = errorFunc(http.StatusForbidden, 1003, "Authentication failed")
	ErrInternalServerError         = errorFunc(http.StatusInternalServerError, 1004, "")
	ErrTooManyRequests             = errorFunc(http.StatusTooManyRequests, 1006, "")
	ErrMethodNotDefined            = errorFunc(http.StatusMethodNotAllowed, 1005, "Method not implemented")
	ErrResourceConflict            = errorFunc(http.StatusConflict, 1008, "Duplicate resource")
	ErrUnAuthorized                = errorFunc(http.StatusUnauthorized, 1010, "Authentication failed")
	ErrMetricNotFound              = errorFunc(http.StatusNotFound, 1011, "Metric name not found. Please create first before you send datapoints")
)

All the error constants would be here

Functions

func ContentDecoder

func ContentDecoder(contentType string) func(r io.Reader) Decoder

ContentDecoder returns decoder given content type if the content type given does not align to the expectations it will return json decoder

func ParseToBool

func ParseToBool(data string) (bool, error)

ParseToBool parses a given string and returns bool value of the string

func ParseToFloat

func ParseToFloat(data string) (float64, error)

ParseToFloat parses a given string and returns float64 value of the string

func ParseToInt

func ParseToInt(data string) (int64, error)

ParseToInt parses a given string and returns int64 value of the string

func ParseToUint

func ParseToUint(data string) (uint64, error)

ParseToUint parses a given string and returns uint64 value of the string

Types

type BaseResponse

type BaseResponse struct {
	RequestID string    `json:"request_id"`
	Method    string    `json:"method"`
	HTTPCode  int       `json:"http_code"`
	Metadata  *Metadata `json:"metadata,omitempty"`
}

BaseResponse defines the common structure of standard response This contains all but one field of final response All the request response will embed this structure and should have "response" key

func (*BaseResponse) SetHTTPCode

func (res *BaseResponse) SetHTTPCode(code int) Response

SetHTTPCode stets the http code

func (*BaseResponse) SetMetadata

func (res *BaseResponse) SetMetadata(metadata *Metadata) Response

SetMetadata setter for Metadata in Response class

func (*BaseResponse) SetMethod

func (res *BaseResponse) SetMethod(method string) Response

SetMethod sets http method

func (*BaseResponse) SetRequestID

func (res *BaseResponse) SetRequestID(requestID string) Response

SetRequestID sets requst id for response

type BasicAuthCredentials

type BasicAuthCredentials struct {
	UserName *string `required:"true"`
	Password *string `required:"true"`
}

BasicAuthCredentials defines credentials required for basic auth

func (*BasicAuthCredentials) ExtractFromHTTP

func (ba *BasicAuthCredentials) ExtractFromHTTP(c echo.Context) *Error

ExtractFromHTTP defines how to extract the data form request

func (*BasicAuthCredentials) Validate

func (_receiver_ *BasicAuthCredentials) Validate() *Error

Validate checks if a contract is valid or not and return with appropriate message

type BearerAuthCredentials

type BearerAuthCredentials struct {
	Token      *string `required:"true"`
	AccountSid *string
}

BearerAuthCredentials defines credentials required for basic auth

func (*BearerAuthCredentials) ExtractFromHTTP

func (ba *BearerAuthCredentials) ExtractFromHTTP(c echo.Context) *Error

ExtractFromHTTP defines how to extract the data form request

func (*BearerAuthCredentials) Validate

func (_receiver_ *BearerAuthCredentials) Validate() *Error

Validate checks if a contract is valid or not and return with appropriate message

type CreateDataPointRequest

type CreateDataPointRequest struct {
	*Request `json:"-"`
	Name     *string    `json:"-" path:"metricName" required:"true"`
	Time     *time.Time `json:"time" required:"true"`
	Value    *float64   `json:"value" required:"true"`
}

CreateDataPointRequest defines the structure to store request data Throttle : Basic,1000,1*M Route : /metrics/:metricName/datapoint

func (*CreateDataPointRequest) ExtractFromHTTP

func (_receiver *CreateDataPointRequest) ExtractFromHTTP(c echo.Context) *Error

ExtractFromHTTP reads http request body and fills the object

func (*CreateDataPointRequest) Validate

func (_receiver_ *CreateDataPointRequest) Validate() *Error

Validate checks if a contract is valid or not and return with appropriate message

type CreateDataPointResponse

type CreateDataPointResponse struct {
	BaseResponse
	ResponseData []*SingleDataPointResponse `json:"response"`
}

CreateDataPointResponse defines the structure to store response data for Create DP

type CreateMetricsRequest

type CreateMetricsRequest struct {
	*Request `json:"-"`
	*model.Anomaly
}

CreateMetricsRequest defines the structure to store request data Throttle : Basic,1000,1*M Route : /metrics/:metricName

func (*CreateMetricsRequest) ExtractFromHTTP

func (_receiver *CreateMetricsRequest) ExtractFromHTTP(c echo.Context) *Error

ExtractFromHTTP reads http request body and fills the object

func (*CreateMetricsRequest) Validate

func (_receiver_ *CreateMetricsRequest) Validate() *Error

Validate checks if a contract is valid or not and return with appropriate message

type CreateMetricsResponse

type CreateMetricsResponse struct {
	BaseResponse
	ResponseData []*SingleMetricsResponse `json:"response"`
}

CreateMetricsResponse defines the structure to store response data for CreateItem

type Decoder

type Decoder interface {
	Decode(interface{}) error
}

Decoder defines interface for a function

type Error

type Error struct {
	HTTPCode        int           `json:"-"`
	Code            uint64        `json:"code"`
	Description     string        `json:"description"`
	InternalMessage []interface{} `json:"-"`
	Message         string        `json:"message"`
}

Error defines the error contract

func (*Error) AddMsg

func (err *Error) AddMsg(msg ...interface{}) error

AddMsg adds internal message to an error

func (Error) Error

func (err Error) Error() string

Error returns string form of the error

func (Error) GetCode

func (err Error) GetCode() uint64

GetCode returns numeric code corresponding to the error

type Extractor

type Extractor interface {
	ExtractFromHTTP(echo.Context) *Error
}

Extractor defines the interface to be implemented by all contracts it defines how to read values from a http request to its fields

type Metadata

type Metadata struct {
	Failed   *uint64     `json:"failed,omitempty"`
	PageSize *uint64     `json:"page_size,omitempty"`
	Page     *uint64     `json:"page,omitempty"`
	Total    *uint64     `json:"total,omitempty"`
	Success  *uint64     `json:"success,omitempty"`
	Custom   interface{} `json:"custom,omitempty"`
}

Metadata defines the structure for metadata

type Request

type Request struct {
	Method    *string `json:"-" required:"true"`
	RequestID *string `json:"-" required:"true"`
}

Request defines the base request

func (*Request) Validate

func (_receiver_ *Request) Validate() *Error

Validate checks if a contract is valid or not and return with appropriate message

type Response

type Response interface {
	SetHTTPCode(int) Response
	SetMethod(string) Response
	SetRequestID(string) Response
	SetMetadata(*Metadata) Response
}

Response defines interface for a valid response

type SingleDataPointResponse

type SingleDataPointResponse struct {
	SingleResponse
	Name      string    `json:"name"`
	Time      time.Time `json:"time"`
	Value     float64   `json:"value"`
	IsAnomaly bool      `json:"is_anomaly"`
	Score     float64   `json:"score"`
}

type SingleMetricsResponse

type SingleMetricsResponse struct {
	SingleResponse
	ResourceData *model.Anomaly `json:"data" required:"true"`
}

SingleMetricsResponse defines the structure of response for single item this is to include in the response item

type SingleResponse

type SingleResponse struct {
	Code      *int    `json:"code"`
	ErrorData *Error  `json:"error_data"`
	Msg       *string `json:"msg,omitempty"`
	Status    *string `json:"status" enum:"failure|success"`
}

SingleResponse struct defines response for one resource in the request

func (*SingleResponse) SetErrorData

func (res *SingleResponse) SetErrorData(err *Error) *SingleResponse

SetErrorData setter for ErrorData in Response class

func (*SingleResponse) Validate

func (_receiver_ *SingleResponse) Validate() *Error

Validate checks if a contract is valid or not and return with appropriate message

type Validator

type Validator interface {
	Validate() *Error
}

Validator

Jump to

Keyboard shortcuts

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