/
types.go
46 lines (37 loc) · 903 Bytes
/
types.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
// Copyright (c) Alex Ellis 2017. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package types
import (
"encoding/json"
"net/http"
"os"
)
// OsEnv implements interface to wrap os.Getenv
type OsEnv struct {
}
// Getenv wraps os.Getenv
func (OsEnv) Getenv(key string) string {
return os.Getenv(key)
}
type MarshalBody struct {
Raw []byte `json:"raw"`
}
type MarshalReq struct {
Header http.Header `json:"header"`
Body MarshalBody `json:"body"`
}
func UnmarshalRequest(data []byte) (*MarshalReq, error) {
request := MarshalReq{}
err := json.Unmarshal(data, &request)
return &request, err
}
func MarshalRequest(data []byte, header *http.Header) ([]byte, error) {
req := MarshalReq{
Body: MarshalBody{
Raw: data,
},
Header: *header,
}
res, marshalErr := json.Marshal(&req)
return res, marshalErr
}