-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
54 lines (46 loc) · 1.44 KB
/
options.go
File metadata and controls
54 lines (46 loc) · 1.44 KB
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
package runtime
import (
"time"
"google.golang.org/protobuf/types/known/timestamppb"
)
// Option is a functional option for configuring the App.
// It allows for applying configurations to the App instance at creation time.
type Option func(*App)
// WithEnv sets the environment for the application.
func WithEnv(env string) Option {
return func(a *App) {
// This option will be applied after the appInfo is initialized.
a.appInfo.Env = env
}
}
// WithID sets a custom instance ID.
func WithID(id string) Option {
return func(a *App) {
// This option will be applied after the appInfo is initialized.
a.appInfo.Id = id
}
}
// WithStartTime sets a custom start time.
func WithStartTime(startTime time.Time) Option {
return func(a *App) {
// This option will be applied after the appInfo is initialized.
a.appInfo.StartTime = timestamppb.New(startTime)
}
}
// WithMetadata adds a key-value pair to the application's metadata.
func WithMetadata(key, value string) Option {
return func(a *App) {
// This option will be applied after the appInfo is initialized.
if a.appInfo.Metadata == nil {
a.appInfo.Metadata = make(map[string]string)
}
a.appInfo.Metadata[key] = value
}
}
// WithMetadataMap adds a map of key-value pairs to the application's metadata.
func WithMetadataMap(metadata map[string]string) Option {
return func(a *App) {
// This option will be applied after the appInfo is initialized.
a.appInfo.Metadata = metadata
}
}