-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (51 loc) · 1.16 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"strconv"
"time"
examples "github.com/alextanhongpin/mapper/examples"
)
//go:generate go run github.com/alextanhongpin/mapper/cmd/mapper -type Mapper
type Mapper interface {
AtoB(A) B
ExternalAtoB(examples.A) examples.B
CtoD(C) (D, error)
}
type Status string
// Automatically maps methods. However, tags does not work if you use methods.
type A struct {
id int
str string
bool bool
slice []string
m map[string]int
t time.Time
status Status
}
func (a *A) ID() int { return a.id }
func (a A) Str() string { return a.str }
func (a A) Bool() bool { return a.bool }
func (a A) Slice() []string { return a.slice }
func (a A) Map() map[string]int { return a.m }
func (a A) Time() time.Time { return a.t }
func (a A) Status() Status { return a.status }
type B struct {
ID int
Str string
Bool bool
Slice []string
Map map[string]int
Time time.Time
Status string `map:"Status(),StatusToString"`
}
type C struct {
id string
}
func (c C) ID() (int, error) {
return strconv.Atoi(c.id)
}
type D struct {
ID int
}
func StatusToString(s Status) string {
return string(s)
}