-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feature: Implement variable arguments based on NewMapper for flexible configuration settings when you init mapper. * Feature: Add Setting struct used to Config mapper * you can use like this: ``` go // Default Setting: // EnabledTypeChecking: false, // EnabledMapperStructField: true, // EnabledAutoTypeConvert: true, // EnabledMapperTag: true, // EnabledJsonTag: true, // EnabledCustomTag: false, // EnableFieldIgnoreTag: false, /// When you use default setting NewMapper() /// When you will change some setting NewMapper(CTypeChecking(true), CCustomTagName("-")) ``` * 2024-09-06 19:00 in ShangHai
- Loading branch information
Showing
10 changed files
with
263 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/devfeel/mapper" | ||
"time" | ||
) | ||
|
||
type ( | ||
User struct { | ||
Name string | ||
Age int `mapper:"_Age"` | ||
Id string `mapper:"_id"` | ||
AA string `json:"Score,omitempty"` | ||
Data []byte | ||
Students []Student | ||
Time time.Time | ||
} | ||
|
||
Student struct { | ||
Name string | ||
Age int | ||
Id string `mapper:"_id"` | ||
Score string | ||
} | ||
|
||
Teacher struct { | ||
Name string | ||
Age int | ||
Id string `mapper:"_id"` | ||
Level string | ||
} | ||
) | ||
|
||
func main() { | ||
user := &User{} | ||
userMap := &User{} | ||
teacher := &Teacher{} | ||
student := &Student{Name: "test", Age: 10, Id: "testId", Score: "100"} | ||
valMap := make(map[string]interface{}) | ||
valMap["Name"] = "map" | ||
valMap["Age"] = 10 | ||
valMap["_id"] = "x1asd" | ||
valMap["Score"] = 100 | ||
valMap["Data"] = []byte{1, 2, 3, 4} | ||
valMap["Students"] = []byte{1, 2, 3, 4} //[]Student{*student} | ||
valMap["Time"] = time.Now() | ||
|
||
mp := mapper.NewMapper(mapper.CTypeChecking(true), mapper.CMapperTag(true)) | ||
|
||
mp.Mapper(student, user) | ||
mp.AutoMapper(student, teacher) | ||
mp.MapperMap(valMap, userMap) | ||
|
||
fmt.Println("student:", student) | ||
fmt.Println("user:", user) | ||
fmt.Println("teacher", teacher) | ||
fmt.Println("userMap:", userMap) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.