-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathzEncodeBase64.go
More file actions
48 lines (36 loc) · 886 Bytes
/
zEncodeBase64.go
File metadata and controls
48 lines (36 loc) · 886 Bytes
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
package netroutine
import (
"context"
"encoding/base64"
"encoding/json"
)
const idEncodeBase64 = "EncodeBase64"
func init() {
blocks[idEncodeBase64] = &EncodeBase64{}
}
type EncodeBase64 struct {
FromKey string
ToKey string
}
func (b *EncodeBase64) toBytes() ([]byte, error) {
return json.Marshal(b)
}
func (b *EncodeBase64) fromBytes(bytes []byte) error {
return json.Unmarshal(bytes, b)
}
func (b *EncodeBase64) kind() string {
return idEncodeBase64
}
func (b *EncodeBase64) Run(ctx context.Context, wce *Environment) (string, Status) {
v, ok := wce.getData(b.FromKey)
if !ok {
return log(b, missingWorkingData(b.FromKey), Error)
}
s, err := toString(v)
if err != nil {
return log(b, reportWrongType(b.FromKey), Error)
}
e := base64.StdEncoding.EncodeToString([]byte(s))
wce.setData(b.ToKey, e)
return log(b, setWorkingData(b.ToKey, e), Success)
}