Skip to content

jmattheis/goverter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ca8ed26 · Apr 4, 2025
Apr 4, 2025
Mar 29, 2025
Jun 10, 2024
Feb 22, 2024
Mar 23, 2025
Mar 23, 2025
Apr 4, 2025
Feb 22, 2024
Feb 16, 2025
Feb 16, 2025
Dec 13, 2024
Mar 10, 2023
Mar 23, 2025
Apr 4, 2025
Apr 4, 2025
Aug 15, 2021
Feb 22, 2024
Feb 13, 2025
Mar 14, 2021
Feb 22, 2024
Jun 10, 2024
Feb 13, 2025
Feb 13, 2025
Feb 16, 2025
Jun 21, 2024

Repository files navigation

goverter

a "type-safe Go converter" generator

Build Status codecov Go Report Card Go Reference latest release

goverter is a tool for creating type-safe converters. All you have to do is create an interface and execute goverter. The project is meant as alternative to jinzhu/copier that doesn't use reflection.

Getting StartedInstallationCLIConfig

Features

Example

Given this converter:

package example

// goverter:converter
type Converter interface {
    ConvertItems(source []Input) []Output

    // goverter:ignore Irrelevant
    // goverter:map Nested.AgeInYears Age
    Convert(source Input) Output
}

type Input struct {
    Name string
    Nested InputNested
}
type InputNested struct {
    AgeInYears int
}
type Output struct {
    Name string
    Age int
    Irrelevant bool
}

Goverter will generated these conversion methods:

package generated

import example "goverter/example"

type ConverterImpl struct{}

func (c *ConverterImpl) Convert(source example.Input) example.Output {
    var exampleOutput example.Output
    exampleOutput.Name = source.Name
    exampleOutput.Age = source.Nested.AgeInYears
    return exampleOutput
}
func (c *ConverterImpl) ConvertItems(source []example.Input) []example.Output {
    var exampleOutputList []example.Output
    if source != nil {
        exampleOutputList = make([]example.Output, len(source))
        for i := 0; i < len(source); i++ {
            exampleOutputList[i] = c.Convert(source[i])
        }
    }
    return exampleOutputList
}

See Getting Started.

Versioning

goverter uses SemVer for versioning the cli.

License

This project is licensed under the MIT License - see the LICENSE file for details

Logo by MariaLetta