management

package
v0.0.0-...-360c817 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2018 License: Apache-2.0 Imports: 21 Imported by: 56

Documentation

Index

Constants

View Source
const (
	ERR_NOT_IMPLEMENTED         string = "not_implemented"
	ERR_BAD_REQUEST                    = "bad_request"
	ERR_SERVICE_ERROR                  = "service_error"
	ERR_BAD_GATEWAY                    = "external_error"
	ERR_NOT_FOUND                      = "not_found"
	ERR_FORBIDDEN                      = "forbidden_error"
	ERR_SERVICE_UNAVAILABLE            = "service_unavailable"
	ERR_RESOURCE_ALREADY_EXISTS        = "resource_already_exists"
)

Define common error ids

View Source
const MaxInt = int(MaxUint >> 1) // on OSX,  9,223,372,036,854,775,807
View Source
const MaxUint = ^uint(0)
View Source
const MinInt = -MaxInt - 1 // on OSX, -9,223,372,036,854,775,808
View Source
const MinUint = 0

Variables

View Source
var (
	ErrorNotImplemented = &Error{HttpStatus: http.StatusNotImplemented, Id: ERR_NOT_IMPLEMENTED, Description: "This version of the service does not support the functionality required to fulfill the request."}
	ErrorBadRequest     = &Error{HttpStatus: http.StatusBadRequest, Id: ERR_BAD_REQUEST, Description: "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed."}
	ErrorInternal       = &Error{HttpStatus: http.StatusInternalServerError, Id: ERR_SERVICE_ERROR, Description: "The service encountered an unexpected condition that prevented it from fulfilling the request."}
	ErrorExternal       = &Error{HttpStatus: http.StatusBadGateway, Id: ERR_BAD_GATEWAY, Description: "The services, while acting as a gateway, received an invalid response from the upstream service."}
	ErrorNotFound       = &Error{HttpStatus: http.StatusNotFound, Id: ERR_NOT_FOUND, Description: "The service did not find the resource matching the Request-URI."}
	ErrorForbidden      = &Error{HttpStatus: http.StatusForbidden, Id: ERR_FORBIDDEN, Description: "Access to view or modify the resource identified by the Request-URI is forbidden."}
)

Defined common management Errors

View Source
var (
	HealthLogRate = 1

	ProfilingEnabled = true
)

Functions

func Engine

func Engine() *gin.Engine

Engine Return the one and only gin engine

func Listen

func Listen(hostAndPort string) error

Listen Listen to the given port (e.g., ":8888") and optional interface (designated by IP, e.g., lo0 using "127.0.0.1:8888")

func NewHttpClient

func NewHttpClient() *http.Client

Helper method used to create new Http Clients.

func SetHealth

func SetHealth(h *Health)

Types

type Counter

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

func (*Counter) Count

func (this *Counter) Count() int

Count Return the current count value

Note that this read is not syncronized by design, do not add Rlock

func (*Counter) Dec

func (this *Counter) Dec()

Dec Decrement the counter

func (*Counter) Inc

func (this *Counter) Inc()

Inc Increment the counter

func (*Counter) MarshalJSON

func (this *Counter) MarshalJSON() ([]byte, error)

func (*Counter) SetCount

func (this *Counter) SetCount(value int)

SetCount Force the count to a particular value

func (*Counter) WriteTo

func (this *Counter) WriteTo(w io.Writer)

type Error

type Error struct {
	// http status (e.g., http.StatusNotFound)
	HttpStatus int `json:"-"`

	// optional http headers, e.g. "retry_after"
	Header http.Header `json:"-"`

	// a freeform error identifier (e.g., 'BAD_PARAMETER')
	Id string `json:"error" binding:"required"`

	// the error identifier description
	Description string `json:"error_description" binding:"required"`

	// the error uri describing the error and recovery
	Uri string `json:"error_uri,omitempty"`
}

Defines the type used to represent REST API error message body. Note that in order to help clients handle error conditions this structure follows the Oauth 2.0 definition.

