argo-web-api: github.com/ARGOeu/argo-web-api/respond Index | Files

package respond

import "github.com/ARGOeu/argo-web-api/respond"

Index

Package Files

respond.go validators.go wrappers.go

Variables

var BadRequestBadJSON = ResponseMessage{
    Status: StatusResponse{
        Message: "Bad Request",
        Code:    "400",
        Details: "Request Body contains malformed JSON, thus rendering the Request Bad",
    }}

BadRequestBadJson is used to inform the user about malformed json body

var BadRequestInvalidJSON = ResponseMessage{
    Status: StatusResponse{
        Message: "Bad Request",
        Code:    "400",
    },
    Errors: []StatusResponse{
        {Message: "Bad Request", Code: "400", Details: "Request Body contains malformed JSON, thus rendering the Request Bad"},
    },
}
var BadRequestSimple = ResponseMessage{
    Status: StatusResponse{
        Message: "Bad Request",
        Code:    "400",
    }}

BadRequest is used to inform the user about malformed json body

var ErrConflict = func(details string) ResponseMessage {
    return ResponseMessage{
        Status: StatusResponse{
            Message: "Conflict",
            Code:    "409",
        },
        Errors: []StatusResponse{
            {Message: "Conflict", Code: "409", Details: details},
        },
    }
}
var ErrNotAcceptableContentType = func() ResponseMessage {
    return ResponseMessage{
        Status: StatusResponse{
            Message: "Not Acceptable Content Type",
            Code:    "406",
        },
        Errors: []StatusResponse{
            {Message: "Conflict", Code: "406", Details: "" /* 135 byte string literal not displayed */},
        },
    }
}
var ErrNotFound = ResponseMessage{
    Status: StatusResponse{
        Message: "Not Found",
        Code:    "404",
    },
    Errors: []StatusResponse{
        {Message: "Not Found", Code: "404", Details: "item with the specific ID was not found on the server"},
    },
}

NotFound is used to inform the user about not found item

var ErrUnprocessableEntity = func(details string) ResponseMessage {
    return ResponseMessage{
        Status: StatusResponse{
            Message: "Unprocessable Entity",
            Code:    "422",
        },
        Errors: []StatusResponse{
            {Message: "Unprocessable Entity", Code: "422", Details: details},
        },
    }
}
var Forbidden = ResponseMessage{
    Status: StatusResponse{
        Code:    "403",
        Message: "Access to the resource is Forbidden",
    },
}

Forbidden is used to marshal a response

var InternalServerErrorMessage = ResponseMessage{
    Status: StatusResponse{
        Code:    "500",
        Message: "Internal Server Error",
    },
}

InternalServerErrorMessage is used to marshal a response

var MalformedJSONInput = ResponseMessage{
    Status: StatusResponse{
        Code:    "400",
        Message: "Malformated json input data",
        Details: "Check that your json input is valid",
    },
}

MalformedJSONInput is used to marshal a response when user json input is malformed

var NotAcceptableContentType = ResponseMessage{
    Status: StatusResponse{
        Message: "Not Acceptable Content Type",
        Code:    "406",
        Details: "" /* 135 byte string literal not displayed */,
    }}

NotAcceptableContentType is used to inform the user about incorrect Accept header and can be marshaled to xml and json

var NotFound = ResponseMessage{
    Status: StatusResponse{
        Message: "Not Found",
        Code:    "404",
        Details: "item with the specific ID was not found on the server",
    },
}

NotFound is used to inform the user about not found item

var UnauthorizedMessage = ResponseMessage{
    Status: StatusResponse{
        Message: "Unauthorized",
        Code:    "401",
        Details: "You need to provide a correct authentication token using the header 'x-api-key'",
    }}

UnauthorizedMessage is used to inform the user about incorrect api key and can be marshaled to xml and json

var UnprocessableEntity = ResponseMessage{
    Status: StatusResponse{
        Code:    "422",
        Message: "Unprocessable Entity",
    },
}

UnprocessableEntity is used to marshal a response

func CreateResponseMessage Uses

func CreateResponseMessage(message string, code string, contentType string) ([]byte, error)

CreateResponseMessage creates an output using the parameters given and the correct marshaller according to the contetnType

func Error Uses

func Error(w http.ResponseWriter, r *http.Request, errType ErrEnum, cfg config.Config, errs []ErrorResponse)

Error responds immediately when errors arise in handler chain

func MarshalContent Uses

func MarshalContent(doc interface{}, contentType string, prefix string, indent string) ([]byte, error)

MarshalContent marshals content using the marshaler that corresponds to the contentType parameter

func ParseAcceptHeader Uses

