services

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package services defines the control plane for sherlock's service entities and api routes for interating with those control plane methods

Index

Constants

This section is empty.

Variables

View Source
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

View Source
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

type MockServiceStore struct {
	mock.Mock
}

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

type Service struct {
	ID        int    `gorm:"primaryKey" faker:"unique"`
	Name      string `gorm:"not null;default:null"`
	RepoURL   string
	CreatedAt time.Time
	UpdatedAt time.Time
}

Service is the data structure that models a service entity persisted to a database via gorm

func Seed added in v0.0.2

func Seed(db *gorm.DB) ([]Service, error)

Seed is a test utility that will populate a database with a predetermined list of "services" to be used for running integration tests against a real database

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) FindOrCreate added in v0.0.7

func (sc *ServiceController) FindOrCreate(name string) (int, error)

FindOrCreate will attempt to look an environment by name and return its ID if successful if unsuccessful it will create a new environment from the provider name and return that id

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

Jump to

Keyboard shortcuts

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