Skip to content

Setting: arg

arg:context:regex REGEX

arg:context:regex REGEX can be defined as CLI argument, conversion comment or method comment. This setting is inheritable. Default ^ctx|^context.

go
package example

import "time"

// goverter:converter
// goverter:arg:context:regex .+Format
// goverter:extend FormatTime
type Converter interface {
	Convert(source map[string]Input, dateFormat string) map[string]Output
}

func FormatTime(t time.Time, dateFormat string) string {
	return t.Format(dateFormat)
}

type Input struct {
	Name      string
	CreatedAt time.Time
}
type Output struct {
	Name      string
	CreatedAt string
}
go
// Code generated by github.com/jmattheis/goverter, DO NOT EDIT.
//go:build !goverter

package generated

import regex "github.com/jmattheis/goverter/example/context/regex"

type ConverterImpl struct{}

func (c *ConverterImpl) Convert(source map[string]regex.Input, context string) map[string]regex.Output {
	var mapStringExampleOutput map[string]regex.Output
	if source != nil {
		mapStringExampleOutput = make(map[string]regex.Output, len(source))
		for key, value := range source {
			mapStringExampleOutput[key] = c.exampleInputToExampleOutput(value, context)
		}
	}
	return mapStringExampleOutput
}
func (c *ConverterImpl) exampleInputToExampleOutput(source regex.Input, context string) regex.Output {
	var exampleOutput regex.Output
	exampleOutput.Name = source.Name
	exampleOutput.CreatedAt = regex.FormatTime(source.CreatedAt, context)
	return exampleOutput
}