Documentation
¶
Index ¶
- func SetID(name string) string
- type Environment
- type FirestoreDB
- func (db *FirestoreDB) DeleteService(ctx context.Context, ID string) error
- func (db *FirestoreDB) GetService(ctx context.Context, ID string) (*Service, error)
- func (db *FirestoreDB) GetServices(ctx context.Context) ([]*Service, error)
- func (db *FirestoreDB) SetService(ctx context.Context, ID string, data Service) error
- func (db *FirestoreDB) UpdateServiceURL(ctx context.Context, ID string, url string) error
- type Service
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
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 ¶
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 ¶
Validate the service model ensuring URL and Environment are valid It also uses the go-playground/validator to validate the struct
func (*Service) ValidateEnv ¶
ValidateEnv checks if the service environment is valid.
func (*Service) ValidateURL ¶
ValidateURL checks if the service URL matches the Cloud Run URL pattern.