-
Notifications
You must be signed in to change notification settings - Fork 1k
/
feature.go
55 lines (43 loc) · 1.64 KB
/
feature.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
// Copyright 2020 Lingfei Kong <colin404@foxmail.com>. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package options
import (
"github.com/spf13/pflag"
"github.com/marmotedu/iam/internal/pkg/server"
)
// FeatureOptions contains configuration items related to API server features.
type FeatureOptions struct {
EnableProfiling bool `json:"profiling" mapstructure:"profiling"`
EnableMetrics bool `json:"enable-metrics" mapstructure:"enable-metrics"`
}
// NewFeatureOptions creates a FeatureOptions object with default parameters.
func NewFeatureOptions() *FeatureOptions {
defaults := server.NewConfig()
return &FeatureOptions{
EnableMetrics: defaults.EnableMetrics,
EnableProfiling: defaults.EnableProfiling,
}
}
// ApplyTo applies the run options to the method receiver and returns self.
func (o *FeatureOptions) ApplyTo(c *server.Config) error {
c.EnableProfiling = o.EnableProfiling
c.EnableMetrics = o.EnableMetrics
return nil
}
// Validate is used to parse and validate the parameters entered by the user at
// the command line when the program starts.
func (o *FeatureOptions) Validate() []error {
return []error{}
}
// AddFlags adds flags related to features for a specific api server to the
// specified FlagSet.
func (o *FeatureOptions) AddFlags(fs *pflag.FlagSet) {
if fs == nil {
return
}
fs.BoolVar(&o.EnableProfiling, "feature.profiling", o.EnableProfiling,
"Enable profiling via web interface host:port/debug/pprof/")
fs.BoolVar(&o.EnableMetrics, "feature.enable-metrics", o.EnableMetrics,
"Enables metrics on the apiserver at /metrics")
}