forked from aliyun/aliyun-log-go-sdk
/
oss_shipper_config.go
63 lines (54 loc) · 1.57 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
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 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"`
}
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,
})
}