Files
mattermost/app/options.go
Jesús Espino f5eab1271b Removing all FakeApp usages (#14174)
* Removing some other fake apps

* More FakeApp removed

* Removing entirely FakeApp

* Fixing some tests

* Fixing get Cluster id from get plugin status

* Fixing failing tests

* Fixing tests

* Fixing test initialization for web

* Fixing InitServer for server tests

* Fixing InitServer for server tests

* Reverting go.sum and go.mod

* Removing unneded HTMLTemplates function in App layer

* Moving back some functions to its old place to easy the review

* Moving back some functions to its old place to easy the review

* Using the last struct2interface version

* Generating store layers

* Fixing merge problems

* Addressing PR comments

* Small fix

* Fixing app tests build

* Fixing tests

* fixing tests

* Fix tests

* Fixing tests

* Fixing tests

* Fixing tests

* Moving license to server struct

* Adding some fixes to the test compilation

* Fixing cluster and some jobs initialization

* Fixing some license tests compilation problems

* Fixing recursive cache invalidation

* Regenerating app layers

* Fix test compilation

Co-authored-by: mattermod <mattermod@users.noreply.github.com>
2020-06-12 13:43:50 +02:00

116 lines
2.5 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package app
import (
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/pkg/errors"
"github.com/mattermost/mattermost-server/v5/config"
"github.com/mattermost/mattermost-server/v5/store"
)
type Option func(s *Server) error
// By default, the app will use the store specified by the configuration. This allows you to
// construct an app with a different store.
//
// The override parameter must be either a store.Store or func(App) store.Store().
func StoreOverride(override interface{}) Option {
return func(s *Server) error {
switch o := override.(type) {
case store.Store:
s.newStore = func() store.Store {
return o
}
return nil
case func(*Server) store.Store:
s.newStore = func() store.Store {
return o(s)
}
return nil
default:
return errors.New("invalid StoreOverride")
}
}
}
// Config applies the given config dsn, whether a path to config.json or a database connection string.
func Config(dsn string, watch bool) Option {
return func(s *Server) error {
configStore, err := config.NewStore(dsn, watch)
if err != nil {
return errors.Wrap(err, "failed to apply Config option")
}
s.configStore = configStore
return nil
}
}
// ConfigStore applies the given config store, typically to replace the traditional sources with a memory store for testing.
func ConfigStore(configStore config.Store) Option {
return func(s *Server) error {
s.configStore = configStore
return nil
}
}
func RunJobs(s *Server) error {
s.runjobs = true
return nil
}
func JoinCluster(s *Server) error {
s.joinCluster = true
return nil
}
func StartMetrics(s *Server) error {
s.startMetrics = true
return nil
}
func StartSearchEngine(s *Server) error {
s.startSearchEngine = true
return nil
}
func SetLogger(logger *mlog.Logger) Option {
return func(s *Server) error {
s.Log = logger
return nil
}
}
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.notificationsLog = s.NotificationsLog
a.accountMigration = s.AccountMigration
a.cluster = s.Cluster
a.compliance = s.Compliance
a.dataRetention = s.DataRetention
a.searchEngine = s.SearchEngine
a.messageExport = s.MessageExport
a.metrics = s.Metrics
a.httpService = s.HTTPService
a.imageProxy = s.ImageProxy
a.timezones = s.timezones
}
}