[问题]:自定义类型查询解析器中缺少错误详细信息
// Query struct for testing
type Query struct {
TextField TextField query:"textField" // Built-in type: error includes "Details"
CustomField CustomField query:"customField" // Custom type: error does NOT include "Details"
}
// parseInt function to handle common integer parsing logic func parseInt(s string) (int, error) { n, err := strconv.Atoi(s) if err != nil { return 0, fmt.Errorf("parseInt: %w", err) } if n < 0 { return 0, errors.New("parseInt: must be non-negative") } return n, nil }
// TextField implementing TextUnmarshaler type TextField int
func (t *TextField) UnmarshalText(b []byte) error { if n, err := parseInt(string(b)); err != nil { return fmt.Errorf("TextField: %w", err) } else { *t = TextField(n) return nil } }
// CustomField with custom parser type CustomField int
func ParseCustomField(val string) reflect.Value { if n, err := parseInt(val); err != nil { return reflect.Value{} } else { c := CustomField(n) return reflect.ValueOf(c) } }
func main() { app := fiber.New()
// Register custom parser for CustomField
fiber.SetParserDecoder(fiber.ParserConfig{
ParserType: []fiber.ParserType{{
Customtype: CustomField(0),
Converter: ParseCustomField,
}},
…
内容来源: gofiber/fiber