environments

package
v0.0.3 Latest Latest
Warning

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

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

Documentation

Overview

Package environments defines data structure representing a environment instance and methods for interacting with them it is left to concrete implementations in package db or others to implement these interfaces

Index

Constants

This section is empty.

Variables

View Source
var ErrBadCreateRequest error = errors.New("error invalid create environment request. environment name is required")

ErrBadCreateRequest is an error type used when a create environment request fails validation checks

View Source
var ErrEnvironmentNotFound = gorm.ErrRecordNotFound

ErrEnvironmentNotFound is the error to represent a failed lookup of a environment db record

Functions

This section is empty.

Types

type CreateEnvironmentRequest

type CreateEnvironmentRequest struct {
	Name string `json:"name" binding:"required"`
}

CreateEnvironmentRequest struct defines the data required to create a new environment in db

type Environment

type Environment struct {
	ID          int
	Name        string
	IsPermanent bool
	Requester   string
	DestroyedAt time.Time
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

Environment is the data structure that models a persisted to a database via gorm

func Seed added in v0.0.2

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

Seed takes a gorm DB connection and will seed a db with some fake environment data for use in integration testing

type EnvironmentController

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

EnvironmentController is the management layer for environments

func NewController

func NewController(dbConn *gorm.DB) *EnvironmentController

NewController accepts a gorm DB connection and returns a new instance of the environment controller

func NewMockController added in v0.0.2

func NewMockController(mockStore *MockEnvironmentStore) *EnvironmentController

NewMockController returns an EnvironmentController instance with the provided mock of the storage layer for use in unit tests

func (*EnvironmentController) CreateNew

func (environmentController *EnvironmentController) CreateNew(newEnvironment CreateEnvironmentRequest) (Environment, error)

CreateNew is the public api on the environmentController for persisting a new service entity to the data store

func (EnvironmentController) DoesEnvironmentExist

func (environmentController EnvironmentController) DoesEnvironmentExist(name string) (id int, ok bool)

DoesEnvironmentExist is a helper method to check if a environment with the given name already exists in sherlock's data storage

func (*EnvironmentController) GetByName

func (environmentController *EnvironmentController) GetByName(name string) (Environment, error)

GetByName is the public API for looking up a environment from the data store by name

func (*EnvironmentController) ListAll

func (environmentController *EnvironmentController) ListAll() ([]Environment, error)

ListAll is the public api for listing out all environments tracked by sherlock

func (*EnvironmentController) RegisterHandlers added in v0.0.2

func (ec *EnvironmentController) RegisterHandlers(routerGroup *gin.RouterGroup)

RegisterHandlers accepts a routergroup and will attach all the handlers for working with environment entities to it

type EnvironmentResponse added in v0.0.2

type EnvironmentResponse struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

EnvironmentResponse is the type that environment entities are serialized to and used in responses to clients

type EnvironmentSerializer added in v0.0.3

type EnvironmentSerializer struct {
	Environment Environment
}

func (*EnvironmentSerializer) Response added in v0.0.3

type EnvironmentsSerializer added in v0.0.2

type EnvironmentsSerializer struct {
	Environments []Environment
}

EnvironmentsSerializer is used to convert a list of environment model types to a Respopnse type used to send environment info to clients

func (*EnvironmentsSerializer) Response added in v0.0.2

Response is a function that Serializers a slice of Environment models to responses suitable for sending to clients

type MockEnvironmentStore added in v0.0.2

type MockEnvironmentStore struct {
	mock.Mock
}

MockEnvironmentStore is a concrete type that implements environmentStore interface for use in unit tests

type Response

type Response struct {
	Environments []EnvironmentResponse `json:"environments"`
	Error        string                `json:"error,omitempty"`
}

Response is a type that allows all data returned from the /environment api group to share a consistent structure

Jump to

Keyboard shortcuts

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