forked from uhthomas/kipp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
option.go
68 lines (58 loc) · 1.27 KB
/
option.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
package kipp
import (
"context"
"time"
"github.com/uhthomas/kipp/database"
"github.com/uhthomas/kipp/filesystem"
"github.com/uhthomas/kipp/internal/databaseutil"
"github.com/uhthomas/kipp/internal/filesystemutil"
)
type Option func(ctx context.Context, s *Server) error
func DB(db database.Database) Option {
return func(ctx context.Context, s *Server) error {
s.Database = db
return nil
}
}
func ParseDB(ss string) Option {
return func(ctx context.Context, s *Server) error {
db, err := databaseutil.Parse(ctx, ss)
if err != nil {
return err
}
return DB(db)(ctx, s)
}
}
func FS(fs filesystem.FileSystem) Option {
return func(ctx context.Context, s *Server) error {
s.FileSystem = fs
return nil
}
}
func ParseFS(ss string) Option {
return func(ctx context.Context, s *Server) error {
fs, err := filesystemutil.Parse(ss)
if err != nil {
return err
}
return FS(fs)(ctx, s)
}
}
func Lifetime(d time.Duration) Option {
return func(ctx context.Context, s *Server) error {
s.Lifetime = d
return nil
}
}
func Limit(n int64) Option {
return func(ctx context.Context, s *Server) error {
s.Limit = n
return nil
}
}
func Data(path string) Option {
return func(ctx context.Context, s *Server) error {
s.PublicPath = path
return nil
}
}