Skip to content

Appending, type-friendlier version of MarshalInclude #69

Description

@jwreschnig-utiq

Is your feature request related to a problem? Please describe.

With some code I need to build the list of included resources from multiple different types, extracted from multiple different fields. Currently MarshalInclude only accepts an ...any, and only accepts one set of resources that replaces the old set.

Describe the solution you'd like

I would prefer e.g.

func MarshalInclude[T any](v ...T) MarshalOption {
	return func(m *Marshaler) {
		for _, x := range v {
			m.included = append(m.included, x)
		}
	}
}

(Plus whatever slice capacity performance optimization you may want to complicate that with.)

Either as a direct replacement (which would be an incompatible but for me welcome change), or an alternate version named something like MarshalIncludeAppend.

Describe alternatives you've considered

I think I can't implement my own option here because m.included is private.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions