{"record":{"id":"cf952dc261cab9c6","repo":"beego/beego","slug":"not-int64-value","errorCode":null,"errorMessage":"not int64 value","messagePattern":"not int64 value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/config/json/json.go","lineNumber":164,"sourceCode":"}\n\n// DefaultInt returns the integer value for a given key.\n// if err != nil return defaultval\nfunc (c *JSONConfigContainer) DefaultInt(key string, defaultVal int) int {\n\tif v, err := c.Int(key); err == nil {\n\t\treturn v\n\t}\n\treturn defaultVal\n}\n\n// Int64 returns the int64 value for a given key.\nfunc (c *JSONConfigContainer) Int64(key string) (int64, error) {\n\tval := c.getData(key)\n\tif val != nil {\n\t\tif v, ok := val.(float64); ok {\n\t\t\treturn int64(v), nil\n\t\t}\n\t\treturn 0, errors.New(\"not int64 value\")\n\t}\n\treturn 0, errors.New(\"not exist key:\" + key)\n}\n\n// DefaultInt64 returns the int64 value for a given key.\n// if err != nil return defaultval\nfunc (c *JSONConfigContainer) DefaultInt64(key string, defaultVal int64) int64 {\n\tif v, err := c.Int64(key); err == nil {\n\t\treturn v\n\t}\n\treturn defaultVal\n}\n\n// Float returns the float value for a given key.\nfunc (c *JSONConfigContainer) Float(key string) (float64, error) {\n\tval := c.getData(key)\n\tif val != nil {\n\t\tif v, ok := val.(float64); ok {","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/beego/beego/blob/939cfde380bb9f15844ad633b84f037f7da21584/core/config/json/json.go#L146-L182","documentation":"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.","triggerScenarios":"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.","commonSituations":"Quoted numerics in hand-edited JSON; values shared with systems that only accept strings; getters swapped during a widening refactor (int -> int64).","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"],"exampleFix":"// before (conf.json)\n{ \"timeout\": \"30\" }\n\n// after\n{ \"timeout\": 30 }","handlingStrategy":"type-guard","validationCode":"func isJSONNumber(data []byte, key string) bool {\n\tvar m map[string]json.RawMessage\n\tif json.Unmarshal(data, &m) != nil {\n\t\treturn false\n\t}\n\tvar v interface{}\n\tif json.Unmarshal(m[key], &v) != nil {\n\t\treturn false\n\t}\n\t_, ok := v.(float64)\n\treturn ok\n}","typeGuard":"func int64Val(v interface{}) (int64, bool) {\n\tf, ok := v.(float64)\n\tif !ok {\n\t\treturn 0, false // Int64, unlike Int, rejects strings\n\t}\n\treturn int64(f), true\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["go","beego","json","type-mismatch","int64"],"backgroundTag":null,"analyzedSha":"939cfde380bb9f15844ad633b84f037f7da21584","analyzedAt":"2026-08-15T17:22:06.535Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}