TRA-3234 Fetch command (#54)

* preparation to fetch command

* get har as zip from server

* no message

* no message
This commit is contained in:
gadotroee
2021-05-24 19:29:46 +03:00
committed by GitHub
parent 5cbb5a011e
commit 2f33f9229a
14 changed files with 247 additions and 62 deletions

View File

@@ -1,6 +1,7 @@
package utils
import (
"encoding/json"
"fmt"
"github.com/gofiber/fiber/v2"
"log"
@@ -43,7 +44,6 @@ func ReverseSlice(data interface{}) {
}
}
func CheckErr(e error) {
if e != nil {
log.Printf("%v", e)
@@ -51,7 +51,6 @@ func CheckErr(e error) {
}
}
func SetHostname(address, newHostname string) string {
replacedUrl, err := url.Parse(address)
if err != nil{
@@ -81,3 +80,8 @@ func GetResolvedBaseEntry(entry models.MizuEntry) models.BaseEntryDetails {
RequestSenderIp: entry.RequestSenderIp,
}
}
func GetBytesFromStruct(v interface{}) []byte{
a, _ := json.Marshal(v)
return a
}

20
api/pkg/utils/zip.go Normal file
View File

@@ -0,0 +1,20 @@
package utils
import (
"archive/zip"
"bytes"
)
func ZipData(files map[string][]byte) *bytes.Buffer {
// Create a buffer to write our archive to.
buf := new(bytes.Buffer)
// Create a new zip archive.
zipWriter := zip.NewWriter(buf)
defer func() { _ = zipWriter.Close() }()
for fileName, fileBytes := range files {
zipFile, _ := zipWriter.Create(fileName)
_, _ = zipFile.Write(fileBytes)
}
return buf
}