/xavi

Primary LanguageGoMIT LicenseMIT

xavi

GoDoc GoCard Build Status codecov

xavi is a Go library for passing through elements from src struct to dst struct.

There are two ways to match elements

  1. To use xavi struct tag. It requires those two type are the same.
  2. Same name and type of field.

Installation

$ go get github.com/atsushi-ishibashi/xavi

Example

package main

import (
	"fmt"

	"github.com/atsushi-ishibashi/xavi"
)

type Hoge struct {
	Description string

	HogeID     int64   `xavi:"id"`
	HogeName   string  `xavi:"name"`
	HogeStruct SubHoge `xavi:"subHoge"`
}

type SubHoge struct {
	Name string
}

type DstHoge struct {
	Description string

	ID     int64   `xavi:"id"`
	Name   string  `xavi:"name"`
	Struct SubHoge `xavi:"subHoge"`
}

func main() {
	hoge := Hoge{
		HogeID:   1,
		HogeName: "name",
		HogeStruct: SubHoge{
			Name: "sub",
		},
		Description: "description",
	}
	var dstHoge DstHoge

	xavi.Pass(&dstHoge, hoge)

	fmt.Printf("%+v", dstHoge)
}

//Output
{Description:description ID:1 Name:name Struct:{Name:sub}}