Giter Site home page Giter Site logo

alexsem80 / go-mapper Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 0.0 15 KB

go-mapper module is designed for automatic types conversion between structs, pointers, maps and slices

Home Page: https://github.com/alexsem80/go-mapper

Go 100.00%
golang mapper go modules

go-mapper's Introduction

go-mapper

Installation

go get github.com/alexsem80/go-mapper

Usage

package main

import (
	"github.com/alexsem80/go-mapper/mapper"
)

func main() {
	src := Destination{
		Id:     1,
		Name:   "Name",
		Weight: 32.32,
		Marks:  []int32{2, 3, 4},
		Address: []*NestedDestination{
			{
				State: "RYA",
				Index: map[int]*DestinationMapType{
					1: {Name: "Name1"},
				},
			},
			{
				State: "MOW",
				Index: map[int]*DestinationMapType{
					2: {Name: "Name2"},
				},
			},
		},
	}

	dest := &Source{}

	mapper := mapper.NewMapper()
	mapper.CreateMap((*Source)(nil), (*Destination)(nil))
	mapper.CreateMap((*NestedSource)(nil), (*NestedDestination)(nil))
	mapper.CreateMap((*SourceMapType)(nil), (*DestinationMapType)(nil))

	mapper.Init()

	mapper.Map(dest, src)
}

type Source struct {
	ID        int
	FirstName string `mapper:"Name"`
	Weight    float32
	Marks     []int32
	Address   []*NestedSource
}

type NestedSource struct {
	State string
	Index map[int]*SourceMapType
}

type Destination struct {
	Id      int `mapper:"ID"`
	Name    string
	Weight  float32
	Marks   []int32
	Address []*NestedDestination
}

type NestedDestination struct {
	State string
	Index map[int]*DestinationMapType
}

type SourceMapType struct {
	Name string
}

type DestinationMapType struct {
	Name string
}

go-mapper's People

Contributors

alexsem80 avatar

Stargazers

Oussema Zouaghi avatar Meysam Hadeli avatar Mehdi Hadeli avatar YangJun avatar Angelina avatar  avatar Randomazer avatar  avatar Yuri Bukatkin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.