You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my design file, I use the following code to specify a date-time format field as time.Time type:
Attribute(name, String, func() {
Meta("struct:field:type", "time.Time", "time") // Specify struct field type metadataDescription(desc) // Set description of the attributeFormat(FormatDateTime) // Set format for date and timeExample("2024-01-01T11:53:54Z") // Provide example value
})
The reason for writing it this way is to avoid repeatedly converting between time.Time and string.
However, the generated code produces the following error:
cannot use *body.Timestamp (variable of type time.Time) as string value in argument to goa.ValidateFormat
I hope to be able to specify a date-time format field as time.Time type in the design file using Meta, and have the generated code work without the above error.
I would appreciate any solutions or guidance. Thank you!
The text was updated successfully, but these errors were encountered:
Kahoulam
changed the title
Using Meta to Specify time.Time Type in goa.design Causes Code Generation Error
Using Meta to Specify time.Time Type Causes Code Generation Error
Sep 19, 2024
Hello, the type specified with struct:field:type must be structurally compatible with the type defined in the design, here time.Time isn't compatible with String.
Description
In my design file, I use the following code to specify a
date-time
format field astime.Time
type:The reason for writing it this way is to avoid repeatedly converting between time.Time and string.
However, the generated code produces the following error:
cannot use *body.Timestamp (variable of type time.Time) as string value in argument to goa.ValidateFormat
Example
Below is the complete design file example:
Expected Solution
I hope to be able to specify a date-time format field as time.Time type in the design file using Meta, and have the generated code work without the above error.
Additional Information
goa version: v3.16.2
Golang version: go1.22.6
Operating System: linux/arm64
I would appreciate any solutions or guidance. Thank you!
The text was updated successfully, but these errors were encountered: