add targets to init
This commit is contained in:
parent
335eaf02d4
commit
46d210ad26
6
audit.go
6
audit.go
|
@ -17,6 +17,8 @@ type MongoDBConfig struct {
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// Source of server, e.g: selly
|
// Source of server, e.g: selly
|
||||||
Source string
|
Source string
|
||||||
|
// Targets: staff, article, ...
|
||||||
|
Targets []string
|
||||||
// MongoDB config, for save documents
|
// MongoDB config, for save documents
|
||||||
MongoDB MongoDBConfig
|
MongoDB MongoDBConfig
|
||||||
}
|
}
|
||||||
|
@ -31,8 +33,8 @@ var s *Service
|
||||||
|
|
||||||
// NewInstance ...
|
// NewInstance ...
|
||||||
func NewInstance(config Config) error {
|
func NewInstance(config Config) error {
|
||||||
if config.Source == "" || config.MongoDB.Host == "" {
|
if config.Source == "" || len(config.Targets) == 0 || config.MongoDB.Host == "" {
|
||||||
return errors.New("please provide all necessary information: source, mongodb")
|
return errors.New("please provide all necessary information: source, targets, mongodb")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect MongoDB
|
// Connect MongoDB
|
||||||
|
|
12
constant.go
12
constant.go
|
@ -10,15 +10,3 @@ const (
|
||||||
ActionUpdate = "update"
|
ActionUpdate = "update"
|
||||||
ActionUpdatePermissions = "update-permissions"
|
ActionUpdatePermissions = "update-permissions"
|
||||||
)
|
)
|
||||||
|
|
||||||
// List targets
|
|
||||||
const (
|
|
||||||
TargetSellyStaff = "staffs"
|
|
||||||
TargetSellyStaffRole = "staff-roles"
|
|
||||||
)
|
|
||||||
|
|
||||||
// SellyTargets ...
|
|
||||||
var SellyTargets = []string{
|
|
||||||
TargetSellyStaff,
|
|
||||||
TargetSellyStaffRole,
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,17 +5,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s Service) indexDB() {
|
func (s Service) indexDB() {
|
||||||
// Get list targets
|
|
||||||
var targets = make([]string, 0)
|
|
||||||
if s.Source == SourceSelly {
|
|
||||||
targets = SellyTargets
|
|
||||||
}
|
|
||||||
|
|
||||||
// Index key
|
// Index key
|
||||||
commonIndex := mongodb.NewIndexKey("source", "target", "targetId")
|
commonIndex := mongodb.NewIndexKey("source", "target", "targetId")
|
||||||
|
|
||||||
// Index all allowed sources
|
// Index all allowed sources
|
||||||
for _, target := range targets {
|
for _, target := range s.Targets {
|
||||||
mongodb.CreateIndex(getColName(target), commonIndex)
|
mongodb.CreateIndex(getColName(target), commonIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue