Documentation ¶
Overview ¶
Package services defines the control plane for sherlock's service entities and api routes for interating with those control plane methods
Index ¶
- Variables
- type CreateServiceRequest
- type MockServiceStore
- type Response
- type Service
- type ServiceController
- func (sc *ServiceController) CreateNew(newService CreateServiceRequest) (Service, error)
- func (sc *ServiceController) DoesServiceExist(name string) (id int, ok bool)
- func (sc *ServiceController) GetByName(name string) (Service, error)
- func (sc *ServiceController) ListAll() ([]Service, error)
- func (sc *ServiceController) RegisterHandlers(routerGroup *gin.RouterGroup)
- type ServiceResponse
- type ServiceSerializer
- type ServicesSerializer
Constants ¶
This section is empty.
Variables ¶
var ErrBadCreateRequest error = errors.New("error invalid create service request. service name and repo url are required")
ErrBadCreateRequest is an error type used when a create servie request fails validation checks
var (
ErrServiceNotFound = gorm.ErrRecordNotFound
)
ErrServiceNotFound is the error to represent a failed lookup of a service entity
Functions ¶
This section is empty.
Types ¶
type CreateServiceRequest ¶
type CreateServiceRequest struct { Name string `json:"name" binding:"required"` RepoURL string `json:"repo_url" binding:"required"` }
CreateServiceRequest is a type used to represent the information required to register a new service in sherlock
type MockServiceStore ¶
MockServiceStore is used for mocking underlying database operations for services in unit tests
type Response ¶
type Response struct { Services []ServiceResponse `json:"services"` Error string `json:"error,omitempty"` }
Response is a type that allows all data returned from the /service api group to share a consistent structure
type Service ¶
Service is the data structure that models a service entity persisted to a database via gorm
type ServiceController ¶
type ServiceController struct {
// contains filtered or unexported fields
}
ServiceController is the management layer for CRUD operations for service entities
func NewController ¶
func NewController(dbConn *gorm.DB) *ServiceController
NewController accepts a gorm DB connection and returns a new instance of the service controller
func NewMockController ¶
func NewMockController(mockStore *MockServiceStore) *ServiceController
NewMockController returns a service controller that will use a customizable mock store for use in tests in other packages
func (*ServiceController) CreateNew ¶
func (sc *ServiceController) CreateNew(newService CreateServiceRequest) (Service, error)
CreateNew is the public api on the serviceController for persisting a new service entity to the data store
func (*ServiceController) DoesServiceExist ¶
func (sc *ServiceController) DoesServiceExist(name string) (id int, ok bool)
DoesServiceExist is a helper method to check if a service with the given name already exists in sherlock's data storage
func (*ServiceController) GetByName ¶
func (sc *ServiceController) GetByName(name string) (Service, error)
GetByName is the public API for looking up a service from the data store by name
func (*ServiceController) ListAll ¶
func (sc *ServiceController) ListAll() ([]Service, error)
ListAll is the public api for listing out all services tracked by sherlock
func (*ServiceController) RegisterHandlers ¶
func (sc *ServiceController) RegisterHandlers(routerGroup *gin.RouterGroup)
RegisterHandlers accepts a gin router and will attach handlers for working with Service entities to it
type ServiceResponse ¶
type ServiceResponse struct { ID int `json:"id"` Name string `json:"name"` RepoURL string `json:"repo_url"` }
ServiceResponse is the type used to serialize Service data that is returned to clients of the sherlock api
type ServiceSerializer ¶
type ServiceSerializer struct {
Service Service
}
ServiceSerializer is used to serializer a single Service model to a used to generate responses from the /services api group
func (*ServiceSerializer) Response ¶
func (ss *ServiceSerializer) Response() ServiceResponse
Response takes a Service Model entity and transforms it into a ServiceResponse
type ServicesSerializer ¶
type ServicesSerializer struct {
Services []Service
}
ServicesSerializer is used to serialize a ServiceModel entity to a a format used in http response bodies
func (*ServicesSerializer) Response ¶
func (ss *ServicesSerializer) Response() []ServiceResponse
Response serializes Service models into Service Responses