-
-
Notifications
You must be signed in to change notification settings - Fork 201
/
config.go
80 lines (70 loc) · 1.9 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
/*
Nging is a toolbox for webmasters
Copyright (C) 2018-present Wenhui Shen <swh@admpub.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package seaweedfs
import (
"time"
"github.com/admpub/goseaweedfs"
"github.com/webx-top/com"
)
var (
DefaultConfig = &Config{}
DefaultClient = com.HTTPClientWithTimeout(10 * time.Second)
)
type FilerURL struct {
Public string //Readonly URL
Private string //Manage URL
}
type Config struct {
Scheme string
Master string
Filers []*FilerURL
ChunkSize int64
Timeout time.Duration
// TTL Time to live.
// 3m: 3 minutes
// 4h: 4 hours
// 5d: 5 days
// 6w: 6 weeks
// 7M: 7 months
// 8y: 8 years
TTL string
}
func (c *Config) New() (*goseaweedfs.Seaweed, error) {
if len(c.Scheme) == 0 {
c.Scheme = "http"
}
if c.ChunkSize <= 0 {
c.ChunkSize = 2 * 1024 * 1024
}
if c.Timeout <= 0 {
c.Timeout = 5 * time.Minute
}
if len(c.Master) == 0 {
c.Master = `localhost:9333`
}
if c.Filers == nil || len(c.Filers) == 0 {
c.Filers = []*FilerURL{
{
Public: `http://localhost:8989`,
Private: `http://localhost:8888`,
},
}
}
filers := make([]string, len(c.Filers))
for index, filerURL := range c.Filers {
filers[index] = filerURL.Private
}
return goseaweedfs.NewSeaweed(c.Master, filers, c.ChunkSize, DefaultClient)
}