Documentation
¶
Index ¶
- Constants
- Variables
- func CreateHandler(svc ObjectTypeService, w http.ResponseWriter, r *http.Request) error
- func DeleteHandler(svc ObjectTypeService, w http.ResponseWriter, r *http.Request) error
- func GetHandler(svc ObjectTypeService, w http.ResponseWriter, r *http.Request) error
- func ListHandler(svc ObjectTypeService, w http.ResponseWriter, r *http.Request) error
- func UpdateHandler(svc ObjectTypeService, w http.ResponseWriter, r *http.Request) error
- type ForeignKeySpec
- type Model
- type MySQLRepository
- func (repo MySQLRepository) Create(ctx context.Context, model Model) (int64, error)
- func (repo MySQLRepository) DeleteByTypeId(ctx context.Context, typeId string) error
- func (repo MySQLRepository) GetById(ctx context.Context, id int64) (Model, error)
- func (repo MySQLRepository) GetByTypeId(ctx context.Context, typeId string) (Model, error)
- func (repo MySQLRepository) List(ctx context.Context, listParams service.ListParams) ([]Model, error)
- func (repo MySQLRepository) UpdateByTypeId(ctx context.Context, typeId string, model Model) error
- type ObjectType
- func (objectType ObjectType) GetCreatedAt() time.Time
- func (objectType ObjectType) GetDefinition() string
- func (objectType ObjectType) GetDeletedAt() *time.Time
- func (objectType ObjectType) GetID() int64
- func (objectType ObjectType) GetTypeId() string
- func (objectType ObjectType) GetUpdatedAt() time.Time
- func (objectType *ObjectType) SetDefinition(newDefinition string)
- func (objectType ObjectType) ToObjectTypeSpec() (*ObjectTypeSpec, error)
- type ObjectTypeListParamParser
- type ObjectTypeRepository
- type ObjectTypeService
- func (svc ObjectTypeService) Create(ctx context.Context, objectTypeSpec ObjectTypeSpec) (*ObjectTypeSpec, error)
- func (svc ObjectTypeService) DeleteByTypeId(ctx context.Context, typeId string) error
- func (svc ObjectTypeService) GetByTypeId(ctx context.Context, typeId string) (*ObjectTypeSpec, error)
- func (svc ObjectTypeService) List(ctx context.Context, listParams service.ListParams) ([]ObjectTypeSpec, error)
- func (svc ObjectTypeService) Routes() ([]service.Route, error)
- func (svc ObjectTypeService) UpdateByTypeId(ctx context.Context, typeId string, objectTypeSpec ObjectTypeSpec) (*ObjectTypeSpec, error)
- type ObjectTypeSpec
- type PostgresRepository
- func (repo PostgresRepository) Create(ctx context.Context, model Model) (int64, error)
- func (repo PostgresRepository) DeleteByTypeId(ctx context.Context, typeId string) error
- func (repo PostgresRepository) GetById(ctx context.Context, id int64) (Model, error)
- func (repo PostgresRepository) GetByTypeId(ctx context.Context, typeId string) (Model, error)
- func (repo PostgresRepository) List(ctx context.Context, listParams service.ListParams) ([]Model, error)
- func (repo PostgresRepository) UpdateByTypeId(ctx context.Context, typeId string, model Model) error
- type RelationRule
- type SQLiteRepository
- func (repo SQLiteRepository) Create(ctx context.Context, model Model) (int64, error)
- func (repo SQLiteRepository) DeleteByTypeId(ctx context.Context, typeId string) error
- func (repo SQLiteRepository) GetById(ctx context.Context, id int64) (Model, error)
- func (repo SQLiteRepository) GetByTypeId(ctx context.Context, typeId string) (Model, error)
- func (repo SQLiteRepository) List(ctx context.Context, listParams service.ListParams) ([]Model, error)
- func (repo SQLiteRepository) UpdateByTypeId(ctx context.Context, typeId string, model Model) error
- type Source
Constants ¶
View Source
const ( ObjectTypeFeature = "feature" ObjectTypePermission = "permission" ObjectTypePricingTier = "pricing-tier" ObjectTypeRole = "role" ObjectTypeTenant = "tenant" ObjectTypeUser = "user" RelationAdmin = "admin" RelationManager = "manager" RelationMember = "member" RelationParent = "parent" RelationOwner = "owner" RelationEditor = "editor" RelationViewer = "viewer" InheritIfAllOf = "allOf" InheritIfAnyOf = "anyOf" InheritIfNoneOf = "noneOf" )
View Source
const DefaultSortBy = "objectType"
View Source
const DefaultSortByColumn = "typeId"
View Source
const ResourceTypeObjectType = "object-type"
Variables ¶
View Source
var FeatureObjectTypeSpec = ObjectTypeSpec{ Type: ObjectTypeFeature, Relations: map[string]RelationRule{ RelationMember: { InheritIf: InheritIfAnyOf, Rules: []RelationRule{ { InheritIf: RelationMember, OfType: ObjectTypeFeature, WithRelation: RelationMember, }, { InheritIf: RelationMember, OfType: ObjectTypePricingTier, WithRelation: RelationMember, }, }, }, }, }
View Source
var PermissionObjectTypeSpec = ObjectTypeSpec{ Type: ObjectTypePermission, Relations: map[string]RelationRule{ RelationOwner: {}, RelationEditor: { InheritIf: RelationOwner, }, RelationViewer: { InheritIf: RelationEditor, }, RelationMember: { InheritIf: InheritIfAnyOf, Rules: []RelationRule{ { InheritIf: RelationMember, OfType: ObjectTypePermission, WithRelation: RelationMember, }, { InheritIf: RelationMember, OfType: ObjectTypeRole, WithRelation: RelationMember, }, }, }, }, }
View Source
var PricingTierObjectTypeSpec = ObjectTypeSpec{ Type: ObjectTypePricingTier, Relations: map[string]RelationRule{ RelationMember: { InheritIf: RelationMember, OfType: ObjectTypePricingTier, WithRelation: RelationMember, }, }, }
View Source
var RoleObjectTypeSpec = ObjectTypeSpec{ Type: ObjectTypeRole, Relations: map[string]RelationRule{ RelationOwner: {}, RelationEditor: { InheritIf: RelationOwner, }, RelationViewer: { InheritIf: RelationEditor, }, RelationMember: { InheritIf: RelationMember, OfType: ObjectTypeRole, WithRelation: RelationMember, }, }, }
View Source
var TenantObjectTypeSpec = ObjectTypeSpec{ Type: ObjectTypeTenant, Relations: map[string]RelationRule{ RelationAdmin: {}, RelationManager: { InheritIf: RelationAdmin, }, RelationMember: { InheritIf: RelationManager, }, }, }
View Source
var UserObjectTypeSpec = ObjectTypeSpec{ Type: ObjectTypeUser, Relations: map[string]RelationRule{ RelationParent: { InheritIf: RelationParent, OfType: ObjectTypeUser, WithRelation: RelationParent, }, }, }
Functions ¶
func CreateHandler ¶ added in v0.11.0
func CreateHandler(svc ObjectTypeService, w http.ResponseWriter, r *http.Request) error
func DeleteHandler ¶ added in v0.11.0
func DeleteHandler(svc ObjectTypeService, w http.ResponseWriter, r *http.Request) error
func GetHandler ¶ added in v0.11.0
func GetHandler(svc ObjectTypeService, w http.ResponseWriter, r *http.Request) error
func ListHandler ¶ added in v0.11.0
func ListHandler(svc ObjectTypeService, w http.ResponseWriter, r *http.Request) error
func UpdateHandler ¶ added in v0.11.0
func UpdateHandler(svc ObjectTypeService, w http.ResponseWriter, r *http.Request) error
Types ¶
type ForeignKeySpec ¶
type MySQLRepository ¶
type MySQLRepository struct {
database.SQLRepository
}
func NewMySQLRepository ¶
func NewMySQLRepository(db *database.MySQL) MySQLRepository
func (MySQLRepository) DeleteByTypeId ¶
func (repo MySQLRepository) DeleteByTypeId(ctx context.Context, typeId string) error
func (MySQLRepository) GetByTypeId ¶
func (MySQLRepository) List ¶
func (repo MySQLRepository) List(ctx context.Context, listParams service.ListParams) ([]Model, error)
func (MySQLRepository) UpdateByTypeId ¶
type ObjectType ¶
type ObjectType struct {
ID int64 `mysql:"id" postgres:"id" sqlite:"id"`
TypeId string `mysql:"typeId" postgres:"type_id" sqlite:"typeId"`
Definition string `mysql:"definition" postgres:"definition" sqlite:"definition"`
CreatedAt time.Time `mysql:"createdAt" postgres:"created_at" sqlite:"createdAt"`
UpdatedAt time.Time `mysql:"updatedAt" postgres:"updated_at" sqlite:"updatedAt"`
DeletedAt *time.Time `mysql:"deletedAt" postgres:"deleted_at" sqlite:"deletedAt"`
}
func (ObjectType) GetCreatedAt ¶ added in v0.8.0
func (objectType ObjectType) GetCreatedAt() time.Time
func (ObjectType) GetDefinition ¶ added in v0.8.0
func (objectType ObjectType) GetDefinition() string
func (ObjectType) GetDeletedAt ¶ added in v0.8.0
func (objectType ObjectType) GetDeletedAt() *time.Time
func (ObjectType) GetID ¶ added in v0.8.0
func (objectType ObjectType) GetID() int64
func (ObjectType) GetTypeId ¶ added in v0.8.0
func (objectType ObjectType) GetTypeId() string
func (ObjectType) GetUpdatedAt ¶ added in v0.8.0
func (objectType ObjectType) GetUpdatedAt() time.Time
func (*ObjectType) SetDefinition ¶ added in v0.8.0
func (objectType *ObjectType) SetDefinition(newDefinition string)
func (ObjectType) ToObjectTypeSpec ¶
func (objectType ObjectType) ToObjectTypeSpec() (*ObjectTypeSpec, error)
type ObjectTypeListParamParser ¶
type ObjectTypeListParamParser struct{}
func (ObjectTypeListParamParser) GetDefaultSortBy ¶
func (parser ObjectTypeListParamParser) GetDefaultSortBy() string
func (ObjectTypeListParamParser) GetSupportedSortBys ¶
func (parser ObjectTypeListParamParser) GetSupportedSortBys() []string
func (ObjectTypeListParamParser) ParseValue ¶
func (parser ObjectTypeListParamParser) ParseValue(val string, sortBy string) (interface{}, error)
type ObjectTypeRepository ¶
type ObjectTypeRepository interface {
Create(ctx context.Context, objectType Model) (int64, error)
GetById(ctx context.Context, id int64) (Model, error)
GetByTypeId(ctx context.Context, typeId string) (Model, error)
List(ctx context.Context, listParams service.ListParams) ([]Model, error)
UpdateByTypeId(ctx context.Context, typeId string, objectType Model) error
DeleteByTypeId(ctx context.Context, typeId string) error
}
func NewRepository ¶
func NewRepository(db database.Database) (ObjectTypeRepository, error)
type ObjectTypeService ¶
type ObjectTypeService struct {
service.BaseService
Repository ObjectTypeRepository
EventSvc event.EventService
}
func NewService ¶
func NewService(env service.Env, repository ObjectTypeRepository, eventSvc event.EventService) ObjectTypeService
func (ObjectTypeService) Create ¶
func (svc ObjectTypeService) Create(ctx context.Context, objectTypeSpec ObjectTypeSpec) (*ObjectTypeSpec, error)
func (ObjectTypeService) DeleteByTypeId ¶
func (svc ObjectTypeService) DeleteByTypeId(ctx context.Context, typeId string) error
func (ObjectTypeService) GetByTypeId ¶
func (svc ObjectTypeService) GetByTypeId(ctx context.Context, typeId string) (*ObjectTypeSpec, error)
func (ObjectTypeService) List ¶
func (svc ObjectTypeService) List(ctx context.Context, listParams service.ListParams) ([]ObjectTypeSpec, error)
func (ObjectTypeService) Routes ¶ added in v0.8.0
func (svc ObjectTypeService) Routes() ([]service.Route, error)
GetRoutes registers all route handlers for this module
func (ObjectTypeService) UpdateByTypeId ¶
func (svc ObjectTypeService) UpdateByTypeId(ctx context.Context, typeId string, objectTypeSpec ObjectTypeSpec) (*ObjectTypeSpec, error)
type ObjectTypeSpec ¶
type ObjectTypeSpec struct {
Type string `json:"type" validate:"required,valid_object_type"`
Source *Source `json:"source,omitempty"`
Relations map[string]RelationRule `json:"relations" validate:"required,min=1,dive"` // NOTE: map key = name of relation
}
func (ObjectTypeSpec) ToObjectType ¶
func (spec ObjectTypeSpec) ToObjectType() (*ObjectType, error)
type PostgresRepository ¶ added in v0.4.0
type PostgresRepository struct {
database.SQLRepository
}
func NewPostgresRepository ¶ added in v0.4.0
func NewPostgresRepository(db *database.Postgres) PostgresRepository
func (PostgresRepository) DeleteByTypeId ¶ added in v0.4.0
func (repo PostgresRepository) DeleteByTypeId(ctx context.Context, typeId string) error
func (PostgresRepository) GetByTypeId ¶ added in v0.4.0
func (PostgresRepository) List ¶ added in v0.4.0
func (repo PostgresRepository) List(ctx context.Context, listParams service.ListParams) ([]Model, error)
func (PostgresRepository) UpdateByTypeId ¶ added in v0.4.0
type RelationRule ¶
type RelationRule struct {
InheritIf string `json:"inheritIf,omitempty" validate:"required_with=Rules OfType WithRelation,valid_inheritif"`
Rules []RelationRule `json:"rules,omitempty" validate:"required_if_oneof=InheritIf anyOf allOf noneOf,omitempty,min=1,dive"` // Required if InheritIf is "anyOf", "allOf", or "noneOf", empty otherwise
OfType string `json:"ofType,omitempty" validate:"required_with=WithRelation,valid_relation"`
WithRelation string `json:"withRelation,omitempty" validate:"required_with=OfType,valid_relation"`
}
RelationRule type represents the rule or set of rules that imply a particular relation if met
type SQLiteRepository ¶ added in v0.11.0
type SQLiteRepository struct {
database.SQLRepository
}
func NewSQLiteRepository ¶ added in v0.11.0
func NewSQLiteRepository(db *database.SQLite) SQLiteRepository
func (SQLiteRepository) DeleteByTypeId ¶ added in v0.11.0
func (repo SQLiteRepository) DeleteByTypeId(ctx context.Context, typeId string) error
func (SQLiteRepository) GetByTypeId ¶ added in v0.11.0
func (SQLiteRepository) List ¶ added in v0.11.0
func (repo SQLiteRepository) List(ctx context.Context, listParams service.ListParams) ([]Model, error)
func (SQLiteRepository) UpdateByTypeId ¶ added in v0.11.0
type Source ¶
type Source struct {
DatabaseType string `json:"dbType" validate:"required"`
DatabaseName string `json:"dbName" validate:"required"`
Table string `json:"table" validate:"required"`
PrimaryKey []string `json:"primaryKey" validate:"min=1"`
ForeignKeys []ForeignKeySpec `json:"foreignKeys,omitempty"`
}
Click to show internal directories.
Click to hide internal directories.