db

package
v0.0.0-...-6b7fd41 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetID

func SetID(name string) string

SetID generates a unique ID for a service based on its name This is useful for Firestore, which requires a unique ID for each document

Types

type Environment

type Environment string
const (
	Prod    Environment = "prod"
	Staging Environment = "staging"
	Dev     Environment = "dev"
)

type FirestoreDB

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

FirestoreDB represents a service in the database

func NewFirestoreDB

func NewFirestoreDB(ctx context.Context, projectID string) (*FirestoreDB, error)

NewFirestoreDB creates a new FirestoreDB instance It requires a context and a projectID The projectID is the GCP project ID where Firestore is located

func (*FirestoreDB) DeleteService

func (db *FirestoreDB) DeleteService(ctx context.Context, ID string) error

DeleteService deletes a service from Firestore by its ID

func (*FirestoreDB) GetService

func (db *FirestoreDB) GetService(ctx context.Context, ID string) (*Service, error)

GetService retrieves a service from Firestore by its name If the service does not exist, an error will be returned The ID is a sha256 hash of the service name

func (*FirestoreDB) GetServices

func (db *FirestoreDB) GetServices(ctx context.Context) ([]*Service, error)

GetServices retrieves a list of services from Firestore

func (*FirestoreDB) SetService

func (db *FirestoreDB) SetService(ctx context.Context, ID string, data Service) error

SetService sets a service in Firestore, it will be used both for updating and creating services If the service does not exist, it will be created

func (*FirestoreDB) UpdateServiceURL

func (db *FirestoreDB) UpdateServiceURL(ctx context.Context, ID string, url string) error

UpdateServiceURL updates the URL of a service in Firestore It requires the ID of the service and the new URL

type Service

type Service struct {
	ID          string      `json:"-" firestore:"id"`
	Name        string      `json:"name" firestore:"name"`
	URL         string      `json:"url" firestore:"url" validate:"required,min=1"`
	Environment Environment `json:"environment" firestore:"environment" validate:"required,min=1"`
	Description string      `json:"description" firestore:"description"`
}

Service represents a service in the database ID is a sha256 hash of the service name Name is the service name URL is the URL of the service Environment is the environment where the service is running Description is a brief description of the service

func (*Service) Validate

func (s *Service) Validate() error

Validate the service model ensuring URL and Environment are valid It also uses the go-playground/validator to validate the struct

func (*Service) ValidateEnv

func (s *Service) ValidateEnv() error

ValidateEnv checks if the service environment is valid.

func (*Service) ValidateURL

func (s *Service) ValidateURL() error

ValidateURL checks if the service URL matches the Cloud Run URL pattern.

Jump to

Keyboard shortcuts

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