Skip to content

tamboto2000/mapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mapper

PkgGoDev

Mapper map struct to another struct with same or similiar fields.

Installation

Mapper require Go version 1.14 or up

$ go get github.com/tamboto2000/mapper

Example

package main

import (
	"fmt"

	"github.com/tamboto2000/mapper"
)

type Struct1 struct {
	Str   string
	Num   int
	Float float64
}

type Struct2 struct {
	Str string
	Num int
}

func main() {
	struct1 := Struct1{Str: "Hello world!", Num: 1, Float: 1.5}
	struct2 := new(Struct2)
	if err := mapper.Map(struct1, struct2); err != nil {
		panic(err.Error())
	}

	fmt.Println("Str:", struct2.Str)
	fmt.Println("Num:", struct2.Num)
}

License

MIT

About

Mapper map struct to another struct

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages