2017-10-09 14:59:48 -07:00
|
|
|
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
|
|
|
|
package app
|
|
|
|
|
|
|
|
|
|
import (
|
2019-02-12 08:37:54 -05:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
|
2017-10-09 14:59:48 -07:00
|
|
|
"github.com/mattermost/mattermost-server/store"
|
|
|
|
|
)
|
|
|
|
|
|
2019-02-12 08:37:54 -05:00
|
|
|
type Option func(s *Server) error
|
2017-10-09 14:59:48 -07:00
|
|
|
|
|
|
|
|
// By default, the app will use the store specified by the configuration. This allows you to
|
|
|
|
|
// construct an app with a different store.
|
|
|
|
|
//
|
2017-10-16 08:09:43 -07:00
|
|
|
// The override parameter must be either a store.Store or func(App) store.Store.
|
|
|
|
|
func StoreOverride(override interface{}) Option {
|
2019-02-12 08:37:54 -05:00
|
|
|
return func(s *Server) error {
|
2017-10-16 08:09:43 -07:00
|
|
|
switch o := override.(type) {
|
2017-10-09 14:59:48 -07:00
|
|
|
case store.Store:
|
2018-11-28 10:56:21 -08:00
|
|
|
s.newStore = func() store.Store {
|
2017-10-16 08:09:43 -07:00
|
|
|
return o
|
2017-10-09 14:59:48 -07:00
|
|
|
}
|
2019-02-12 08:37:54 -05:00
|
|
|
return nil
|
|
|
|
|
|
2018-11-28 10:56:21 -08:00
|
|
|
case func(*Server) store.Store:
|
|
|
|
|
s.newStore = func() store.Store {
|
|
|
|
|
return o(s)
|
2017-10-12 12:24:54 -07:00
|
|
|
}
|
2019-02-12 08:37:54 -05:00
|
|
|
return nil
|
|
|
|
|
|
2017-10-09 14:59:48 -07:00
|
|
|
default:
|
2019-02-12 08:37:54 -05:00
|
|
|
return errors.New("invalid StoreOverride")
|
2017-10-09 14:59:48 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-16 08:40:26 -06:00
|
|
|
|
2019-02-12 08:37:54 -05:00
|
|
|
func ConfigFile(file string, watch bool) Option {
|
|
|
|
|
return func(s *Server) error {
|
2018-11-28 10:56:21 -08:00
|
|
|
s.configFile = file
|
2019-02-12 08:37:54 -05:00
|
|
|
s.disableConfigWatch = !watch
|
|
|
|
|
|
|
|
|
|
return nil
|
2017-11-16 08:40:26 -06:00
|
|
|
}
|
|
|
|
|
}
|
2018-01-11 15:23:41 -06:00
|
|
|
|
2019-02-12 08:37:54 -05:00
|
|
|
func RunJobs(s *Server) error {
|
2018-12-17 08:51:46 -08:00
|
|
|
s.runjobs = true
|
2019-02-12 08:37:54 -05:00
|
|
|
|
|
|
|
|
return nil
|
2018-12-17 08:51:46 -08:00
|
|
|
}
|
|
|
|
|
|
2019-02-12 08:37:54 -05:00
|
|
|
func JoinCluster(s *Server) error {
|
2019-01-15 09:09:25 -08:00
|
|
|
s.joinCluster = true
|
2019-02-12 08:37:54 -05:00
|
|
|
|
|
|
|
|
return nil
|
2019-01-15 09:09:25 -08:00
|
|
|
}
|
|
|
|
|
|
2019-02-12 08:37:54 -05:00
|
|
|
func StartMetrics(s *Server) error {
|
2019-01-15 09:09:25 -08:00
|
|
|
s.startMetrics = true
|
2019-02-12 08:37:54 -05:00
|
|
|
|
|
|
|
|
return nil
|
2019-01-15 09:09:25 -08:00
|
|
|
}
|
|
|
|
|
|
2019-02-12 08:37:54 -05:00
|
|
|
func StartElasticsearch(s *Server) error {
|
2019-01-15 09:09:25 -08:00
|
|
|
s.startElasticsearch = true
|
|
|
|
|
|
2019-02-12 08:37:54 -05:00
|
|
|
return nil
|
2018-11-28 10:56:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type AppOption func(a *App)
|
|
|
|
|
type AppOptionCreator func() []AppOption
|
|
|
|
|
|
|
|
|
|
func ServerConnector(s *Server) AppOption {
|
|
|
|
|
return func(a *App) {
|
|
|
|
|
a.Srv = s
|
|
|
|
|
|
|
|
|
|
a.Log = s.Log
|
|
|
|
|
|
|
|
|
|
a.AccountMigration = s.AccountMigration
|
|
|
|
|
a.Cluster = s.Cluster
|
|
|
|
|
a.Compliance = s.Compliance
|
|
|
|
|
a.DataRetention = s.DataRetention
|
|
|
|
|
a.Elasticsearch = s.Elasticsearch
|
|
|
|
|
a.Ldap = s.Ldap
|
|
|
|
|
a.MessageExport = s.MessageExport
|
|
|
|
|
a.Metrics = s.Metrics
|
|
|
|
|
a.Saml = s.Saml
|
2018-12-17 08:51:46 -08:00
|
|
|
|
|
|
|
|
a.HTTPService = s.HTTPService
|
2019-01-24 16:11:32 -04:00
|
|
|
a.ImageProxy = s.ImageProxy
|
2018-12-17 08:51:46 -08:00
|
|
|
a.Timezones = s.timezones
|
2018-11-28 10:56:21 -08:00
|
|
|
}
|
2018-01-11 15:23:41 -06:00
|
|
|
}
|