juryrig

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2022 License: MIT Imports: 3 Imported by: 0

README

Photograph of a man fixing a truck.
A mechanic performing maintenance on a WWII truck.

JuryRig

A tool for generating Go struct mapping code, inspired by mapstruct.

StatusRunConfigurationContributingLicense

[GitHub release] [Build Status] GitHub go.mod Go version [Go Report Card] [License]

Status

JuryRig is in alpha - you can try it. :)

Run

Since JuryRig operates through go generate, once you've added the binary to your $PATH you can run

go generate ./...

... or similar.

Configuration

Given some structs...

type ExternalFilm struct {
    title   string
    runtime int
}

type ExternalUser struct {
    username string
    age      int
}

type InternalUser struct {
    username string
}

type InternalUserFilm struct {
    title   string
    runtime int
    director string
    user    InternalUser
}

We can describe a mapper as follows:

package film

//go:generate juryrig gen -o zz.mapper.impl.go

// +juryrig:mapper
type Mapper interface {
	// +juryrig:link:ef.title->title
	// +juryrig:link:ef.runtime->runtime
	// +juryrig:ignore:director
	// +juryrig:linkfunc:eu->ToInternalUser->user
	ToInternalUserFilm(ef ExternalFilm, eu ExternalUser) InternalUserFilm
	// +juryrig:link:eu.username->username
	ToInternalUser(eu ExternalUser) InternalUser
}

Running go generate will implement the following mapper struct in zz.mapper.impl.go:

package film

type MapperImpl struct{}

func (impl *MapperImpl) ToInternalUserFilm(ef ExternalFilm, eu ExternalUser) InternalUserFilm {
	return InternalUserFilm{
		title:   ef.title,
		runtime: ef.runtime,
		// director: (ignored),
		user: impl.ToInternalUser(eu),
	}
}

func (impl *MapperImpl) ToInternalUser(eu ExternalUser) InternalUser {
	return InternalUser{
		username: eu.username,
	}
}

Contributing

Please submit an issue with your proposal.

License

See LICENSE

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL