Files
larksuite-cli/internal/util/json.go
梁硕 83dfb068ad feat: open-source lark-cli — the official CLI for Lark/Feishu
Change-Id: I113d9cdb5403cec347efe4595415e34a18b7decf
2026-03-28 10:36:25 +08:00

26 lines
522 B
Go

// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
package util
import (
"encoding/json"
)
// ToFloat64 extracts a float64 from a value that may be float64 or json.Number.
// Returns (0, false) if the value is neither.
func ToFloat64(v interface{}) (float64, bool) {
switch n := v.(type) {
case float64:
return n, true
case json.Number:
f, err := n.Float64()
return f, err == nil
case int:
return float64(n), true
case int64:
return float64(n), true
}
return 0, false
}