From b62b3039950ce6caec038c0f98591b085c4c5d51 Mon Sep 17 00:00:00 2001 From: Las Zenow Date: Sun, 4 Sep 2016 12:33:53 -0400 Subject: [PATCH] Helper functions for the migration scripts --- lib/database/users.go | 6 +++++- lib/parser/parser.go | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/database/users.go b/lib/database/users.go index 79eeab3..4cf1c3f 100644 --- a/lib/database/users.go +++ b/lib/database/users.go @@ -36,11 +36,15 @@ func (db *pgDB) AddUser(name string, pass string) error { log.Error("Error hashing password: ", err) return errors.New("An error happen storing the password") } + return db.AddRawUser(name, hpass, salt, "") +} + +func (db *DB) AddRawUser(name string, hpass []byte, salt []byte, role string) error { u := user{ Username: name, Password: hpass, Salt: salt, - Role: "", + Role: role, } return db.sql.Create(&u) } diff --git a/lib/parser/parser.go b/lib/parser/parser.go index 9d87b5d..26fad63 100644 --- a/lib/parser/parser.go +++ b/lib/parser/parser.go @@ -27,7 +27,7 @@ func EpubMetadata(epub *epubgo.Epub) database.Book { case "description": book.Description = parseDescription(data) case "subject": - book.Tags = parseSubject(data) + book.Tags = ParseSubject(data) case "date": book.Date = parseDate(data) case "language": @@ -88,7 +88,7 @@ func parseDescription(description []string) string { return str } -func parseSubject(subject []string) []string { +func ParseSubject(subject []string) []string { parsed := subject for _, sep := range []string{"/", ","} { p2 := []string{}