github.com/polarismesh/polaris@v1.17.8/plugin/healthchecker/leader/config.go (about)

     1  /**
     2   * Tencent is pleased to support the open source community by making Polaris available.
     3   *
     4   * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
     5   *
     6   * Licensed under the BSD 3-Clause License (the "License");
     7   * you may not use this file except in compliance with the License.
     8   * You may obtain a copy of the License at
     9   *
    10   * https://opensource.org/licenses/BSD-3-Clause
    11   *
    12   * Unless required by applicable law or agreed to in writing, software distributed
    13   * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
    14   * CONDITIONS OF ANY KIND, either express or implied. See the License for the
    15   * specific language governing permissions and limitations under the License.
    16   */
    17  
    18  package leader
    19  
    20  import (
    21  	"time"
    22  
    23  	"github.com/mitchellh/mapstructure"
    24  
    25  	"github.com/polarismesh/polaris/common/batchjob"
    26  )
    27  
    28  type Config struct {
    29  	SoltNum   int32               `json:"soltNum"`
    30  	StreamNum int32               `json:"streamNum"`
    31  	Batch     batchjob.CtrlConfig `json:"batch,omitempty"`
    32  }
    33  
    34  func unmarshal(options map[string]interface{}) (*Config, error) {
    35  	config := &Config{
    36  		SoltNum:   DefaultSoltNum,
    37  		StreamNum: int32(streamNum),
    38  		Batch: batchjob.CtrlConfig{
    39  			QueueSize:     16384,
    40  			WaitTime:      32 * time.Millisecond,
    41  			MaxBatchCount: 64,
    42  			Concurrency:   512,
    43  		},
    44  	}
    45  	decodeConfig := &mapstructure.DecoderConfig{
    46  		DecodeHook: mapstructure.StringToTimeDurationHookFunc(),
    47  		Result:     config,
    48  	}
    49  	decoder, err := mapstructure.NewDecoder(decodeConfig)
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  	if err = decoder.Decode(options); err != nil {
    54  		return nil, err
    55  	}
    56  	return config, nil
    57  }