Files
threshold/internal/host/static/repository.go
T
Michael Gaffney 7ac4be51c0 Refactor static host package (#263)
* Refactor: inline tablename constants

* Refactor: move functionality to new files
2020-08-13 14:00:15 -04:00

38 lines
963 B
Go

package static
import (
"fmt"
wrapping "github.com/hashicorp/go-kms-wrapping"
"github.com/hashicorp/boundary/internal/db"
)
// A Repository stores and retrieves the persistent types in the static
// package. It is not safe to use a repository concurrently.
type Repository struct {
reader db.Reader
writer db.Writer
wrapper wrapping.Wrapper
}
// NewRepository creates a new Repository. The returned repository should
// only be used for one transaction and it is not safe for concurrent go
// routines to access it.
func NewRepository(r db.Reader, w db.Writer, wrapper wrapping.Wrapper) (*Repository, error) {
switch {
case r == nil:
return nil, fmt.Errorf("db.Reader: %w", db.ErrNilParameter)
case w == nil:
return nil, fmt.Errorf("db.Writer: %w", db.ErrNilParameter)
case wrapper == nil:
return nil, fmt.Errorf("wrapping.Wrapper: %w", db.ErrNilParameter)
}
return &Repository{
reader: r,
writer: w,
wrapper: wrapper,
}, nil
}