2017-06-30 21:10:25 +05:30
|
|
|
package files
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"elyby/minecraft-skinsystem/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
type filesDb struct {
|
|
|
|
path string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repository *filesDb) FindByUsername(username string) (model.Cape, error) {
|
|
|
|
var record model.Cape
|
2017-08-09 21:41:53 +05:30
|
|
|
if username == "" {
|
|
|
|
return record, CapeNotFoundError{username}
|
|
|
|
}
|
|
|
|
|
2017-06-30 21:10:25 +05:30
|
|
|
capePath := path.Join(repository.path, strings.ToLower(username) + ".png")
|
|
|
|
file, err := os.Open(capePath)
|
|
|
|
if err != nil {
|
2017-07-02 06:05:38 +05:30
|
|
|
return record, CapeNotFoundError{username}
|
2017-06-30 21:10:25 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
record.File = file
|
|
|
|
|
|
|
|
return record, nil
|
|
|
|
}
|