Using Meta to Specify time.Time Type Causes Code Generation Error
- Dominant language
- Go
- Stars
- 6.1k
- Forks
- 583
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 15
Description
## Description
In my design file, I use the following code to specify a `date-time` format field as `time.Time` type:
```go
Attribute(name, String, func() {
Meta("struct:field:type", "time.Time", "time") // Specify struct field type metadata
Description(desc) // Set description of the attribute
Format(FormatDateTime) // Set format for date and time
Example("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:
```console
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:
```golang
package design
import (
. "goa.design/goa/v3/dsl"
)
var _ = API("example", func() {
Title("Example API")
Server("example", func() {
Host("localhost", func() {
URI("http://localhost:8080")
})
})
})
var ExampleType = Type("ExampleType", func() {
Attribute("timestamp", String, func() {
Meta("struct:field:type", "time.Time", "time") // Specify struct field type metadata
Description("Timestamp in RFC3339 format")
Format(FormatDateTime)
Example("2024-01-01T11:53:54Z")
})
Required("timestamp")
})
var _ = Service("example", func() {
Method("show", func() {
Payload(ExampleType)
Result(ExampleType)
HTTP(func() {
GET("/example")
Response(StatusOK)
})
})
})
```
## 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!
Contributor guide
Assessment
This issue has not been assessed yet.