Rework db layer.

Add database checker.
Rename SkinsRepositoryInterface and CapesRepositoryInterface methods.
This commit is contained in:
ErickSkrauch
2020-04-20 22:18:27 +03:00
parent 632ad4795a
commit a07905ca5a
14 changed files with 335 additions and 354 deletions

37
db/fs/fs.go Normal file
View File

@@ -0,0 +1,37 @@
package fs
import (
"os"
"path"
"strings"
"github.com/elyby/chrly/model"
)
func New(basePath string) (*Filesystem, error) {
return &Filesystem{path: basePath}, nil
}
type Filesystem struct {
path string
}
func (f *Filesystem) FindCapeByUsername(username string) (*model.Cape, error) {
if username == "" {
return nil, nil
}
capePath := path.Join(f.path, strings.ToLower(username)+".png")
file, err := os.Open(capePath)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
return &model.Cape{
File: file,
}, nil
}