Documentation
¶
Index ¶
- Constants
- func ExtractRequestBody(request *restful.Request, body RequestBody) error
- func GetCreatedID(rows *sqlx.Rows) (int64, error)
- func LoadServiceConfig(fileName string, output *ServiceConfig) error
- func WriteError(response *restful.Response, err error)
- type AccessDeniedError
- type BackendConfig
- type DBConfig
- type DuplicateResourceError
- type EndpointConfig
- type ErrorBody
- type IllegalArgumentError
- type LoggingConfig
- type RequestBody
- type ResourceNotFoundError
- type ResourceResult
- type ServiceConfig
- type StatsResource
- type SwaggerConfig
- type UnauthorizedError
Constants ¶
const ( // DefaultMaxOpenConnections represents the default number of open database connections DefaultMaxOpenConnections = 10 // DefaultMaxIdleConnections represents the default number of idle database connections DefaultMaxIdleConnections = 10 )
Variables ¶
This section is empty.
Functions ¶
func ExtractRequestBody ¶
func ExtractRequestBody(request *restful.Request, body RequestBody) error
ExtractRequestBody extracts the body of a request into a RequestBody and validates it. Returns an error if the extraction fails.
func GetCreatedID ¶
GetCreatedID grabs the sequential id from the result rows returned from an INSERT...RETURNING query and closes the result set.
func LoadServiceConfig ¶
func LoadServiceConfig(fileName string, output *ServiceConfig) error
LoadServiceConfig loads configuration from a file containing configuration in JSON.
func WriteError ¶
func WriteError(response *restful.Response, err error)
WriteError ensures the error is appropriately handled by ensuring the correct http status code is assigned and the error message is logged.
Types ¶
type AccessDeniedError ¶
type AccessDeniedError struct {
Err error
}
AccessDeniedError represents unauthorized access to a specific system function or resource
func (*AccessDeniedError) Error ¶
func (a *AccessDeniedError) Error() string
Error returns this error as a string
func (*AccessDeniedError) StatusCode ¶
func (a *AccessDeniedError) StatusCode() int
StatusCode returns the HTTP status code appropriate for the error type
func (*AccessDeniedError) Unwrap ¶
func (a *AccessDeniedError) Unwrap() error
Unwrap returns the underlying error
type BackendConfig ¶
type BackendConfig struct { BackendName string `json:"backend_name"` FilePath string `json:"file_path"` }
BackendConfig represents configuration of a specific logging backend, specifically one of [STDOUT, SYSLOG, FILE]
type DBConfig ¶
type DBConfig struct { Hostname string `json:"hostname"` Port int `json:"port"` MaxIdleConnections int `json:"max_idle_connections"` MaxOpenConnections int `json:"max_open_connections"` DBName string `json:"dbname"` SSLMode string `json:"sslmode"` ConnectTimeout int `json:"connect_timeout"` SchemaName string `json:"schema_name"` Role string `json:"role"` RolePassword string `json:"role_password"` }
DBConfig represents database configuration that points to a specific schema and allows for connection specific settings.
func ParseDBConfig ¶
ParseDBConfig represents a configuration that is parsed from an environment variable. Returns an error onky if an environment variable exists and parsing data from that environment fails. If an environment variable is not set nil is returned.
type DuplicateResourceError ¶
DuplicateResourceError represents a duplicate resource signal (409) typically raised on resource creation
func (*DuplicateResourceError) Error ¶
func (d *DuplicateResourceError) Error() string
Error returns this error as a string
func (*DuplicateResourceError) StatusCode ¶
func (d *DuplicateResourceError) StatusCode() int
StatusCode returns the HTTP status code appropriate for the error type
func (*DuplicateResourceError) Unwrap ¶
func (d *DuplicateResourceError) Unwrap() error
Unwrap returns the underlying error
type EndpointConfig ¶
EndpointConfig represents the root configuration for the service
func (*EndpointConfig) GetHostAddress ¶
func (e *EndpointConfig) GetHostAddress() string
GetHostAddress returns the host address host:port. If the host is empty, returns a leading ':'.
func (*EndpointConfig) Validate ¶
func (e *EndpointConfig) Validate() error
Validate ensures the service config is valid
type ErrorBody ¶
type ErrorBody struct { ErrorMessage string `json:"error" description:"The error message."` StatusCode int `json:"status_code" description:"The status code."` }
ErrorBody struct is used when constructing a single error response body.
type IllegalArgumentError ¶
IllegalArgumentError represents a bad request argument (400)
func (*IllegalArgumentError) Error ¶
func (i *IllegalArgumentError) Error() string
Error returns this error as as string
func (*IllegalArgumentError) StatusCode ¶
func (i *IllegalArgumentError) StatusCode() int
StatusCode returns the HTTP status code appropriate for the error type
func (*IllegalArgumentError) Unwrap ¶
func (i *IllegalArgumentError) Unwrap() error
Unwrap returns the underlying error
type LoggingConfig ¶
type LoggingConfig struct { LogLevel string `json:"log_level"` Format string `json:"format"` Backends []BackendConfig `json:"backends"` }
LoggingConfig contains configuration for op/go-logging
func (*LoggingConfig) InitializeLogging ¶
func (l *LoggingConfig) InitializeLogging() error
InitializeLogging configures logging based on the logging configuration.
func (*LoggingConfig) Validate ¶
func (l *LoggingConfig) Validate() error
Validate ensures a configuration has populated all required fields.
type RequestBody ¶
type RequestBody interface { // Validate validatess the request body, returning an error if validation fails. Validate() error }
RequestBody represents a request body that can be validated.
type ResourceNotFoundError ¶
ResourceNotFoundError represents an error when a resource could not be found (404).
func (*ResourceNotFoundError) Error ¶
func (r *ResourceNotFoundError) Error() string
Error returns this error as a string
func (*ResourceNotFoundError) StatusCode ¶
func (r *ResourceNotFoundError) StatusCode() int
StatusCode returns the HTTP status code appropriate for the error type
func (*ResourceNotFoundError) Unwrap ¶
func (r *ResourceNotFoundError) Unwrap() error
Unwrap returns the underlying error
type ResourceResult ¶
ResourceResult represents a definition of a resource that is identifiable and tracks creation/update timestamps.
func GetCreatedResourceResult ¶
func GetCreatedResourceResult(rows *sqlx.Rows) (*ResourceResult, error)
GetCreatedResourceResult grabs the sequential id created_on and modified_on timestamps from the result rows returned from an INSERT...RETURNING query and closes the result set.
type ServiceConfig ¶
type ServiceConfig struct { Endpoint *EndpointConfig `json:"endpoint"` DB *DBConfig `json:"db"` MigrationDB *DBConfig `json:"migration_db"` Swagger *SwaggerConfig `json:"swagger"` Logging *LoggingConfig `json:"logging"` Custom map[string]interface{} `json:"custom"` // contains filtered or unexported fields }
ServiceConfig represents a configuration suitable for fully configuration a service.
func NewServiceConfig ¶
func NewServiceConfig() *ServiceConfig
NewServiceConfig intializes a new instance
func (*ServiceConfig) SetCustomValidator ¶
func (s *ServiceConfig) SetCustomValidator(f func(map[string]interface{}) error)
SetCustomValidator sets a function that is executed during validation that validates any custom configuration
func (*ServiceConfig) Validate ¶
func (s *ServiceConfig) Validate() error
Validate validates a configuration, returning an error signaling invalid configuration
type StatsResource ¶
type StatsResource struct { ServiceName string `json:"service_name" description:"The name of the service."` ServiceUptime string `json:"service_uptime" description:"The service uptime in unix format."` ServiceStartTime time.Time `json:"service_start_time" description:"Timestamp in UTC of when the service was first started."` ServiceVersion string `json:"service_version" description:"The version of the service binary."` CommitHash string `json:"commit_hash" description:"The git commit hash representing the sources built into the service binary."` APIVersion string `json:"api_version" description:"The version of the API (protocol)."` }
StatsResource represents health stats that can be exposed as an API, useful for monitoring
func (*StatsResource) UpdateUptime ¶
func (s *StatsResource) UpdateUptime()
UpdateUptime updates the service uptime based on the current time returned in a Unix standard uptime format.
type SwaggerConfig ¶
type SwaggerConfig struct { APIPath string `json:"api_path"` SwaggerPath string `json:"swagger_path"` SwaggerFilePath string `json:"swagger_file_path"` }
SwaggerConfig represents configuration to enable swagger documentation.
func (*SwaggerConfig) InstallSwaggerService ¶
func (s *SwaggerConfig) InstallSwaggerService(info *spec.Info)
InstallSwaggerService sets up and installs the swagger service
func (*SwaggerConfig) Validate ¶
func (s *SwaggerConfig) Validate() error
Validate ensures the configuration is valid
type UnauthorizedError ¶
type UnauthorizedError struct {}
UnauthorizedError represents unauthorized access to the system
func (*UnauthorizedError) Error ¶
func (u *UnauthorizedError) Error() string
Error returns this error as a string
func (*UnauthorizedError) StatusCode ¶
func (u *UnauthorizedError) StatusCode() int
StatusCode returns the HTTP status code appropriate for the error type
func (*UnauthorizedError) Unwrap ¶
func (u *UnauthorizedError) Unwrap() error
Unwrap returns the underlying error