fix config nil error
This commit is contained in:
@@ -11,6 +11,11 @@ func NewAlertingOptions() *AlertingOptions {
|
||||
}
|
||||
|
||||
func (s *AlertingOptions) ApplyTo(options *AlertingOptions) {
|
||||
if options == nil {
|
||||
options = s
|
||||
return
|
||||
}
|
||||
|
||||
if s.Endpoint != "" {
|
||||
options.Endpoint = s.Endpoint
|
||||
}
|
||||
|
||||
@@ -25,7 +25,12 @@ func NewDevopsOptions() *DevopsOptions {
|
||||
|
||||
// ApplyTo apply configuration to another options
|
||||
func (s *DevopsOptions) ApplyTo(options *DevopsOptions) {
|
||||
if s.Host != "" && options != nil {
|
||||
if options == nil {
|
||||
options = s
|
||||
return
|
||||
}
|
||||
|
||||
if s.Host != "" {
|
||||
reflectutils.Override(options, s)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,11 @@ func NewElasticSearchOptions() *ElasticSearchOptions {
|
||||
}
|
||||
|
||||
func (s *ElasticSearchOptions) ApplyTo(options *ElasticSearchOptions) {
|
||||
if options == nil {
|
||||
options = s
|
||||
return
|
||||
}
|
||||
|
||||
if s.Host != "" {
|
||||
reflectutils.Override(options, s)
|
||||
}
|
||||
|
||||
@@ -46,6 +46,10 @@ func (k *KubernetesOptions) Validate() []error {
|
||||
}
|
||||
|
||||
func (k *KubernetesOptions) ApplyTo(options *KubernetesOptions) {
|
||||
if options == nil {
|
||||
options = k
|
||||
return
|
||||
}
|
||||
reflectutils.Override(options, k)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,10 @@ func NewKubeSphereOptions() *KubeSphereOptions {
|
||||
}
|
||||
|
||||
func (s *KubeSphereOptions) ApplyTo(options *KubeSphereOptions) {
|
||||
if options == nil {
|
||||
options = s
|
||||
return
|
||||
}
|
||||
if s.AccountServer != "" {
|
||||
options.AccountServer = s.AccountServer
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ func (l *LdapOptions) Validate() []error {
|
||||
}
|
||||
|
||||
func (l *LdapOptions) ApplyTo(options *LdapOptions) {
|
||||
if options == nil {
|
||||
options = l
|
||||
return
|
||||
}
|
||||
|
||||
if l.Host != "" {
|
||||
reflectutils.Override(options, l)
|
||||
}
|
||||
|
||||
@@ -34,6 +34,10 @@ func (m *MySQLOptions) Validate() []error {
|
||||
}
|
||||
|
||||
func (m *MySQLOptions) ApplyTo(options *MySQLOptions) {
|
||||
if options == nil {
|
||||
options = m
|
||||
return
|
||||
}
|
||||
reflectutils.Override(options, m)
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,11 @@ func NewNotificationOptions() *NotificationOptions {
|
||||
}
|
||||
|
||||
func (s *NotificationOptions) ApplyTo(options *NotificationOptions) {
|
||||
if options == nil {
|
||||
options = s
|
||||
return
|
||||
}
|
||||
|
||||
if s.Endpoint != "" {
|
||||
options.Endpoint = s.Endpoint
|
||||
}
|
||||
|
||||
@@ -19,6 +19,11 @@ func NewOpenPitrixOptions() *OpenPitrixOptions {
|
||||
}
|
||||
|
||||
func (s *OpenPitrixOptions) ApplyTo(options *OpenPitrixOptions) {
|
||||
if options == nil {
|
||||
options = s
|
||||
return
|
||||
}
|
||||
|
||||
if s.APIServer != "" {
|
||||
reflectutils.Override(options, s)
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ func (s *PrometheusOptions) Validate() []error {
|
||||
}
|
||||
|
||||
func (s *PrometheusOptions) ApplyTo(options *PrometheusOptions) {
|
||||
if options == nil {
|
||||
options = s
|
||||
return
|
||||
}
|
||||
|
||||
if s.Endpoint != "" {
|
||||
options.Endpoint = s.Endpoint
|
||||
}
|
||||
|
||||
@@ -44,6 +44,11 @@ func (r *RedisOptions) Validate() []error {
|
||||
|
||||
// ApplyTo apply to another options if it's a enabled option(non empty host)
|
||||
func (r *RedisOptions) ApplyTo(options *RedisOptions) {
|
||||
if options == nil {
|
||||
options = r
|
||||
return
|
||||
}
|
||||
|
||||
if r.Host != "" {
|
||||
reflectutils.Override(options, r)
|
||||
}
|
||||
|
||||
@@ -40,6 +40,11 @@ func (s *S3Options) Validate() []error {
|
||||
|
||||
// ApplyTo overrides options if it's valid, which endpoint is not empty
|
||||
func (s *S3Options) ApplyTo(options *S3Options) {
|
||||
if options == nil {
|
||||
options = s
|
||||
return
|
||||
}
|
||||
|
||||
if s.Endpoint != "" {
|
||||
reflectutils.Override(options, s)
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ func (s *ServiceMeshOptions) Validate() []error {
|
||||
|
||||
func (s *ServiceMeshOptions) ApplyTo(options *ServiceMeshOptions) {
|
||||
if options == nil {
|
||||
options = s
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ func (s *SonarQubeOptions) Validate() []error {
|
||||
|
||||
func (s *SonarQubeOptions) ApplyTo(options *SonarQubeOptions) {
|
||||
if options == nil {
|
||||
options = s
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -37,22 +37,23 @@ func In(value interface{}, container interface{}) bool {
|
||||
}
|
||||
|
||||
func Override(left interface{}, right interface{}) {
|
||||
if left == nil || right == nil {
|
||||
if reflect.ValueOf(left).IsNil() || reflect.ValueOf(right).IsNil() {
|
||||
return
|
||||
}
|
||||
|
||||
if reflect.ValueOf(left).Type().Kind() != reflect.Ptr ||
|
||||
reflect.ValueOf(right).Type().Kind() != reflect.Ptr {
|
||||
reflect.ValueOf(right).Type().Kind() != reflect.Ptr ||
|
||||
reflect.ValueOf(left).Kind() != reflect.ValueOf(right).Kind() {
|
||||
return
|
||||
}
|
||||
|
||||
old := reflect.ValueOf(left).Elem()
|
||||
new := reflect.ValueOf(right).Elem()
|
||||
oldVal := reflect.ValueOf(left).Elem()
|
||||
newVal := reflect.ValueOf(right).Elem()
|
||||
|
||||
for i := 0; i < old.NumField(); i++ {
|
||||
val := new.Field(i).Interface()
|
||||
for i := 0; i < oldVal.NumField(); i++ {
|
||||
val := newVal.Field(i).Interface()
|
||||
if !reflect.DeepEqual(val, reflect.Zero(reflect.TypeOf(val)).Interface()) {
|
||||
old.Field(i).Set(reflect.ValueOf(val))
|
||||
oldVal.Field(i).Set(reflect.ValueOf(val))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user