feat: Update project structure and configuration files
This commit is contained in:
26
backend/pkg/utils/buffer.go
Normal file
26
backend/pkg/utils/buffer.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
)
|
||||
|
||||
// NewLogBuffer creates a buffer that can be used to capture output stream
|
||||
// and write to a logger in real time
|
||||
func NewLogBuffer(output func(string)) io.Writer {
|
||||
reader, writer := io.Pipe()
|
||||
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(reader)
|
||||
for scanner.Scan() {
|
||||
output(scanner.Text())
|
||||
}
|
||||
}()
|
||||
|
||||
return writer
|
||||
}
|
||||
|
||||
// NewCombinedBuffer combines multiple io.Writers
|
||||
func NewCombinedBuffer(writers ...io.Writer) io.Writer {
|
||||
return io.MultiWriter(writers...)
|
||||
}
|
||||
33
backend/pkg/utils/md5.go
Normal file
33
backend/pkg/utils/md5.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Compare file md5
|
||||
func CompareFileMd5(file, md5 string) (bool, error) {
|
||||
fileMd5, err := GetFileMd5(file)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return fileMd5 == md5, nil
|
||||
}
|
||||
|
||||
// GetFileMd5
|
||||
func GetFileMd5(file string) (string, error) {
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
h := md5.New()
|
||||
if _, err := io.Copy(h, f); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%x", h.Sum(nil)), nil
|
||||
}
|
||||
Reference in New Issue
Block a user