63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
/*
|
|
* Copyright (c) New Cloud Technologies, Ltd., 2013-2026
|
|
*
|
|
* You can not use the contents of the file in any way without New Cloud Technologies Ltd. written permission.
|
|
* To obtain such a permit, you should contact New Cloud Technologies, Ltd. at https://myoffice.ru/contacts/
|
|
*/
|
|
|
|
package config
|
|
|
|
import (
|
|
"reflect"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/go-viper/mapstructure/v2"
|
|
)
|
|
|
|
type CommaSeparatedFloat64Slice []float64
|
|
|
|
func CommaSeparatedFloat64SliceHookFunc() mapstructure.DecodeHookFuncType {
|
|
return func(
|
|
f reflect.Type,
|
|
t reflect.Type,
|
|
data interface{},
|
|
) (interface{}, error) {
|
|
// Check that the data is string
|
|
if f.Kind() != reflect.String {
|
|
return data, nil
|
|
}
|
|
|
|
// Check that the target type is our custom type
|
|
if t != reflect.TypeOf(CommaSeparatedFloat64Slice{}) {
|
|
return data, nil
|
|
}
|
|
|
|
stringSlice := strings.Split(data.(string), ",")
|
|
floatSlice := make([]float64, 0)
|
|
for _, str := range stringSlice {
|
|
val, err := strconv.ParseFloat(strings.TrimSpace(str), 64)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
floatSlice = append(floatSlice, val)
|
|
}
|
|
|
|
// Return the parsed value
|
|
return CommaSeparatedFloat64Slice(floatSlice), nil
|
|
}
|
|
}
|
|
|
|
// HttpMetrics configuration properties for http monitoring
|
|
type HttpMetrics struct {
|
|
HistogramEnabled bool
|
|
Buckets CommaSeparatedFloat64Slice
|
|
}
|
|
|
|
// Metrics configuration properties for monitoring
|
|
type Metrics struct {
|
|
Endpoint string
|
|
HistogramBuckets CommaSeparatedFloat64Slice
|
|
Http HttpMetrics
|
|
}
|