-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
45 lines (36 loc) · 980 Bytes
/
utils.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
package main
import (
"crypto/md5"
"encoding/base64"
"encoding/hex"
"encoding/json"
)
func ParseInputMessageAsProjectDirectory(message []byte) (InputProjectDir, error) {
var projDir InputProjectDir
err := json.Unmarshal([]byte(message), &projDir)
if err != nil {
return projDir, err
}
decodedCargoToml, err := base64Decoder(projDir.CargoToml)
if err != nil {
return projDir, err
}
projDir.CargoToml = string(decodedCargoToml)
decodedMainRs, err := base64Decoder(projDir.MainRs)
if err != nil {
return projDir, err
}
projDir.MainRs = string(decodedMainRs)
return projDir, nil
}
func GetMd5StringOfInput(input string) string {
hashAsByteArray := md5.Sum([]byte(input))
hashAsString := hex.EncodeToString(hashAsByteArray[:])
return hashAsString
}
func base64Decoder(input string) ([]byte, error) {
return base64.StdEncoding.DecodeString(input)
}
func base64Encoder(input string) string {
return base64.StdEncoding.EncodeToString([]byte(input))
}