This repository has been archived by the owner on Jan 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig.go
96 lines (85 loc) · 2.1 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
// Copyright 2018 ekino. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package godim
import (
"log"
"reflect"
"strings"
)
// Config struct for Godim
type Config struct {
injectString string
configString string
appProfile *AppProfile
configFunction func(key string, val reflect.Value) (interface{}, error)
activateES bool
bufferSize int
eventSwitch *EventSwitch
}
// NewConfig declare a new config
func NewConfig() *Config {
return &Config{
injectString: defaultInject,
configString: defaultConfig,
activateES: false,
}
}
// DefaultConfig declare a default configuration
func DefaultConfig() *Config {
return &Config{
injectString: defaultInject,
configString: defaultConfig,
appProfile: newAppProfile(),
activateES: false,
}
}
// WithInjectString use a new inject string
func (c *Config) WithInjectString(inject string) *Config {
i := strings.TrimSpace(inject)
if len(i) > 0 {
c.injectString = i
} else {
log.Printf("Inject string %s ignored", inject)
}
return c
}
// WithConfigString use a new config string
func (c *Config) WithConfigString(config string) *Config {
i := strings.TrimSpace(config)
if len(i) > 0 {
c.configString = i
} else {
log.Printf("Config string %s ignored", config)
}
return c
}
// WithAppProfile declare the app profile to use
func (c *Config) WithAppProfile(ap *AppProfile) *Config {
if ap != nil {
c.appProfile = ap
}
return c
}
// WithConfigurationFunction declare your configuration function
func (c *Config) WithConfigurationFunction(f func(key string, val reflect.Value) (interface{}, error)) *Config {
c.configFunction = f
return c
}
// WithEventSwitch start an event switch with godim
func (c *Config) WithEventSwitch(bufferSize int) *Config {
c.activateES = true
c.bufferSize = bufferSize
return c
}
// Build lock profile and build godim
func (c *Config) Build() *Godim {
if c.appProfile == nil {
c.appProfile = newAppProfile()
}
c.appProfile.lock()
if c.activateES {
c.eventSwitch = NewEventSwitch(c.bufferSize)
}
return NewGodim(c)
}