-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
130 lines (111 loc) · 3.26 KB
/
config.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
118
119
120
121
122
123
124
125
126
127
128
129
130
package sparkle
import (
"fmt"
"github.com/octofoxio/foundation"
"github.com/octofoxio/sparkle/external/line"
sparklecrypto "github.com/octofoxio/sparkle/pkg/crypto"
"net/url"
)
var (
LocalMongoDBURL = "mongodb://root:root@localhost:6692" //,localhost:27018,localhost:27019/?replicaSet=rs
LocalDatastoreURL = ""
LocalHostURL = "http://localhost:3009" //http://35.198.223.236:3009
LocalSparkleServiceURL = "//localhost:3019" // //35.198.223.236:3019"
LocalSpikeServiceURL = "localhost:8901"
)
// Collection name
const (
UserCollectionName = "user"
IdentityCollectionName = "identity"
SessionCollectionName = "session"
)
type Config struct {
Database Database
EmailSender EmailSender
Fs foundation.FileSystem
DefaultEmailConfirmationTemplate string
Host *url.URL // hostname for views
Address *url.URL // GRPC address for binding service
DefaultEmailSenderAddress string
TokenSigner sparklecrypto.TokenSigner
UserCollectionName string
IdentityCollectionName string
SessionCollectionName string
LineClient line.LineClient
}
func NewConfig(system foundation.FileSystem) *Config {
b, err := system.GetObject("./default-email-template.hbs")
if err != nil {
fmt.Println("new config error!")
panic(err)
}
return &Config{
DefaultEmailConfirmationTemplate: string(b),
EmailSender: &ConsoleEmailSender{},
Fs: system,
DefaultEmailSenderAddress: "[email protected]",
IdentityCollectionName: IdentityCollectionName,
UserCollectionName: UserCollectionName,
SessionCollectionName: SessionCollectionName,
LineClient: line.NewDefaultLineClient(),
}
}
func (c *Config) UseJWTSignerWithHMAC256(secret string) *Config {
c.TokenSigner = sparklecrypto.NewJWT(secret)
return c
}
func (c *Config) SetTokenSigner(signer sparklecrypto.TokenSigner) *Config {
c.TokenSigner = signer
return c
}
func (c *Config) GetAddress() url.URL {
if c.Address == nil {
panic("config.Address is nil")
}
return *c.Address
}
// SetAddress set grpc service address
func (c *Config) SetAddress(value string) *Config {
host, err := url.Parse(value)
if err != nil {
panic(err)
}
c.Address = host
return c
}
func (c *Config) GetHost() url.URL {
return *c.Host
}
// SeteHost // set view host (confirm email page and etc.)
func (c *Config) SetHost(value string) *Config {
host, err := url.Parse(value)
if err != nil {
panic(err)
}
c.Host = host
return c
}
func (c *Config) UseLocalFileSystem(path string) *Config {
c.Fs = foundation.NewFileSystem(path, foundation.StaticMode_LOCAL)
return c
}
func (c *Config) UseStatikFileSystem() *Config {
c.Fs = foundation.NewFileSystem("", foundation.StaticMode_Statik)
return c
}
func (c *Config) SetDatabase(value Database) *Config {
c.Database = value
return c
}
func (c *Config) SetDefaultEmailTemplate(value string) *Config {
c.DefaultEmailConfirmationTemplate = value
return c
}
func (c *Config) SetDefaultEmailSenderAddress(value string) *Config {
c.DefaultEmailSenderAddress = value
return c
}
func (c *Config) SetEmailSender(sender EmailSender) *Config {
c.EmailSender = sender
return c
}