forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
117 lines (92 loc) · 2.45 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package app
import (
"github.com/mattermost/mattermost-server/mlog"
"github.com/pkg/errors"
"github.com/mattermost/mattermost-server/config"
"github.com/mattermost/mattermost-server/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 StartElasticsearch(s *Server) error {
s.startElasticsearch = 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.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
a.HTTPService = s.HTTPService
a.ImageProxy = s.ImageProxy
a.Timezones = s.timezones
}
}