func Delete

func Delete(hostAndPort, path string) *Error

Delete Perform a HTTP DELETE

func DeleteWithHeaders

func DeleteWithHeaders(hostAndPort, path string, headers map[string]string) *Error

Delete Perform a HTTP DELETE. Adds headers to request if provided.

func Get

func Get(hostAndPort, path string) ([]byte, *Error)

Get Perform a HTTP GET returning response content as a byte array

func GetBadRequestError

func GetBadRequestError(description string) *Error

Helper method used to create a custom bad-request error.

func GetExternalError

func GetExternalError(description string) *Error

Helper method used to create a custom external error.

func GetForbiddenError

func GetForbiddenError(description string) *Error

Helper method used to create custom forbidden errors.

func GetInternalError

func GetInternalError(description string) *Error

Helper method used to create a custom internal error.

func GetNotFoundError

func GetNotFoundError(description string) *Error

Helper method used to create a custom not found error.

func GetResourceAlreadyExistsError

func GetResourceAlreadyExistsError(description string) *Error

func GetServiceUnavailableError

func GetServiceUnavailableError(description string, retryAfter int64) *Error

Helper method used to create custom 503 errors.

func GetWithHeaders

func GetWithHeaders(hostAndPort, path string, headers map[string]string) ([]byte, *Error)

Get Perform a HTTP GET with headers returning response content as a byte array

func NewError

func NewError(status int, id, template string, args ...interface{}) *Error

func Post

func Post(hostAndPort, path string) ([]byte, *Error)

Post Perform an empty HTTP POST returning response content as a byte array

func PostData

func PostData(hostAndPort, path string, content_type string, data []byte) ([]byte, *Error)

Post Perform HTTP POST request with data returning response content as a byte array

func PostDataWithHeaders

func PostDataWithHeaders(hostAndPort, path string, data []byte, headers map[string]string) ([]byte, *Error)

PostDataWithHeaders Perform a HTTP POST using the data returning response content as a byte array

func PostJSON

func PostJSON(hostAndPort, path string, content interface{}) ([]byte, *Error)

PostJSON Perform a HTTP POST using JSON content marshaled from the given content returning response content as a byte array

func PostJSONWithHeaders

func PostJSONWithHeaders(hostAndPort, path string, content interface{}, headers map[string]string) ([]byte, *Error)

PostJSONWithHeaders Perform a HTTP POST using JSON content marshaled from the given content returning response content as a byte array

func Put

func Put(hostAndPort, path string) ([]byte, *Error)

Put Perform an empty HTTP PUT returning response content as a byte array

func PutJSON

func PutJSON(hostAndPort, path string, content interface{}) ([]byte, *Error)

PutJSON Perform a HTTP PUT using the JSON content marsheled from the given content returning response content as a byte array

func PutJSONWithHeaders

func PutJSONWithHeaders(hostAndPort, path string, content interface{}, headers map[string]string) ([]byte, *Error)

PutJSONWithHeaders Perform a HTTP PUT using the JSON content marsheled from the given content returning response content as a byte array

func UploadFile

func UploadFile(hostAndPort, path string, filename string) ([]byte, *Error)

UploadFile: uploading a given file to server location Perform a HTTP POST using bytes buffer content returning response content as a byte array

func (*Error) Error

func (this *Error) Error() string

func (*Error) String

func (this *Error) String() string

type Health

type Health struct {
	// http status (e.g., http.StatusOK)
	HttpStatus int `json:"-"`

	// service name
	Name string `json:"name,omitempty"`

	// developer-defined health status (enumeration, e.g., "OK", "BAD", etc)
	Id string `json:"id" binding:"required"`

	// status definition
	Description string `json:"description,omitempty"`

	// status uri
	Uri string `json:"uri,omitempty"`
}

adapted from Dakota, "User Services Sprint 5",

func GetHealth

func GetHealth() *Health

get and set the current health value for this service

func NewHealth

