setup

package module
v0.0.0-...-4cf80b3 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: GPL-3.0 Imports: 11 Imported by: 28

README

Basic setup helpers for microservices

We typically use sql, redis and datastore in our microservices

These provide some basic methods and structs to keep our microservice definition and structure consistent

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConfig

func GetConfig(deployment string, config any) error

GetConfig creates a config for the specified deployment from a local file of form "***-config.json" the json file is decoded into the supplied struct (each service will provide its own config struct)

func NewSafecilitySql

func NewSafecilitySql(config MySQLConfig) (*sql.DB, error)

NewSafecilitySql creates a new MySQL server.

Types

type Deployment

type Deployment string
const (
	LocalTest  Deployment = "local-test"
	Local      Deployment = "local"
	Test       Deployment = "test"
	Staging    Deployment = "staging"
	Production Deployment = "prod"
)

type MySQLConfig

type MySQLConfig struct {
	//don't json in password
	Password               string `json:"-"`
	Username               string `json:"user"`
	Host                   string `json:"host"`
	Port                   int    `json:"port"`
	Database               string `json:"database"`
	InstanceConnectionName string `json:"instanceConnectionName"`
}

type RedisConfig

type RedisConfig struct {
	Host   string  `json:"host"`
	Port   int     `json:"port"`
	Secret *Secret `json:"secret"`
	Key    []byte  `json:"-"`
}

func (*RedisConfig) Address

func (r *RedisConfig) Address() string

func (*RedisConfig) NewClient

func (r *RedisConfig) NewClient() (*redis.Client, error)

type Secret

type Secret struct {
	Name    string `json:"name"`
	Version int    `json:"version"`
}

type Secrets

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

func GetNewSecrets

func GetNewSecrets(projectID string, client *secretmanager.Client) *Secrets

GetNewSecrets - fix all the weird things in google's api

func (*Secrets) AddSecretVersion

func (s *Secrets) AddSecretVersion(secretName string, newPayload []byte) (*secretmanagerpb.SecretVersion, error)

func (*Secrets) Close

func (s *Secrets) Close() error

func (*Secrets) GetSecret

func (s *Secrets) GetSecret(secret Secret) ([]byte, error)

GetSecret retrieve a secret with the given version name. The version name must comply with naming convention - auto is 1, 2 etc

func (*Secrets) SetSecret

func (s *Secrets) SetSecret(secretID string, payload []byte) (*secretmanagerpb.Secret, error)

func (*Secrets) UpdateSecret

func (s *Secrets) UpdateSecret(secret Secret, labels map[string]string) error

Jump to

Keyboard shortcuts

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