feat(upload): add first prototype of File storage, svg database and svg processing. Also added --help command
All checks were successful
build / Go-Build (push) Successful in 1m5s
All checks were successful
build / Go-Build (push) Successful in 1m5s
This commit is contained in:
50
pkg/svg/storage.go
Normal file
50
pkg/svg/storage.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package svg
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type SvgStorage interface {
|
||||
Create(id string, svg io.Reader) (string, error)
|
||||
Get(id string) (io.Reader, error)
|
||||
}
|
||||
|
||||
type FileSvgStorage struct {
|
||||
basepath string
|
||||
}
|
||||
|
||||
func NewFileStorage(path string) *FileSvgStorage {
|
||||
err := os.MkdirAll(path, 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &FileSvgStorage{path}
|
||||
}
|
||||
|
||||
func (f FileSvgStorage) Create(id string, svg io.Reader) (string, error) {
|
||||
file, err := os.Create(filepath.Join(f.basepath, id+".svg"))
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
_, err = io.Copy(file, svg)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
log.Println("Created File: ", file.Name())
|
||||
return file.Name(), nil
|
||||
}
|
||||
|
||||
func (f FileSvgStorage) Get(id string) (io.Reader, error) {
|
||||
file, err := os.Open(filepath.Join(f.basepath, "svg", id+".svg"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return file, nil
|
||||
}
|
||||
Reference in New Issue
Block a user