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 {
|
||||
// Source of server, e.g: selly
|
||||
Source string
|
||||
// Targets: staff, article, ...
|
||||
Targets []string
|
||||
// MongoDB config, for save documents
|
||||
MongoDB MongoDBConfig
|
||||
}
|
||||
|
@ -31,8 +33,8 @@ var s *Service
|
|||
|
||||
// NewInstance ...
|
||||
func NewInstance(config Config) error {
|
||||
if config.Source == "" || config.MongoDB.Host == "" {
|
||||
return errors.New("please provide all necessary information: source, mongodb")
|
||||
if config.Source == "" || len(config.Targets) == 0 || config.MongoDB.Host == "" {
|
||||
return errors.New("please provide all necessary information: source, targets, mongodb")
|
||||
}
|
||||
|
||||
// Connect MongoDB
|
||||
|
|
12
constant.go
12
constant.go
|
@ -10,15 +10,3 @@ const (
|
|||
ActionUpdate = "update"
|
||||
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() {
|
||||
// Get list targets
|
||||
var targets = make([]string, 0)
|
||||
if s.Source == SourceSelly {
|
||||
targets = SellyTargets
|
||||
}
|
||||
|
||||
// Index key
|
||||
commonIndex := mongodb.NewIndexKey("source", "target", "targetId")
|
||||
|
||||
// Index all allowed sources
|
||||
for _, target := range targets {
|
||||
for _, target := range s.Targets {
|
||||
mongodb.CreateIndex(getColName(target), commonIndex)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue