beego/beego · error
not int64 value
Error message
not int64 value
What it means
JSONConfigContainer.Int64 only accepts float64 — the type encoding/json gives every JSON number — and, unlike Int, has no string fallback. A value that is a JSON string ("30"), boolean, array, or object yields "not int64 value", even though Int would parse the same quoted string successfully.
Source
Thrown at core/config/json/json.go:164
}
// DefaultInt returns the integer value for a given key.
// if err != nil return defaultval
func (c *JSONConfigContainer) DefaultInt(key string, defaultVal int) int {
if v, err := c.Int(key); err == nil {
return v
}
return defaultVal
}
// Int64 returns the int64 value for a given key.
func (c *JSONConfigContainer) Int64(key string) (int64, error) {
val := c.getData(key)
if val != nil {
if v, ok := val.(float64); ok {
return int64(v), nil
}
return 0, errors.New("not int64 value")
}
return 0, errors.New("not exist key:" + key)
}
// DefaultInt64 returns the int64 value for a given key.
// if err != nil return defaultval
func (c *JSONConfigContainer) DefaultInt64(key string, defaultVal int64) int64 {
if v, err := c.Int64(key); err == nil {
return v
}
return defaultVal
}
// Float returns the float value for a given key.
func (c *JSONConfigContainer) Float(key string) (float64, error) {
val := c.getData(key)
if val != nil {
if v, ok := val.(float64); ok {View on GitHub (pinned to 939cfde380)
Solutions
- Remove the quotes so the value is a bare JSON number
- If the value must stay a string, read it with String and strconv.ParseInt yourself
- Use DefaultInt64(key, fallback) when a fallback is acceptable
Example fix
// before (conf.json)
{ "timeout": "30" }
// after
{ "timeout": 30 } Defensive patterns
Strategy: type-guard
Validate before calling
func isJSONNumber(data []byte, key string) bool {
var m map[string]json.RawMessage
if json.Unmarshal(data, &m) != nil {
return false
}
var v interface{}
if json.Unmarshal(m[key], &v) != nil {
return false
}
_, ok := v.(float64)
return ok
} Type guard
func int64Val(v interface{}) (int64, bool) {
f, ok := v.(float64)
if !ok {
return 0, false // Int64, unlike Int, rejects strings
}
return int64(f), true
} Prevention
- Never quote int64 settings in JSON
- Remember the Int vs Int64 asymmetry when choosing getters
- Unmarshal into typed structs to catch type errors at startup with field context
When it happens
Trigger: cfg.Int64("timeout") when the file holds "timeout": "30" (quoted), true, or any composite value; switching a call site from Int to Int64 where quoted numeric values previously worked.
Common situations: Quoted numerics in hand-edited JSON; values shared with systems that only accept strings; getters swapped during a widening refactor (int -> int64).
Related errors
- not valid value
- not float64 value
- not exist key:%s
- nonexist section ${section}
- incompatible types for comparison
AI-assisted analysis of beego/beego@939cfde380 (2026-08-15).
Data as JSON: /api/errors/cf952dc261cab9c6.
Report an issue: GitHub.