Skip to content

Using Meta to Specify time.Time Type Causes Code Generation Error #3595

Open
@Kahoulam

Description

Description

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 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:

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:

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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions