xavi

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2019 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

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}}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pass

func Pass(dst, src interface{}) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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