func ParseAcceptHeader(r *http.Request) (string, error)

ParseAcceptHeader parses the accept header to determine the content type

func PrepAppRoutes Uses

func PrepAppRoutes(s *mux.Router, confHandler *ConfHandler, routes []AppRoutes) *mux.Router

PrepAppRoutes is used in apps to prepare app's routes

func ResetCache Uses

func ResetCache(w http.ResponseWriter, r *http.Request, cfg config.Config) []byte

ResetCache resets the cache if it is set

func WrapAuthenticate Uses

func WrapAuthenticate(hfn http.Handler, cfg config.Config, routeName string) http.HandlerFunc

WrapAuthenticate handle wrapper to apply authentication

func WrapAuthorize Uses

func WrapAuthorize(hfn http.Handler, cfg config.Config, routeName string) http.HandlerFunc

WrapAuthorize handle wrapper to apply authorization

func WrapValidate Uses

func WrapValidate(hfn http.Handler, cfg config.Config, routeName string) http.HandlerFunc

WrapValidate handle wrapper to apply validation

type AppRoutes Uses

type AppRoutes struct {
    Name             string
    Verb             string
    Path             string
    SubrouterHandler func(r *http.Request, cfg config.Config) (int, http.Header, []byte, error)
}

AppRoutes holds

type ConfHandler Uses

type ConfHandler struct {
    Config config.Config
}

ConfHandler Keeps all the configuration/variables required by all the requests

func (*ConfHandler) Respond Uses

func (confhandler *ConfHandler) Respond(fn func(r *http.Request, cfg config.Config) (int, http.Header, []byte, error)) http.HandlerFunc

Respond will be called to answer to http requests to the PI

type ErrEnum Uses

type ErrEnum int

ErrEnum used as type for enumerations of errors

const (
    //ErrAuthen is Error during authentication
    ErrAuthen ErrEnum = iota
    //ErrAuthor is Error during authorization
    ErrAuthor ErrEnum = iota
    //ErrValidHead is Error during validation
    ErrValidHead ErrEnum = iota
    //ErrValidQuery is Error during validation
    ErrValidQuery ErrEnum = iota
)

type ErrorResponse Uses

type ErrorResponse struct {
    Message string `xml:"message,omitempty" json:"message,omitempty"`
    Code    string `xml:"code,omitempty" json:"code,omitempty"`
    Details string `xml:"details,omitempty" json:"details,omitempty"`
}

ErrorResponse holds a list of error objects

func ValidateAcceptHeader Uses

func ValidateAcceptHeader(accept string) ErrorResponse

ValidateAcceptHeader parses the accept header to determine the content type

func ValidateMetricParams Uses

func ValidateMetricParams(queries url.Values) []ErrorResponse

func ValidateResultsParams Uses

func ValidateResultsParams(queries url.Values) []ErrorResponse

func ValidateStatusParams Uses

func ValidateStatusParams(queries url.Values) []ErrorResponse

type ResponseMessage Uses

type ResponseMessage struct {
    XMLName xml.Name       `xml:"root" json:"-"`
    Status  StatusResponse `xml:"status,omitempty" json:"status,omitempty"`
    Data    interface{}    `xml:"data>result,omitempty" json:"data,omitempty"`
    Errors  interface{}    `xml:"errors>error,omitempty" json:"errors,omitempty"`
}

ResponseMessage is used to construct and marshal correctly response messages

func CreateFailureResponseMessage Uses

func CreateFailureResponseMessage(message string, code string, errs []ErrorResponse) ResponseMessage

CreateFailureResponseMessage creates a response message struct intance to represent all the errors that occured during the request

func (ResponseMessage) MarshalTo Uses

func (resp ResponseMessage) MarshalTo(contentType string) []byte

MarshalTo takes a reponse message and uses the requested marshaller to render it into the desired content type

type SelfLinks struct {
    Self string `xml:"self" json:"self"`
}

SelfLinks struct to acoomodate link inside the SelfReference

type SelfReference Uses

type SelfReference struct {
    ID    string    `xml:"id" json:"id" bson:"id,omitempty"`
    Links SelfLinks `xml:"links" json:"links"`
}

SelfReference struct for self referencing resource after they are created

type StatusResponse Uses

type StatusResponse struct {
    Message string `xml:"message,omitempty" json:"message,omitempty"`
    Code    string `xml:"code,omitempty" json:"code,omitempty"`
    Details string `xml:"details,omitempty" json:"details,omitempty"`
}

StatusResponse accompanies the ResponseMessage struct to construct a response

Package respond imports 17 packages (graph) and is imported by 31 packages. Updated 2019-11-14. Refresh now. Tools for package owners.