Documentation ¶
Index ¶
- Constants
- Variables
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func MustAsset(name string) []byte
- func NewMigrator(dsn DSN, opts ...MigrateOption) (*migrate.Migrate, error)
- func NewMigratorFromDB(db *sql.DB, opts ...MigrateOption) (*migrate.Migrate, error)
- func Open(dsn DSN) (*sqlx.DB, error)
- func QueryRowx(db sqlx.Queryer, handler RowHandler, qry string, args ...interface{}) error
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- type DSN
- type DentryStore
- func (store *DentryStore) DelegationTables() ([]string, error)
- func (store *DentryStore) DeleteDentryById(id uuid.UUID) (int64, error)
- func (store *DentryStore) DeleteDentryByPrefix(dtab, prefix string) (int64, error)
- func (store *DentryStore) DentriesByDtab(ctx context.Context, dtab string) (<-chan *store.Dentry, error)
- func (store *DentryStore) DtabUpdates() <-chan namerd.Dtab
- func (store *DentryStore) PutDentry(dentry *store.Dentry) (*store.Dentry, error)
- type MigrateLogger
- type MigrateOption
- type QueryExecer
- type RowHandler
- type RowHandlerFunc
- type ServiceStore
- type Store
Constants ¶
const DentryTableName = "dentry"
Dentry table name
const ServiceTableName = "service"
Service table name
Variables ¶
var DeleteDentryByIdQry = fmt.Sprintf(` DELETE FROM public.%s WHERE id=$1`, DentryTableName)
var DeleteDentryByPrefixQry = fmt.Sprintf(` DELETE FROM public.%s WHERE dtab=$1 AND prefix=$2`, DentryTableName)
var DentryListByDtab = fmt.Sprintf(` SELECT * FROM public.%s WHERE dtab = $1 ORDER BY priority ASC`, DentryTableName)
var GetServiceByLogicalNameQry = fmt.Sprintf(` SELECT * FROM "%s" WHERE logical_name = $1`, ServiceTableName)
var SelectDentryById = fmt.Sprintf(` SELECT * FROM public.%s WHERE id=$1`, DentryTableName)
var UpsertDentryQry = fmt.Sprintf(` INSERT INTO public.%s ( "dtab", "prefix", "destination", "priority") VALUES ($1,$2,$3,$4) ON CONFLICT ON CONSTRAINT uq_dentry_dtab_prefix DO UPDATE SET update_date=timezone('UTC'::text, now()), dtab=excluded.dtab, prefix=excluded.prefix, destination=excluded.destination, priority=excluded.priority RETURNING *;`, DentryTableName)
Service upsert query
var UpsertServiceQry = fmt.Sprintf(` INSERT INTO "%s" ( "logical_name", "namespace", "description") VALUES ($1,$2,$3) ON CONFLICT ON CONSTRAINT uq_service_logical_name DO UPDATE SET update_date=timezone('UTC'::text, now()), namespace=excluded.namespace, description=excluded.description RETURNING *;`, ServiceTableName)
Service upsert query
Functions ¶
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetInfo ¶
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func NewMigrator ¶
func NewMigrator(dsn DSN, opts ...MigrateOption) (*migrate.Migrate, error)
Migrate runs database migrat
func NewMigratorFromDB ¶
func QueryRowx ¶
func QueryRowx(db sqlx.Queryer, handler RowHandler, qry string, args ...interface{}) error
QueryRowx wraps sqlx.QueryRowx, executing the query and passing the resulting row to a RowHandler
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively
Types ¶
type DentryStore ¶
type DentryStore struct {
// contains filtered or unexported fields
}
DentryStore manages dentry CRUD ops
func NewDentryStore ¶
func NewDentryStore(db *sqlx.DB) *DentryStore
NewDentryStore returns a new DentryStore
func (*DentryStore) DelegationTables ¶
func (store *DentryStore) DelegationTables() ([]string, error)
DelegationTables returns a list of distinct delgation tables
func (*DentryStore) DeleteDentryById ¶
func (store *DentryStore) DeleteDentryById(id uuid.UUID) (int64, error)
DeleteDentryById deletes a dentry by it's UUID
func (*DentryStore) DeleteDentryByPrefix ¶
func (store *DentryStore) DeleteDentryByPrefix(dtab, prefix string) (int64, error)
DeleteDentryByPrefix deletes a dentry by it's prefix in a specified dtab
func (*DentryStore) DentriesByDtab ¶
func (store *DentryStore) DentriesByDtab(ctx context.Context, dtab string) (<-chan *store.Dentry, error)
DentriesByDtab returns a slice of Dentry for the Delegation table
func (*DentryStore) DtabUpdates ¶
func (store *DentryStore) DtabUpdates() <-chan namerd.Dtab
TODO: could be a subscription style model
type MigrateLogger ¶
migrateLogger is used to log database migrations
func (*MigrateLogger) Printf ¶
func (l *MigrateLogger) Printf(format string, v ...interface{})
Printf passes the log message and arguments to our logger
func (*MigrateLogger) Verbose ¶
func (l *MigrateLogger) Verbose() bool
Verbose returns true so we can log what the migrator is doing
type MigrateOption ¶
func MigrateWithLog ¶
func MigrateWithLog(log migrate.Logger) MigrateOption
type RowHandler ¶
A RowHandler handles struct scanning a sqlx.Row into a destination inerface
type RowHandlerFunc ¶
The RowHandlerFunc type is an adapter to allow the use of ordinary functions as row handlers
type ServiceStore ¶
type ServiceStore struct {
// contains filtered or unexported fields
}
ServiceStore handles CRUD opperations for services in psql
func NewServiceStore ¶
func NewServiceStore(db *sqlx.DB) *ServiceStore
NewServiceStore returns a new ServiceStore
func (*ServiceStore) GetByLogicalName ¶
func (store *ServiceStore) GetByLogicalName(ln string) (*store.Service, error)
GetByLogicalName returns a service by its unique logical name
func (*ServiceStore) PutService ¶
PutService implements the store.ServicePutter and executes an Upsert query to create or update a service
type Store ¶
type Store struct { *ServiceStore *DentryStore }
Store embeds the various other stores for a single store interface