basket

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2020 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GitCommit string = "436ae9a0d9237f682cc64bde60630c68adf2ab5d"
	GitBranch string = "master"
	GitTag    string = "v1.0.0"
	BuildTime string = "Tue Apr 14 10:02:02 CEST 2020"
)
View Source
const (
	ContentTypeTextPlain string = "text/plain"
)
View Source
const (
	RequestHeaderKey contextKey = 1 + iota
)

Variables

View Source
var (
	NullError = errors.New("unexpected null value")
	TypeError = errors.New("unexpected type")
)
View Source
var EmptyString = errors.New("string is empty")

Functions

func CreateHttpContext

func CreateHttpContext(header http.Header) context.Context

func JSON

func JSON(r io.Reader, v interface{}, required bool) (err error)

func NewHTTPStatusCodeError

func NewHTTPStatusCodeError(status int) xHTTPError

Types

type BasketServiceClient

type BasketServiceClient interface {
	PostItem(request *PostItemRequest) (PostItemResponse, error)
	GetItems(request *GetItemsRequest) (GetItemsResponse, error)
}

func NewBasketServiceClient

func NewBasketServiceClient(httpClient *http.Client, baseUrl string, options Opts) BasketServiceClient

type BasketServiceServer

type BasketServiceServer struct {
	*Server
	Validator *Validator
	// contains filtered or unexported fields
}

func NewBasketServiceServer

func NewBasketServiceServer(options *ServerOpts) *BasketServiceServer

func (*BasketServiceServer) GetItemsHandler

func (server *BasketServiceServer) GetItemsHandler(c *routing.Context) error

func (*BasketServiceServer) PostItemHandler

func (server *BasketServiceServer) PostItemHandler(c *routing.Context) error

func (*BasketServiceServer) SetGetItemsHandler

func (server *BasketServiceServer) SetGetItemsHandler(handler GetItemsHandler, middleware ...Middleware)

func (*BasketServiceServer) SetPostItemHandler

func (server *BasketServiceServer) SetPostItemHandler(handler PostItemHandler, middleware ...Middleware)

func (*BasketServiceServer) Start

func (server *BasketServiceServer) Start(port int) error

type ErrorHandler

type ErrorHandler func(v ...interface{})

type GetItems200Response

type GetItems200Response struct {
	Body Items
}

Items posted

func (*GetItems200Response) StatusCode

func (r *GetItems200Response) StatusCode() int

type GetItemsHandler

type GetItemsHandler func(ctx context.Context, request *GetItemsRequest) GetItemsResponse

type GetItemsRequest

type GetItemsRequest struct{}

type GetItemsResponse

type GetItemsResponse interface {
	StatusCode() int
	// contains filtered or unexported methods
}

type HooksClient

type HooksClient struct {
	OnUnknownResponseCode func(response *http.Response, request *http.Request) string
}

func DevHook

func DevHook() HooksClient

type HttpContext

type HttpContext interface {
	GetHTTPRequestHeaders() (http.Header, bool)
}

type HttpJsonError

type HttpJsonError struct {
	Message interface{}
	// contains filtered or unexported fields
}

func (*HttpJsonError) Error

func (e *HttpJsonError) Error() string

func (*HttpJsonError) StatusCode

func (e *HttpJsonError) StatusCode() int

type Item

type Item struct {
	Id    int64   `bson:"id,required" json:"id,required" xml:"id,required"`
	Name  string  `bson:"name,required" json:"name,required" xml:"name,required"`
	Price float64 `bson:"price,required" json:"price,required" xml:"price,required"`
}

type Items

type Items []Item

type Middleware

type Middleware struct {
	Handler routing.Handler
	After   bool
}

type MimeFile

type MimeFile struct {
	Header  *multipart.FileHeader
	Content io.ReadCloser
}

type NewRequest

type NewRequest func(string, io.Reader) (*http.Request, error)

type Opts

type Opts struct {
	Hooks HooksClient
	Ctx   context.Context
}

type PostItem200Response

type PostItem200Response struct{}

OK

func (*PostItem200Response) StatusCode

func (r *PostItem200Response) StatusCode() int

type PostItem500Response

type PostItem500Response struct{}

Internal server error (e.g. unexpected condition occurred)

func (*PostItem500Response) StatusCode

func (r *PostItem500Response) StatusCode() int

type PostItemHandler

type PostItemHandler func(ctx context.Context, request *PostItemRequest) PostItemResponse

type PostItemRequest

type PostItemRequest struct {
	Item *Item
}

type PostItemResponse

type PostItemResponse interface {
	StatusCode() int
	// contains filtered or unexported methods
}

type PrometheusHandler

type PrometheusHandler struct {
	// contains filtered or unexported fields
}

func NewPrometheusHandler

func NewPrometheusHandler(namespace *string) *PrometheusHandler

func (*PrometheusHandler) HandleRequest

func (h *PrometheusHandler) HandleRequest(path, method string, status int, duration time.Duration)

func (*PrometheusHandler) InitMetric

func (h *PrometheusHandler) InitMetric(path, method string)

type RouteDescription

type RouteDescription struct {
	Path       string
	Handler    routing.Handler
	Middleware []Middleware
	Method     string
}

type Server

type Server struct {
	ErrorLogger func(v ...interface{})

	SwaggerSpec string
	Router      *routing.Router
	OnStart     func(router *routing.Router)
	// contains filtered or unexported fields
}

func (*Server) Start

func (server *Server) Start(port int, routes []RouteDescription) error

func (*Server) Stop

func (server *Server) Stop() error

type ServerOpts

type ServerOpts struct {
	ErrorHandler ErrorHandler
	Middleware   []Middleware
	OnStart      func(router *routing.Router)
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService() *Service

func (*Service) GetItems

func (s *Service) GetItems(ctx context.Context, request *GetItemsRequest) GetItemsResponse

func (*Service) PostItem

func (s *Service) PostItem(ctx context.Context, request *PostItemRequest) PostItemResponse

func (*Service) Start

func (s *Service) Start(port int) error

Start starts the server to listen at port

func (*Service) Stop

func (s *Service) Stop() error

Stop stops the server to listen at port

type ValidationErrorObject

type ValidationErrorObject struct {
	Message string `json:"message"`
	Field   string `json:"field"`
	Code    string `json:"code"`
}

type ValidationErrorsObject

type ValidationErrorsObject struct {
	Message string                  `json:"message"`
	Errors  []ValidationErrorObject `json:"errors"`
}

type Validator

type Validator struct {
	*validator.Validate
}

func NewValidation

func NewValidation() *Validator

func (*Validator) ValidateRequest

func (v *Validator) ValidateRequest(request interface{}) (*ValidationErrorsObject, error)

type VersionInfo

type VersionInfo struct {
	GoVersion string `json:"go_version"`
	GitTag    string `json:"git_tag"`
	GitCommit string `json:"git_commit"`
	GitBranch string `json:"git_branch"`
	BuildTime string `json:"build_time"`
}

func ApikitVersion

func ApikitVersion() *VersionInfo

func (*VersionInfo) PrintTable

func (vi *VersionInfo) PrintTable() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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