Skip to content

Add support for generic structs #15

@mikemorris

Description

@mikemorris

It would be nice for mog to support conversions to/from types using generic struct fields, such as the following example.

type Gateway struct {
  Status Status[GatewayConditionType]
}

type Route struct {
  Status Status[RouteConditionType]
}

type Status[T ConditionType] struct {
  Type T
}

type ConditionType interface {
  GatewayConditionType | RouteConditionType
}

type GatewayConditionType string
const {
  GatewayConditionAccepted GatewayConditionType = "Accepted"
  GatewayConditionInSync GatewayConditionType = "InSync"
}

type RouteConditionType string
const {
  RouteConditionAccepted RouteConditionType = "Accepted"
  RouteConditionResolvedRefs RouteConditionType = "ResolvedRefs"
}

https://github.com/golang/exp/tree/master/typeparams/example and https://pkg.go.dev/go/types should provide some guidance for how to approach adding this functionality.

Metadata

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