storageDao.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package dao
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "io"
  6. "strings"
  7. "github.com/willie68/schematic-service-go/model"
  8. )
  9. /*
  10. StorageDao this is the interface which all method implementation of a storage engine has to fulfill
  11. */
  12. type StorageDao interface {
  13. AddFile(filename string, reader io.Reader) (string, error)
  14. CreateSchematic(schematic model.Schematic) (string, error)
  15. GetSchematic(schematicID string) (model.Schematic, error)
  16. UpdateSchematic(schematic model.Schematic) (string, error)
  17. GetFilename(fileid string) (string, error)
  18. GetFile(fileid string, stream io.Writer) error
  19. GetSchematics(query string, offset int, limit int, owner string) (int64, []model.Schematic, error)
  20. GetSchematicsCount(query string, owner string) (int64, error)
  21. DeleteSchematic(schematicID string) error
  22. CreateTag(tag string) error
  23. GetTags() []model.Tag
  24. GetTagsCount() int
  25. CreateManufacturer(manufacturer string) error
  26. GetManufacturers() []model.Manufacturer
  27. GetManufacturersCount() int
  28. CreateEffectType(effectType model.EffectType) (string, error)
  29. GetEffectTypes() ([]model.EffectType, error)
  30. CreateEffect(effect model.Effect) (string, error)
  31. GetEffectsCount(query string) (int, error)
  32. GetEffects(query string, offset int, limit int) (int, []model.Effect, error)
  33. GetEffect(effectID string) (model.Effect, error)
  34. CheckUser(username string, password string) bool
  35. GetUser(username string) (model.User, bool)
  36. AddUser(user model.User) error
  37. DeleteUser(username string) error
  38. ChangePWD(username string, newpassword string, oldpassword string) error
  39. DropAll()
  40. Ping() error
  41. Backup(path string) error
  42. Stop()
  43. }
  44. var Storage StorageDao
  45. func GetStorage() StorageDao {
  46. return Storage
  47. }
  48. func BuildPasswordHash(password string) string {
  49. if !strings.HasPrefix(password, "md5:") {
  50. hash := md5.Sum([]byte(password))
  51. password = fmt.Sprintf("md5:%x", hash)
  52. }
  53. return password
  54. }