Skip to content

hannamil/mapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hannamil/mapper


A simple go struct mapper.

1. Install

go get -u github.com/hannamil/mapper

2. Getting Started

package main

import (
	"fmt"
	"time"

	"github.com/hannamil/mapper"
)

type (
	Class struct {
		Name  string
		Level string
	}
	
	Person struct {
		Name  string
		Age   int
		Birth time.Time
		Class Class
	}

	Student struct {
		Name  string
		Age   int
		Class interface{}
	}
)

func main() {
	person := &Person{
		Name: "Chris han",
		Age:  40,
		Class: Class{
			Name: "algorithm",
			Level: "basic",
        },
	}
	
	student, err := mapper.Mapper(person, &Student{})
	// or
	// student, err := mapper.Mapper(person, Student{})
	if err != nil {
		fmt.Println(err)
	}
	fmt.Printf("student: %v\n", student)
}

3. output

student: {Chris han 40 {algorithm basic}}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages