package dao import ( "crypto/md5" "fmt" "io" "strings" "github.com/willie68/schematic-service-go/model" ) /* StorageDao this is the interface which all method implementation of a storage engine has to fulfill */ type StorageDao interface { AddFile(filename string, reader io.Reader) (string, error) CreateSchematic(schematic model.Schematic) (string, error) GetSchematic(schematicID string) (model.Schematic, error) UpdateSchematic(schematic model.Schematic) (string, error) GetFilename(fileid string) (string, error) GetFile(fileid string, stream io.Writer) error GetSchematics(query string, offset int, limit int, owner string) (int64, []model.Schematic, error) GetSchematicsCount(query string, owner string) (int64, error) DeleteSchematic(schematicID string) error CreateTag(tag string) error GetTags() []model.Tag GetTagsCount() int CreateManufacturer(manufacturer string) error GetManufacturers() []model.Manufacturer GetManufacturersCount() int CreateEffectType(effectType model.EffectType) (string, error) GetEffectTypes() ([]model.EffectType, error) CreateEffect(effect model.Effect) (string, error) GetEffectsCount(query string) (int, error) GetEffects(query string, offset int, limit int) (int, []model.Effect, error) GetEffect(effectID string) (model.Effect, error) CheckUser(username string, password string) bool GetUser(username string) (model.User, bool) AddUser(user model.User) error DeleteUser(username string) error ChangePWD(username string, newpassword string, oldpassword string) error DropAll() Ping() error Backup(path string) error Stop() } var Storage StorageDao func GetStorage() StorageDao { return Storage } func BuildPasswordHash(password string) string { if !strings.HasPrefix(password, "md5:") { hash := md5.Sum([]byte(password)) password = fmt.Sprintf("md5:%x", hash) } return password }