mirror of
https://github.com/elyby/chrly.git
synced 2024-12-11 15:59:18 +05:30
34 lines
527 B
Go
34 lines
527 B
Go
|
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) {
|
||
|
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
|
||
|
}
|