Skip to content

Commit 3631c88

Browse files
authored
refactor (#39)
1 parent 4e00b05 commit 3631c88

File tree

5 files changed

+58
-55
lines changed

5 files changed

+58
-55
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.DS_STORE
1+
.DS_STORE
2+
.idea
3+
vendor

client.go

+8-12
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ type Client struct {
99
spec *FileSpec
1010
csv *csvFile.Client
1111
json *jsonFile.Client
12-
csvTransformer *csvFile.Transformer
13-
csvReverseTransformer *csvFile.ReverseTransformer
14-
jsonTransformer *jsonFile.Transformer
15-
jsonReverseTransformer *jsonFile.ReverseTransformer
12+
csvTransformer csvFile.Transformer
13+
csvReverseTransformer csvFile.ReverseTransformer
14+
jsonTransformer jsonFile.Transformer
15+
jsonReverseTransformer jsonFile.ReverseTransformer
1616
}
1717

1818
// NewClient creates a new client for the given spec
@@ -41,10 +41,8 @@ func NewClient(spec *FileSpec) (*Client, error) {
4141
return &Client{}, err
4242
}
4343
return &Client{
44-
spec: spec,
45-
csvTransformer: &csvFile.Transformer{},
46-
csvReverseTransformer: &csvFile.ReverseTransformer{},
47-
csv: client,
44+
spec: spec,
45+
csv: client,
4846
}, nil
4947

5048
case FormatTypeJSON:
@@ -53,10 +51,8 @@ func NewClient(spec *FileSpec) (*Client, error) {
5351
return &Client{}, err
5452
}
5553
return &Client{
56-
spec: spec,
57-
jsonTransformer: &jsonFile.Transformer{},
58-
jsonReverseTransformer: &jsonFile.ReverseTransformer{},
59-
json: client,
54+
spec: spec,
55+
json: client,
6056
}, nil
6157

6258
default:

csv/transformer.go

+23-21
Original file line numberDiff line numberDiff line change
@@ -6,79 +6,81 @@ import (
66
)
77

88
type ReverseTransformer struct {
9-
defaultTransformer destination.DefaultReverseTransformer
9+
*destination.DefaultReverseTransformer
1010
}
1111

12-
func (t *ReverseTransformer) ReverseTransformValues(table *schema.Table, values []any) (schema.CQTypes, error) {
13-
return t.defaultTransformer.ReverseTransformValues(table, values)
14-
}
12+
var _ interface {
13+
ReverseTransformValues(table *schema.Table, values []any) (schema.CQTypes, error)
14+
} = ReverseTransformer{}
1515

1616
type Transformer struct{}
1717

18-
func (*Transformer) TransformBool(v *schema.Bool) any {
18+
var _ schema.CQTypeTransformer = Transformer{}
19+
20+
func (Transformer) TransformBool(v *schema.Bool) any {
1921
return v.String()
2022
}
2123

22-
func (*Transformer) TransformBytea(v *schema.Bytea) any {
24+
func (Transformer) TransformBytea(v *schema.Bytea) any {
2325
return v.String()
2426
}
2527

26-
func (*Transformer) TransformFloat8(v *schema.Float8) any {
28+
func (Transformer) TransformFloat8(v *schema.Float8) any {
2729
return v.String()
2830
}
2931

30-
func (*Transformer) TransformInt8(v *schema.Int8) any {
32+
func (Transformer) TransformInt8(v *schema.Int8) any {
3133
return v.String()
3234
}
3335

34-
func (*Transformer) TransformInt8Array(v *schema.Int8Array) any {
36+
func (Transformer) TransformInt8Array(v *schema.Int8Array) any {
3537
return v.String()
3638
}
3739

38-
func (*Transformer) TransformJSON(v *schema.JSON) any {
40+
func (Transformer) TransformJSON(v *schema.JSON) any {
3941
return v.String()
4042
}
4143

42-
func (*Transformer) TransformText(v *schema.Text) any {
44+
func (Transformer) TransformText(v *schema.Text) any {
4345
return v.Str
4446
}
4547

46-
func (*Transformer) TransformTextArray(v *schema.TextArray) any {
48+
func (Transformer) TransformTextArray(v *schema.TextArray) any {
4749
return v.String()
4850
}
4951

50-
func (*Transformer) TransformTimestamptz(v *schema.Timestamptz) any {
52+
func (Transformer) TransformTimestamptz(v *schema.Timestamptz) any {
5153
return v.String()
5254
}
5355

54-
func (*Transformer) TransformUUID(v *schema.UUID) any {
56+
func (Transformer) TransformUUID(v *schema.UUID) any {
5557
return v.String()
5658
}
5759

58-
func (*Transformer) TransformUUIDArray(v *schema.UUIDArray) any {
60+
func (Transformer) TransformUUIDArray(v *schema.UUIDArray) any {
5961
return v.String()
6062
}
6163

62-
func (*Transformer) TransformCIDR(v *schema.CIDR) any {
64+
func (Transformer) TransformCIDR(v *schema.CIDR) any {
6365
return v.String()
6466
}
6567

66-
func (*Transformer) TransformCIDRArray(v *schema.CIDRArray) any {
68+
func (Transformer) TransformCIDRArray(v *schema.CIDRArray) any {
6769
return v.String()
6870
}
6971

70-
func (*Transformer) TransformInet(v *schema.Inet) any {
72+
func (Transformer) TransformInet(v *schema.Inet) any {
7173
return v.String()
7274
}
7375

74-
func (*Transformer) TransformInetArray(v *schema.InetArray) any {
76+
func (Transformer) TransformInetArray(v *schema.InetArray) any {
7577
return v.String()
7678
}
7779

78-
func (*Transformer) TransformMacaddr(v *schema.Macaddr) any {
80+
func (Transformer) TransformMacaddr(v *schema.Macaddr) any {
7981
return v.String()
8082
}
8183

82-
func (*Transformer) TransformMacaddrArray(v *schema.MacaddrArray) any {
84+
func (Transformer) TransformMacaddrArray(v *schema.MacaddrArray) any {
8385
return v.String()
8486
}

json/transformer.go

+23-21
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,46 @@ import (
88
)
99

1010
type ReverseTransformer struct {
11-
defaultTransformer destination.DefaultReverseTransformer
11+
*destination.DefaultReverseTransformer
1212
}
1313

14-
func (t *ReverseTransformer) ReverseTransformValues(table *schema.Table, values []any) (schema.CQTypes, error) {
15-
return t.defaultTransformer.ReverseTransformValues(table, values)
16-
}
14+
var _ interface {
15+
ReverseTransformValues(table *schema.Table, values []any) (schema.CQTypes, error)
16+
} = ReverseTransformer{}
1717

1818
type Transformer struct{}
1919

20-
func (*Transformer) TransformBool(v *schema.Bool) any {
20+
var _ schema.CQTypeTransformer = Transformer{}
21+
22+
func (Transformer) TransformBool(v *schema.Bool) any {
2123
if v.Status != schema.Present {
2224
return nil
2325
}
2426
return v.Bool
2527
}
2628

27-
func (*Transformer) TransformBytea(v *schema.Bytea) any {
29+
func (Transformer) TransformBytea(v *schema.Bytea) any {
2830
if v.Status != schema.Present {
2931
return nil
3032
}
3133
return v.String()
3234
}
3335

34-
func (*Transformer) TransformFloat8(v *schema.Float8) any {
36+
func (Transformer) TransformFloat8(v *schema.Float8) any {
3537
if v.Status != schema.Present {
3638
return nil
3739
}
3840
return v.Float
3941
}
4042

41-
func (*Transformer) TransformInt8(v *schema.Int8) any {
43+
func (Transformer) TransformInt8(v *schema.Int8) any {
4244
if v.Status != schema.Present {
4345
return nil
4446
}
4547
return v.Int
4648
}
4749

48-
func (*Transformer) TransformInt8Array(v *schema.Int8Array) any {
50+
func (Transformer) TransformInt8Array(v *schema.Int8Array) any {
4951
if v.Status != schema.Present {
5052
return nil
5153
}
@@ -56,7 +58,7 @@ func (*Transformer) TransformInt8Array(v *schema.Int8Array) any {
5658
return res
5759
}
5860

59-
func (*Transformer) TransformJSON(v *schema.JSON) any {
61+
func (Transformer) TransformJSON(v *schema.JSON) any {
6062
if v.Status != schema.Present {
6163
return nil
6264
}
@@ -67,14 +69,14 @@ func (*Transformer) TransformJSON(v *schema.JSON) any {
6769
return res
6870
}
6971

70-
func (*Transformer) TransformText(v *schema.Text) any {
72+
func (Transformer) TransformText(v *schema.Text) any {
7173
if v.Status != schema.Present {
7274
return nil
7375
}
7476
return v.Str
7577
}
7678

77-
func (*Transformer) TransformTextArray(v *schema.TextArray) any {
79+
func (Transformer) TransformTextArray(v *schema.TextArray) any {
7880
if v.Status != schema.Present {
7981
return nil
8082
}
@@ -85,21 +87,21 @@ func (*Transformer) TransformTextArray(v *schema.TextArray) any {
8587
return res
8688
}
8789

88-
func (*Transformer) TransformTimestamptz(v *schema.Timestamptz) any {
90+
func (Transformer) TransformTimestamptz(v *schema.Timestamptz) any {
8991
if v.Status != schema.Present {
9092
return nil
9193
}
9294
return v.String()
9395
}
9496

95-
func (*Transformer) TransformUUID(v *schema.UUID) any {
97+
func (Transformer) TransformUUID(v *schema.UUID) any {
9698
if v.Status != schema.Present {
9799
return nil
98100
}
99101
return v.String()
100102
}
101103

102-
func (*Transformer) TransformUUIDArray(v *schema.UUIDArray) any {
104+
func (Transformer) TransformUUIDArray(v *schema.UUIDArray) any {
103105
if v.Status != schema.Present {
104106
return nil
105107
}
@@ -110,14 +112,14 @@ func (*Transformer) TransformUUIDArray(v *schema.UUIDArray) any {
110112
return res
111113
}
112114

113-
func (*Transformer) TransformCIDR(v *schema.CIDR) any {
115+
func (Transformer) TransformCIDR(v *schema.CIDR) any {
114116
if v.Status != schema.Present {
115117
return nil
116118
}
117119
return v.String()
118120
}
119121

120-
func (*Transformer) TransformCIDRArray(v *schema.CIDRArray) any {
122+
func (Transformer) TransformCIDRArray(v *schema.CIDRArray) any {
121123
if v.Status != schema.Present {
122124
return nil
123125
}
@@ -128,14 +130,14 @@ func (*Transformer) TransformCIDRArray(v *schema.CIDRArray) any {
128130
return res
129131
}
130132

131-
func (*Transformer) TransformInet(v *schema.Inet) any {
133+
func (Transformer) TransformInet(v *schema.Inet) any {
132134
if v.Status != schema.Present {
133135
return nil
134136
}
135137
return v.String()
136138
}
137139

138-
func (*Transformer) TransformInetArray(v *schema.InetArray) any {
140+
func (Transformer) TransformInetArray(v *schema.InetArray) any {
139141
if v.Status != schema.Present {
140142
return nil
141143
}
@@ -146,14 +148,14 @@ func (*Transformer) TransformInetArray(v *schema.InetArray) any {
146148
return v.String()
147149
}
148150

149-
func (*Transformer) TransformMacaddr(v *schema.Macaddr) any {
151+
func (Transformer) TransformMacaddr(v *schema.Macaddr) any {
150152
if v.Status != schema.Present {
151153
return nil
152154
}
153155
return v.String()
154156
}
155157

156-
func (*Transformer) TransformMacaddrArray(v *schema.MacaddrArray) any {
158+
func (Transformer) TransformMacaddrArray(v *schema.MacaddrArray) any {
157159
if v.Status != schema.Present {
158160
return nil
159161
}

spec.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func (s *FileSpec) SetDefaults() {
3131
s.jsonSpec.SetDefaults()
3232
}
3333
}
34+
3435
func (s *FileSpec) Validate() error {
3536
if s.Format == "" {
3637
return fmt.Errorf("format is required")

0 commit comments

Comments
 (0)