Documentation
¶
Index ¶
- Constants
- Variables
- func Engine() *gin.Engine
- func Listen(hostAndPort string) error
- func NewHttpClient() *http.Client
- func SetHealth(h *Health)
- type Counter
- type Error
- func Delete(hostAndPort, path string) *Error
- func DeleteWithHeaders(hostAndPort, path string, headers map[string]string) *Error
- func Get(hostAndPort, path string) ([]byte, *Error)
- func GetBadRequestError(description string) *Error
- func GetExternalError(description string) *Error
- func GetForbiddenError(description string) *Error
- func GetInternalError(description string) *Error
- func GetNotFoundError(description string) *Error
- func GetResourceAlreadyExistsError(description string) *Error
- func GetServiceUnavailableError(description string, retryAfter int64) *Error
- func GetWithHeaders(hostAndPort, path string, headers map[string]string) ([]byte, *Error)
- func NewError(status int, id, template string, args ...interface{}) *Error
- func Post(hostAndPort, path string) ([]byte, *Error)
- func PostData(hostAndPort, path string, content_type string, data []byte) ([]byte, *Error)
- func PostDataWithHeaders(hostAndPort, path string, data []byte, headers map[string]string) ([]byte, *Error)
- func PostJSON(hostAndPort, path string, content interface{}) ([]byte, *Error)
- func PostJSONWithHeaders(hostAndPort, path string, content interface{}, headers map[string]string) ([]byte, *Error)
- func Put(hostAndPort, path string) ([]byte, *Error)
- func PutJSON(hostAndPort, path string, content interface{}) ([]byte, *Error)
- func PutJSONWithHeaders(hostAndPort, path string, content interface{}, headers map[string]string) ([]byte, *Error)
- func UploadFile(hostAndPort, path string, filename string) ([]byte, *Error)
- type Health
- type Profile
- func (this *Profile) AddCounter(name string, initial int) *Counter
- func (this *Profile) AddCounterWithTemplate(name, template string, initial int) *Counter
- func (this *Profile) AddRate(name string, size int) *Rate
- func (this *Profile) AddRateWithTemplate(name, template string, size int) *Rate
- func (this *Profile) AddReporter(name string, reporter Reporter)
- func (this *Profile) AddTimer(name string, size int) *Timer
- func (this *Profile) AddTimerWithTemplate(name, template string, size int) *Timer
- func (this *Profile) Counter(name string) (*Counter, bool)
- func (this *Profile) MarshalJSON() ([]byte, error)
- func (this *Profile) Rate(name string) (*Rate, bool)
- func (this *Profile) Reporter(name string) (interface{}, bool)
- func (this *Profile) Timer(name string) (*Timer, bool)
- func (this *Profile) WriteTo(w io.Writer)
- type Rate
- type Reporter
- type Timer
Constants ¶
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
const MaxInt = int(MaxUint >> 1) // on OSX, 9,223,372,036,854,775,807
const MaxUint = ^uint(0)
const MinInt = -MaxInt - 1 // on OSX, -9,223,372,036,854,775,808
const MinUint = 0
Variables ¶
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
var ( HealthLogRate = 1 ProfilingEnabled = true )
Functions ¶
func Listen ¶
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 ¶
Helper method used to create new Http Clients.
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
func (*Counter) Count ¶
Count Return the current count value
Note that this read is not syncronized by design, do not add Rlock
func (*Counter) MarshalJSON ¶
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 DeleteWithHeaders ¶
Delete Perform a HTTP DELETE. Adds headers to request if provided.
func GetBadRequestError ¶
Helper method used to create a custom bad-request error.
func GetExternalError ¶
Helper method used to create a custom external error.
func GetForbiddenError ¶
Helper method used to create custom forbidden errors.
func GetInternalError ¶
Helper method used to create a custom internal error.
func GetNotFoundError ¶
Helper method used to create a custom not found error.
func GetServiceUnavailableError ¶
Helper method used to create custom 503 errors.
func GetWithHeaders ¶
Get Perform a HTTP GET with headers 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 ¶
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 PutJSON ¶
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 ¶
UploadFile: uploading a given file to server location Perform a HTTP POST using bytes buffer content returning response content as a byte array
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",
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 ¶
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 ¶
AddCounter Add a Counter Reporter to the Profile
func (*Profile) AddCounterWithTemplate ¶
AddCounterWithTemplate Add a Counter Reporter to the Profile with a custom reporting string
func (*Profile) AddRateWithTemplate ¶
AddRateWithTemplate Add a Rate Reporter with a custom reporting template string
func (*Profile) AddReporter ¶
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) AddTimerWithTemplate ¶
AddTimerWithTemplate Add a Timer Reporter with a custom reporting template string
func (*Profile) MarshalJSON ¶
Custom JSON Marshaller
type Rate ¶
type Rate struct {
// contains filtered or unexported fields
}
func (*Rate) AvgRate ¶
AvgRate Determine and return the event frequency rate based on the samples provided
func (*Rate) MarshalJSON ¶
type Reporter ¶
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 ¶
AddDuration Add a duration value to the set of durations
func (*Timer) AvgDuration ¶
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