A mechanic performing maintenance on a WWII truck.
Status • Run • Configuration • Contributing • License
JuryRig is in alpha - you can try it. :)
Since JuryRig operates through go generate, once you've added the binary to your $PATH
you can run
go generate ./...
... or similar.
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,
}
}
Please submit an issue with your proposal.
See LICENSE