2017-03-29 15:54:07 -05:00
|
|
|
package mysql
|
|
|
|
|
|
|
|
import (
|
2021-09-07 02:35:37 -05:00
|
|
|
"context"
|
2024-01-05 01:37:15 -06:00
|
|
|
"database/sql"
|
2021-09-07 02:35:37 -05:00
|
|
|
"encoding/json"
|
2019-09-24 13:50:49 -05:00
|
|
|
"errors"
|
2017-03-29 15:54:07 -05:00
|
|
|
"fmt"
|
2019-11-06 02:54:53 -06:00
|
|
|
"net/url"
|
2018-01-18 04:44:36 -06:00
|
|
|
"reflect"
|
2017-03-31 04:45:25 -05:00
|
|
|
"strconv"
|
2018-10-17 04:45:06 -05:00
|
|
|
"strings"
|
2021-05-05 09:46:07 -05:00
|
|
|
"time"
|
2019-01-15 06:29:56 -06:00
|
|
|
|
2019-09-24 13:50:49 -05:00
|
|
|
"github.com/VividCortex/mysqlerr"
|
2021-10-07 09:33:50 -05:00
|
|
|
"github.com/go-sql-driver/mysql"
|
2021-09-07 02:35:37 -05:00
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend/datasource"
|
2023-11-13 03:25:19 -06:00
|
|
|
sdkhttpclient "github.com/grafana/grafana-plugin-sdk-go/backend/httpclient"
|
2021-09-07 02:35:37 -05:00
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
|
2021-05-05 09:46:07 -05:00
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/data"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/data/sqlutil"
|
2022-11-02 09:03:50 -05:00
|
|
|
|
2023-12-14 02:42:06 -06:00
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
|
2024-04-15 07:26:15 -05:00
|
|
|
"github.com/grafana/grafana/pkg/tsdb/mysql/sqleng"
|
2021-05-05 09:46:07 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
dateFormat = "2006-01-02"
|
|
|
|
dateTimeFormat1 = "2006-01-02 15:04:05"
|
|
|
|
dateTimeFormat2 = "2006-01-02T15:04:05Z"
|
2017-03-29 15:54:07 -05:00
|
|
|
)
|
|
|
|
|
2019-11-06 02:54:53 -06:00
|
|
|
func characterEscape(s string, escapeChar string) string {
|
2020-09-22 09:22:19 -05:00
|
|
|
return strings.ReplaceAll(s, escapeChar, url.QueryEscape(escapeChar))
|
2019-11-06 02:54:53 -06:00
|
|
|
}
|
|
|
|
|
2024-05-07 02:54:30 -05:00
|
|
|
func NewInstanceSettings(logger log.Logger) datasource.InstanceFactoryFunc {
|
2023-10-16 09:40:04 -05:00
|
|
|
return func(ctx context.Context, settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
|
2024-02-22 07:22:14 -06:00
|
|
|
cfg := backend.GrafanaConfigFromContext(ctx)
|
|
|
|
sqlCfg, err := cfg.SQL()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-09-07 02:35:37 -05:00
|
|
|
jsonData := sqleng.JsonData{
|
2024-02-22 07:22:14 -06:00
|
|
|
MaxOpenConns: sqlCfg.DefaultMaxOpenConns,
|
|
|
|
MaxIdleConns: sqlCfg.DefaultMaxIdleConns,
|
|
|
|
ConnMaxLifetime: sqlCfg.DefaultMaxConnLifetimeSeconds,
|
2023-05-26 05:33:55 -05:00
|
|
|
SecureDSProxy: false,
|
|
|
|
AllowCleartextPasswords: false,
|
2021-09-07 02:35:37 -05:00
|
|
|
}
|
|
|
|
|
2024-02-22 07:22:14 -06:00
|
|
|
err = json.Unmarshal(settings.JSONData, &jsonData)
|
2021-09-07 02:35:37 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error reading settings: %w", err)
|
|
|
|
}
|
2022-12-13 02:56:52 -06:00
|
|
|
|
|
|
|
database := jsonData.Database
|
|
|
|
if database == "" {
|
|
|
|
database = settings.Database
|
|
|
|
}
|
|
|
|
|
2021-09-07 02:35:37 -05:00
|
|
|
dsInfo := sqleng.DataSourceInfo{
|
|
|
|
JsonData: jsonData,
|
|
|
|
URL: settings.URL,
|
|
|
|
User: settings.User,
|
2022-12-13 02:56:52 -06:00
|
|
|
Database: database,
|
2021-09-07 02:35:37 -05:00
|
|
|
ID: settings.ID,
|
|
|
|
Updated: settings.Updated,
|
|
|
|
UID: settings.UID,
|
|
|
|
DecryptedSecureJSONData: settings.DecryptedSecureJSONData,
|
|
|
|
}
|
2021-05-19 16:53:41 -05:00
|
|
|
|
|
|
|
protocol := "tcp"
|
2021-09-07 02:35:37 -05:00
|
|
|
if strings.HasPrefix(dsInfo.URL, "/") {
|
2021-05-19 16:53:41 -05:00
|
|
|
protocol = "unix"
|
|
|
|
}
|
2019-11-06 02:54:53 -06:00
|
|
|
|
2024-02-14 06:05:47 -06:00
|
|
|
proxyClient, err := settings.ProxyClient(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-03-16 07:54:19 -05:00
|
|
|
// register the secure socks proxy dialer context, if enabled
|
2024-02-14 06:05:47 -06:00
|
|
|
if proxyClient.SecureSocksProxyEnabled() {
|
|
|
|
dialer, err := proxyClient.NewSecureSocksProxyContextDialer()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-03-16 07:54:19 -05:00
|
|
|
// UID is only unique per org, the only way to ensure uniqueness is to do it by connection information
|
|
|
|
uniqueIdentifier := dsInfo.User + dsInfo.DecryptedSecureJSONData["password"] + dsInfo.URL + dsInfo.Database
|
2024-02-14 06:05:47 -06:00
|
|
|
protocol, err = registerProxyDialerContext(protocol, uniqueIdentifier, dialer)
|
2023-03-16 07:54:19 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 16:53:41 -05:00
|
|
|
cnnstr := fmt.Sprintf("%s:%s@%s(%s)/%s?collation=utf8mb4_unicode_ci&parseTime=true&loc=UTC&allowNativePasswords=true",
|
2021-09-07 02:35:37 -05:00
|
|
|
characterEscape(dsInfo.User, ":"),
|
|
|
|
dsInfo.DecryptedSecureJSONData["password"],
|
2021-05-19 16:53:41 -05:00
|
|
|
protocol,
|
2021-09-07 02:35:37 -05:00
|
|
|
characterEscape(dsInfo.URL, ")"),
|
|
|
|
characterEscape(dsInfo.Database, "?"),
|
2021-05-19 16:53:41 -05:00
|
|
|
)
|
2019-01-15 06:29:56 -06:00
|
|
|
|
2023-05-26 05:33:55 -05:00
|
|
|
if dsInfo.JsonData.AllowCleartextPasswords {
|
|
|
|
cnnstr += "&allowCleartextPasswords=true"
|
|
|
|
}
|
|
|
|
|
2023-10-16 09:40:04 -05:00
|
|
|
opts, err := settings.HTTPClientOptions(ctx)
|
2021-09-07 02:35:37 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-11-13 03:25:19 -06:00
|
|
|
tlsConfig, err := sdkhttpclient.GetTLSConfig(opts)
|
2021-05-19 16:53:41 -05:00
|
|
|
if err != nil {
|
2019-10-22 09:16:53 -05:00
|
|
|
return nil, err
|
|
|
|
}
|
2019-01-15 06:29:56 -06:00
|
|
|
|
2021-05-19 16:53:41 -05:00
|
|
|
if tlsConfig.RootCAs != nil || len(tlsConfig.Certificates) > 0 {
|
2021-09-07 02:35:37 -05:00
|
|
|
tlsConfigString := fmt.Sprintf("ds%d", settings.ID)
|
2021-05-19 16:53:41 -05:00
|
|
|
if err := mysql.RegisterTLSConfig(tlsConfigString, tlsConfig); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cnnstr += "&tls=" + tlsConfigString
|
|
|
|
}
|
2017-03-30 06:46:46 -05:00
|
|
|
|
2021-09-07 02:35:37 -05:00
|
|
|
if dsInfo.JsonData.Timezone != "" {
|
|
|
|
cnnstr += fmt.Sprintf("&time_zone='%s'", url.QueryEscape(dsInfo.JsonData.Timezone))
|
2021-05-27 03:03:03 -05:00
|
|
|
}
|
|
|
|
|
2021-05-19 16:53:41 -05:00
|
|
|
config := sqleng.DataPluginConfiguration{
|
2021-09-07 02:35:37 -05:00
|
|
|
DSInfo: dsInfo,
|
2021-05-19 16:53:41 -05:00
|
|
|
TimeColumnNames: []string{"time", "time_sec"},
|
|
|
|
MetricColumnTypes: []string{"CHAR", "VARCHAR", "TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT"},
|
2024-02-22 07:22:14 -06:00
|
|
|
RowLimit: sqlCfg.RowLimit,
|
|
|
|
}
|
|
|
|
|
|
|
|
userFacingDefaultError, err := cfg.UserFacingDefaultError()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2021-05-19 16:53:41 -05:00
|
|
|
}
|
2017-04-21 08:07:43 -05:00
|
|
|
|
2023-06-16 10:46:47 -05:00
|
|
|
rowTransformer := mysqlQueryResultTransformer{
|
2024-02-22 07:22:14 -06:00
|
|
|
userError: userFacingDefaultError,
|
2023-06-16 10:46:47 -05:00
|
|
|
}
|
2021-05-19 16:53:41 -05:00
|
|
|
|
2024-01-05 01:37:15 -06:00
|
|
|
db, err := sql.Open("mysql", cnnstr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
db.SetMaxOpenConns(config.DSInfo.JsonData.MaxOpenConns)
|
|
|
|
db.SetMaxIdleConns(config.DSInfo.JsonData.MaxIdleConns)
|
|
|
|
db.SetConnMaxLifetime(time.Duration(config.DSInfo.JsonData.ConnMaxLifetime) * time.Second)
|
|
|
|
|
2024-02-22 07:22:14 -06:00
|
|
|
return sqleng.NewQueryDataHandler(userFacingDefaultError, db, config, &rowTransformer, newMysqlMacroEngine(logger, userFacingDefaultError), logger)
|
2021-09-07 02:35:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 13:50:49 -05:00
|
|
|
type mysqlQueryResultTransformer struct {
|
2023-06-16 10:46:47 -05:00
|
|
|
userError string
|
2018-07-26 11:10:45 -05:00
|
|
|
}
|
2018-01-18 04:44:36 -06:00
|
|
|
|
2022-11-02 09:03:50 -05:00
|
|
|
func (t *mysqlQueryResultTransformer) TransformQueryError(logger log.Logger, err error) error {
|
2020-11-19 07:47:17 -06:00
|
|
|
var driverErr *mysql.MySQLError
|
|
|
|
if errors.As(err, &driverErr) {
|
|
|
|
if driverErr.Number != mysqlerr.ER_PARSE_ERROR && driverErr.Number != mysqlerr.ER_BAD_FIELD_ERROR &&
|
|
|
|
driverErr.Number != mysqlerr.ER_NO_SUCH_TABLE {
|
2022-11-02 09:03:50 -05:00
|
|
|
logger.Error("Query error", "error", err)
|
2023-06-16 10:46:47 -05:00
|
|
|
return fmt.Errorf(("query failed - %s"), t.userError)
|
2019-09-24 13:50:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-05-05 09:46:07 -05:00
|
|
|
func (t *mysqlQueryResultTransformer) GetConverterList() []sqlutil.StringConverter {
|
|
|
|
// For the MySQL driver , we have these possible data types:
|
|
|
|
// https://www.w3schools.com/sql/sql_datatypes.asp#:~:text=In%20MySQL%20there%20are%20three,numeric%2C%20and%20date%20and%20time.
|
|
|
|
// Since by default, we convert all into String, we need only to handle the Numeric data types
|
|
|
|
return []sqlutil.StringConverter{
|
|
|
|
{
|
|
|
|
Name: "handle DOUBLE",
|
|
|
|
InputScanKind: reflect.Struct,
|
|
|
|
InputTypeName: "DOUBLE",
|
|
|
|
ConversionFunc: func(in *string) (*string, error) { return in, nil },
|
|
|
|
Replacer: &sqlutil.StringFieldReplacer{
|
|
|
|
OutputFieldType: data.FieldTypeNullableFloat64,
|
2023-08-30 10:46:47 -05:00
|
|
|
ReplaceFunc: func(in *string) (any, error) {
|
2021-05-05 09:46:07 -05:00
|
|
|
if in == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
v, err := strconv.ParseFloat(*in, 64)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &v, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "handle BIGINT",
|
|
|
|
InputScanKind: reflect.Struct,
|
|
|
|
InputTypeName: "BIGINT",
|
|
|
|
ConversionFunc: func(in *string) (*string, error) { return in, nil },
|
|
|
|
Replacer: &sqlutil.StringFieldReplacer{
|
|
|
|
OutputFieldType: data.FieldTypeNullableInt64,
|
2023-08-30 10:46:47 -05:00
|
|
|
ReplaceFunc: func(in *string) (any, error) {
|
2021-05-05 09:46:07 -05:00
|
|
|
if in == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
v, err := strconv.ParseInt(*in, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &v, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "handle DECIMAL",
|
|
|
|
InputScanKind: reflect.Slice,
|
|
|
|
InputTypeName: "DECIMAL",
|
|
|
|
ConversionFunc: func(in *string) (*string, error) { return in, nil },
|
|
|
|
Replacer: &sqlutil.StringFieldReplacer{
|
|
|
|
OutputFieldType: data.FieldTypeNullableFloat64,
|
2023-08-30 10:46:47 -05:00
|
|
|
ReplaceFunc: func(in *string) (any, error) {
|
2021-05-05 09:46:07 -05:00
|
|
|
if in == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
v, err := strconv.ParseFloat(*in, 64)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &v, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "handle DATETIME",
|
|
|
|
InputScanKind: reflect.Struct,
|
|
|
|
InputTypeName: "DATETIME",
|
|
|
|
ConversionFunc: func(in *string) (*string, error) { return in, nil },
|
|
|
|
Replacer: &sqlutil.StringFieldReplacer{
|
|
|
|
OutputFieldType: data.FieldTypeNullableTime,
|
2023-08-30 10:46:47 -05:00
|
|
|
ReplaceFunc: func(in *string) (any, error) {
|
2021-05-05 09:46:07 -05:00
|
|
|
if in == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
v, err := time.Parse(dateTimeFormat1, *in)
|
|
|
|
if err == nil {
|
|
|
|
return &v, nil
|
|
|
|
}
|
|
|
|
v, err = time.Parse(dateTimeFormat2, *in)
|
|
|
|
if err == nil {
|
|
|
|
return &v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "handle DATE",
|
|
|
|
InputScanKind: reflect.Struct,
|
|
|
|
InputTypeName: "DATE",
|
|
|
|
ConversionFunc: func(in *string) (*string, error) { return in, nil },
|
|
|
|
Replacer: &sqlutil.StringFieldReplacer{
|
|
|
|
OutputFieldType: data.FieldTypeNullableTime,
|
2023-08-30 10:46:47 -05:00
|
|
|
ReplaceFunc: func(in *string) (any, error) {
|
2021-05-05 09:46:07 -05:00
|
|
|
if in == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
v, err := time.Parse(dateFormat, *in)
|
|
|
|
if err == nil {
|
|
|
|
return &v, nil
|
|
|
|
}
|
|
|
|
v, err = time.Parse(dateTimeFormat1, *in)
|
|
|
|
if err == nil {
|
|
|
|
return &v, nil
|
|
|
|
}
|
|
|
|
v, err = time.Parse(dateTimeFormat2, *in)
|
|
|
|
if err == nil {
|
|
|
|
return &v, nil
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "handle TIMESTAMP",
|
|
|
|
InputScanKind: reflect.Struct,
|
|
|
|
InputTypeName: "TIMESTAMP",
|
|
|
|
ConversionFunc: func(in *string) (*string, error) { return in, nil },
|
|
|
|
Replacer: &sqlutil.StringFieldReplacer{
|
|
|
|
OutputFieldType: data.FieldTypeNullableTime,
|
2023-08-30 10:46:47 -05:00
|
|
|
ReplaceFunc: func(in *string) (any, error) {
|
2021-05-05 09:46:07 -05:00
|
|
|
if in == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
v, err := time.Parse(dateTimeFormat1, *in)
|
|
|
|
if err == nil {
|
|
|
|
return &v, nil
|
|
|
|
}
|
|
|
|
v, err = time.Parse(dateTimeFormat2, *in)
|
|
|
|
if err == nil {
|
|
|
|
return &v, nil
|
|
|
|
}
|
|
|
|
return nil, err
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "handle YEAR",
|
|
|
|
InputScanKind: reflect.Struct,
|
|
|
|
InputTypeName: "YEAR",
|
|
|
|
ConversionFunc: func(in *string) (*string, error) { return in, nil },
|
|
|
|
Replacer: &sqlutil.StringFieldReplacer{
|
|
|
|
OutputFieldType: data.FieldTypeNullableInt64,
|
2023-08-30 10:46:47 -05:00
|
|
|
ReplaceFunc: func(in *string) (any, error) {
|
2021-05-05 09:46:07 -05:00
|
|
|
if in == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
v, err := strconv.ParseInt(*in, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &v, nil
|
|
|
|
},
|
|
|
|
},
|
2021-06-21 11:10:45 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "handle TINYINT",
|
|
|
|
InputScanKind: reflect.Struct,
|
|
|
|
InputTypeName: "TINYINT",
|
|
|
|
ConversionFunc: func(in *string) (*string, error) { return in, nil },
|
|
|
|
Replacer: &sqlutil.StringFieldReplacer{
|
|
|
|
OutputFieldType: data.FieldTypeNullableInt64,
|
2023-08-30 10:46:47 -05:00
|
|
|
ReplaceFunc: func(in *string) (any, error) {
|
2021-06-21 11:10:45 -05:00
|
|
|
if in == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
v, err := strconv.ParseInt(*in, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &v, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "handle SMALLINT",
|
|
|
|
InputScanKind: reflect.Struct,
|
|
|
|
InputTypeName: "SMALLINT",
|
|
|
|
ConversionFunc: func(in *string) (*string, error) { return in, nil },
|
|
|
|
Replacer: &sqlutil.StringFieldReplacer{
|
|
|
|
OutputFieldType: data.FieldTypeNullableInt64,
|
2023-08-30 10:46:47 -05:00
|
|
|
ReplaceFunc: func(in *string) (any, error) {
|
2021-06-21 11:10:45 -05:00
|
|
|
if in == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
v, err := strconv.ParseInt(*in, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &v, nil
|
|
|
|
},
|
|
|
|
},
|
2021-05-05 09:46:07 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "handle INT",
|
|
|
|
InputScanKind: reflect.Struct,
|
|
|
|
InputTypeName: "INT",
|
|
|
|
ConversionFunc: func(in *string) (*string, error) { return in, nil },
|
|
|
|
Replacer: &sqlutil.StringFieldReplacer{
|
|
|
|
OutputFieldType: data.FieldTypeNullableInt64,
|
2023-08-30 10:46:47 -05:00
|
|
|
ReplaceFunc: func(in *string) (any, error) {
|
2021-05-05 09:46:07 -05:00
|
|
|
if in == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
v, err := strconv.ParseInt(*in, 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &v, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "handle FLOAT",
|
|
|
|
InputScanKind: reflect.Struct,
|
|
|
|
InputTypeName: "FLOAT",
|
|
|
|
ConversionFunc: func(in *string) (*string, error) { return in, nil },
|
|
|
|
Replacer: &sqlutil.StringFieldReplacer{
|
|
|
|
OutputFieldType: data.FieldTypeNullableFloat64,
|
2023-08-30 10:46:47 -05:00
|
|
|
ReplaceFunc: func(in *string) (any, error) {
|
2021-05-05 09:46:07 -05:00
|
|
|
if in == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
v, err := strconv.ParseFloat(*in, 64)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &v, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|