split main

This commit is contained in:
Umputun
2018-03-04 02:37:39 -06:00
parent 695afad55b
commit 3278a687c1
2 changed files with 17 additions and 11 deletions
+16 -10
View File
@@ -89,16 +89,21 @@ func main() {
return
}
if opts.DevPasswd != "" {
log.Printf("[WARN] running in dev mode")
}
dataService := store.Service{Interface: dataStore, EditDuration: 5 * time.Minute}
sessionStore := func() sessions.Store {
sess := sessions.NewFilesystemStore(opts.ServerCommand.SessionStore, []byte(opts.ServerCommand.StoreKey))
sess.Options.HttpOnly = true
sess.Options.Secure = true
sess.Options.MaxAge = 3600 * 24 * 365
sess.Options.Path = "/"
return sess
}()
exporter := migrator.Remark{DataStore: dataStore}
exporter := &migrator.Remark{DataStore: dataStore}
avatarProxy := &auth.AvatarProxy{
StorePath: opts.ServerCommand.AvatarStore,
@@ -107,10 +112,12 @@ func main() {
DefaultAvatar: opts.ServerCommand.DefaultAvatar,
}
activateBackup(exporter)
srv := api.Rest{
Version: revision,
DataService: dataService,
Exporter: &exporter,
Exporter: exporter,
Authenticator: auth.Authenticator{
Admins: opts.Admins,
SessionStore: sessionStore,
@@ -122,22 +129,21 @@ func main() {
Cache: rest.NewLoadingCache(4*time.Hour, 15*time.Minute, postFlushFn),
Notifier: notifier.NewNoOperation(),
}
srv.Run(opts.ServerCommand.Port)
}
if opts.DevPasswd != "" {
log.Printf("[WARN] running in dev mode")
}
// activateBackup runs background backups for each site
func activateBackup(exporter migrator.Exporter) {
for _, siteID := range opts.Sites {
go migrator.AutoBackup{
backup := migrator.AutoBackup{
Exporter: &exporter,
BackupLocation: opts.BackupLocation,
SiteID: siteID,
KeepMax: opts.MaxBackupFiles,
Duration: 24 * time.Hour,
}.Do()
}
go backup.Do()
}
srv.Run(opts.ServerCommand.Port)
}
// makeBoltStore creates store for all sites
+1 -1
View File
@@ -521,7 +521,7 @@ func (b *BoltDB) load(bkt *bolt.Bucket, key []byte) (comment Comment, err error)
return comment, nil
}
// count adds val to counts key postURL. val can be negative to substruct. if val 0 can be used as accessor
// count adds val to counts key postURL. val can be negative to subtract. if val 0 can be used as accessor
// it uses separate counts bucket because boltdb Stat call is very slow
func (b *BoltDB) count(tx *bolt.Tx, postURL string, val int) (int, error) {