Documentation ¶
Index ¶
- Constants
- Variables
- func GetPasswordHash(password string) (string, error)
- func InitDB() error
- func Migrate(migrationsDirUri string, destroy bool) error
- func SetDBConfiguration() error
- type CreateServiceInput
- type CreateVersionInput
- type GetServiceWithVersionsTxOutput
- type ListServicesInput
- type Model
- type Service
- type UpdateServiceInput
- type User
- type Version
Constants ¶
const (
MIGRATIONS_DIR_URI = "file://internal/models/migrations"
)
const ServiceTableName = "services"
const UserTableName = "users"
const VersionTableName = "versions"
Variables ¶
var ( ErrRecordNotFound = errors.New("record not found") ErrUniqueConstraintViolation = errors.New("unique key constraint violated") )
var DB *gorm.DB
Functions ¶
func GetPasswordHash ¶
func Migrate ¶
Migrate runs the migrations present in the specified URI. If destroy is true, the migrations are run downwards than upwards.
func SetDBConfiguration ¶
func SetDBConfiguration() error
SetDBConfiguration reads the database connection configuration from env vars. This NEEDS to be called before InitDB().
Types ¶
type CreateServiceInput ¶
type CreateServiceInput struct { Name string `json:"name" binding:"required,max=50"` Description string `json:"description"` UserID uint }
CreateServiceInput represents the input required to create a Service.
type CreateVersionInput ¶
type CreateVersionInput struct { Version string `json:"version" binding:"required,max=50"` ServiceID int Changelog string `json:"changelog"` UserID uint }
CreateVersionInput represents the input required to create Version object.
type GetServiceWithVersionsTxOutput ¶
type GetServiceWithVersionsTxOutput struct { ServiceID uint ServiceCreatedAt time.Time ServiceUpdatedAt time.Time Name string Description string VersionID uint VersionCreatedAt time.Time VersionUpdatedAt time.Time Version string Changelog string }
GetServiceWithVersionsTxOutput represents the various columns returned by the database query made in GetServiceWithVersions().
func GetServiceWithVersions ¶
func GetServiceWithVersions(svcID uint, userID uint) ([]GetServiceWithVersionsTxOutput, error)
GetServiceWithVersions returns the requested Service for the provided ID along of the Version objects belonging to this Service.
type ListServicesInput ¶
type ListServicesInput struct { Limit int `form:"limit"` Offset int `form:"offset"` UserID uint SortKey string `form:"sortKey"` Descending bool `form:"descending"` Name string `form:"name"` }
ListServicesInput represnts the different input parameters that can be included in the database query. The form struct tags allows for convinient query parameter validation.
type Model ¶
type Model struct { ID uint `json:"id"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` }
Model contains common fields across all tables. It is exactly like gorm.Model with the exception of JSON field tags.
type Service ¶
type Service struct { Model Name string `json:"name"` Description string `json:"description"` // Versions contains the different versions of this service. // It helps us fetch the versions without a JOIN query. Versions pq.StringArray `json:"versions" gorm:"type:varchar(50)[]"` UserID int `json:"userID"` }
Service represents a single service in the catalog.
func CreateService ¶
func CreateService(input CreateServiceInput) (*Service, error)
CreateService creates a new Service.
func GetService ¶
GetService returns the Service for the provided ID.
func ListServices ¶
func ListServices(input ListServicesInput) ([]Service, error)
ListServices returns a list of Service objects based on the different input parameters.
func UpdateService ¶
func UpdateService(input UpdateServiceInput, id uint, userID uint) (*Service, error)
type UpdateServiceInput ¶
type UpdateServiceInput struct { Name string `json:"name" binding:"max=50"` Description string `json:"description"` }
CreateServiceInput represents the input required to create a Service.
type User ¶
User represents a registered user.
func CreateUser ¶
CreateUser creates a user with the provided username and password.
func GetUserByID ¶
GetUserByID returns the User for the provided ID.
func GetUserByUsername ¶
GetUserByUsername returns the User for the provided username.
type Version ¶
type Version struct { Model Version string `json:"version"` ServiceID int `json:"serviceID"` Changelog string `json:"changelog"` }
Version represents a version of a Service.
func CreateVersion ¶
func CreateVersion(input CreateVersionInput) (*Version, error)
CreateVersion fetches the Service with the provided id, and if it exists, it creates a new Version according to the input and then update the related Service with the new version string.