github.com/adacta-ru/mattermost-server@v5.11.1+incompatible/app/options.go (about) 1 // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package app 5 6 import ( 7 "github.com/mattermost/mattermost-server/mlog" 8 "github.com/pkg/errors" 9 10 "github.com/mattermost/mattermost-server/config" 11 "github.com/mattermost/mattermost-server/store" 12 ) 13 14 type Option func(s *Server) error 15 16 // By default, the app will use the store specified by the configuration. This allows you to 17 // construct an app with a different store. 18 // 19 // The override parameter must be either a store.Store or func(App) store.Store. 20 func StoreOverride(override interface{}) Option { 21 return func(s *Server) error { 22 switch o := override.(type) { 23 case store.Store: 24 s.newStore = func() store.Store { 25 return o 26 } 27 return nil 28 29 case func(*Server) store.Store: 30 s.newStore = func() store.Store { 31 return o(s) 32 } 33 return nil 34 35 default: 36 return errors.New("invalid StoreOverride") 37 } 38 } 39 } 40 41 // Config applies the given config dsn, whether a path to config.json or a database connection string. 42 func Config(dsn string, watch bool) Option { 43 return func(s *Server) error { 44 configStore, err := config.NewStore(dsn, watch) 45 if err != nil { 46 return errors.Wrap(err, "failed to apply Config option") 47 } 48 49 s.configStore = configStore 50 return nil 51 } 52 } 53 54 // ConfigStore applies the given config store, typically to replace the traditional sources with a memory store for testing. 55 func ConfigStore(configStore config.Store) Option { 56 return func(s *Server) error { 57 s.configStore = configStore 58 59 return nil 60 } 61 } 62 63 func RunJobs(s *Server) error { 64 s.runjobs = true 65 66 return nil 67 } 68 69 func JoinCluster(s *Server) error { 70 s.joinCluster = true 71 72 return nil 73 } 74 75 func StartMetrics(s *Server) error { 76 s.startMetrics = true 77 78 return nil 79 } 80 81 func StartElasticsearch(s *Server) error { 82 s.startElasticsearch = true 83 84 return nil 85 } 86 87 func SetLogger(logger *mlog.Logger) Option { 88 return func(s *Server) error { 89 s.Log = logger 90 return nil 91 } 92 } 93 94 type AppOption func(a *App) 95 type AppOptionCreator func() []AppOption 96 97 func ServerConnector(s *Server) AppOption { 98 return func(a *App) { 99 a.Srv = s 100 101 a.Log = s.Log 102 103 a.AccountMigration = s.AccountMigration 104 a.Cluster = s.Cluster 105 a.Compliance = s.Compliance 106 a.DataRetention = s.DataRetention 107 a.Elasticsearch = s.Elasticsearch 108 a.Ldap = s.Ldap 109 a.MessageExport = s.MessageExport 110 a.Metrics = s.Metrics 111 a.Saml = s.Saml 112 113 a.HTTPService = s.HTTPService 114 a.ImageProxy = s.ImageProxy 115 a.Timezones = s.timezones 116 } 117 }