func NewHealth(status int, id, template string, args ...interface{}) *Health

func (*Health) String

func (this *Health) String() string

type Profile

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

Profile A profile is a collection of reporters for a particular package or component.

func NewProfile

func NewProfile(name string) *Profile

NewProfile Create a new package or component profile, or return a previously created profile by name. The name is usually in the form of dot delimited package name (not slash delimited).

func (*Profile) AddCounter

func (this *Profile) AddCounter(name string, initial int) *Counter

AddCounter Add a Counter Reporter to the Profile

func (*Profile) AddCounterWithTemplate

func (this *Profile) AddCounterWithTemplate(name, template string, initial int) *Counter

AddCounterWithTemplate Add a Counter Reporter to the Profile with a custom reporting string

func (*Profile) AddRate

func (this *Profile) AddRate(name string, size int) *Rate

AddRate Add a Rate Reporter to the Profile

func (*Profile) AddRateWithTemplate

func (this *Profile) AddRateWithTemplate(name, template string, size int) *Rate

AddRateWithTemplate Add a Rate Reporter with a custom reporting template string

func (*Profile) AddReporter

func (this *Profile) AddReporter(name string, reporter Reporter)

Add Customer Reporter to the Profile See the default profile type definitions (e.g., Counter, Timer or Rate) for examples of a Reporter

func (*Profile) AddTimer

func (this *Profile) AddTimer(name string, size int) *Timer

AddTimer Add a Timer Reporter to the Profile

func (*Profile) AddTimerWithTemplate

func (this *Profile) AddTimerWithTemplate(name, template string, size int) *Timer

AddTimerWithTemplate Add a Timer Reporter with a custom reporting template string

func (*Profile) Counter

func (this *Profile) Counter(name string) (*Counter, bool)

Counter Get the named counter

func (*Profile) MarshalJSON

func (this *Profile) MarshalJSON() ([]byte, error)

Custom JSON Marshaller

func (*Profile) Rate

func (this *Profile) Rate(name string) (*Rate, bool)

Rate Get the named rate reporter

func (*Profile) Reporter

func (this *Profile) Reporter(name string) (interface{}, bool)

Reporter Get the named reporter

func (*Profile) Timer

func (this *Profile) Timer(name string) (*Timer, bool)

Timer Get the named timer

func (*Profile) WriteTo

func (this *Profile) WriteTo(w io.Writer)

Report

type Rate

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

func (*Rate) AddSample

func (this *Rate) AddSample(sample time.Time)

AddSample Add time-stamp to the set of samples

func (*Rate) AvgRate

func (this *Rate) AvgRate() time.Duration

AvgRate Determine and return the event frequency rate based on the samples provided

func (*Rate) MarshalJSON

func (this *Rate) MarshalJSON() ([]byte, error)

func (*Rate) Size

func (this *Rate) Size() int

Size Return size of the sample set

func (*Rate) WriteTo

func (this *Rate) WriteTo(w io.Writer)

type Reporter

type Reporter interface {
	WriteTo(w io.Writer)
	MarshalJSON() ([]byte, error)
}

Reporter A reporter writes profile information to the given io.Writer (e.g., for plain-text web-pages or logging) or JSON marshaller

type Timer

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

func (*Timer) AddDuration

func (this *Timer) AddDuration(duration time.Duration)

AddDuration Add a duration value to the set of durations

func (*Timer) AvgDuration

func (this *Timer) AvgDuration() time.Duration

AvgDuration Calculate the average duration from the set of duration values (i.e., ramped up to a max set length, e.g., if only two samples were taken, the result will be the average of those two samples - not the maximum number of samples allowed)

Note that this read is not syncronized by design, do not add Rlock

func (*Timer) MarshalJSON

func (this *Timer) MarshalJSON() ([]byte, error)

func (*Timer) Size

func (this *Timer) Size() int

Size Return size of the duration set

func (*Timer) WriteTo

func (this *Timer) WriteTo(w io.Writer)

Jump to

Keyboard shortcuts

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