forked from galaxydi/go-loghub
-
Notifications
You must be signed in to change notification settings - Fork 113
/
oss_shipper_config.go
90 lines (77 loc) · 2.3 KB
/
oss_shipper_config.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package sls
import (
"encoding/json"
"fmt"
)
const (
OSSShipperType = "oss"
)
type Shipper struct {
ShipperName string `json:"shipperName"`
TargetType string `json:"targetType"`
RawTargetConfiguration json.RawMessage `json:"targetConfiguration"`
TargetConfiguration interface{} `json:"-"`
}
type shipperAlias Shipper
type shipperDisplay struct {
ShipperName string `json:"shipperName"`
TargetType string `json:"targetType"`
TargetConfiguration interface{} `json:"targetConfiguration"`
}
type OssStoreageCsvDetail struct {
Delimiter string `json:"delemiter"`
Header bool `json:"header"`
LineFeed string `json:"lineFeed"`
Columns []string `json:"columns"`
NullIdentifier string `json:"nullIdentfifier"`
Quote string `json:"quote"`
}
type ParquetConfig struct {
Name string `json:"name"`
Type string `json:"type"`
}
type OssStoreageParquet struct {
Columns []ParquetConfig `json:"columns"`
}
type OSSShipperConfig struct {
OssBucket string `json:"ossBucket"`
OssPrefix string `json:"ossPrefix"`
RoleArn string `json:"roleArn"`
BufferInterval int `json:"bufferInterval"`
BufferSize int `json:"bufferSize"`
CompressType string `json:"compressType"`
PathFormat string `json:"pathFormat"`
Format string `json:"format"`
Storage ShipperStorage `json:"storage"`
}
type ShipperStorage struct {
Format string `json:"format"`
Detail interface{} `json:"detail"`
}
type OssStorageJsonDetail struct {
EnableTag bool `json:"enableTag"`
}
func (s *Shipper) UnmarshalJSON(data []byte) error {
tmp := shipperAlias{}
if err := json.Unmarshal(data, &tmp); err != nil {
return err
}
if tmp.TargetType == OSSShipperType {
oc := &OSSShipperConfig{}
if err := json.Unmarshal(tmp.RawTargetConfiguration, oc); err != nil {
return err
}
tmp.TargetConfiguration = oc
} else {
return fmt.Errorf("unknown target type %s", tmp.TargetType)
}
*s = Shipper(tmp)
return nil
}
func (s *Shipper) MarshalJSON() ([]byte, error) {
return json.Marshal(shipperDisplay{
ShipperName: s.ShipperName,
TargetType: s.TargetType,
TargetConfiguration: s.TargetConfiguration,
})
}