aboutsummaryrefslogtreecommitdiff
path: root/util/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'util/util.go')
-rw-r--r--util/util.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/util/util.go b/util/util.go
index 0126556..9c1ba97 100644
--- a/util/util.go
+++ b/util/util.go
@@ -4,6 +4,7 @@ import (
"crypto/sha256"
"database/sql"
"encoding/hex"
+ "errors"
"fmt"
"io/ioutil"
"mime/multipart"
@@ -213,7 +214,7 @@ func CreateUniqueID(actor string) (string, error) {
args := fmt.Sprintf("%s/%s/%s", config.Domain, actor, newID)
rows, err := config.DB.Query(query, args)
if err != nil {
- return "", err
+ return "", MakeError(err, "CreateUniqueID")
}
defer rows.Close()
@@ -236,7 +237,7 @@ func GetFileContentType(out multipart.File) (string, error) {
_, err := out.Read(buffer)
if err != nil {
- return "", err
+ return "", MakeError(err, "GetFileContentType")
}
out.Seek(0, 0)
@@ -269,7 +270,7 @@ func LoadThemes() {
// get list of themes
themes, err := ioutil.ReadDir("./static/css/themes")
if err != nil {
- panic(err)
+ MakeError(err, "LoadThemes")
}
for _, f := range themes {
@@ -287,14 +288,14 @@ func GetBoardAuth(board string) ([]string, error) {
var rows *sql.Rows
var err error
if rows, err = config.DB.Query(query, board); err != nil {
- return auth, err
+ return auth, MakeError(err, "GetBoardAuth")
}
defer rows.Close()
for rows.Next() {
var _type string
if err := rows.Scan(&_type); err != nil {
- return auth, err
+ return auth, MakeError(err, "GetBoardAuth")
}
auth = append(auth, _type)
@@ -302,3 +303,12 @@ func GetBoardAuth(board string) ([]string, error) {
return auth, nil
}
+
+func MakeError(err error, msg string) error {
+ if err != nil {
+ s := fmt.Sprintf("%s: %s", msg, err.Error())
+ return errors.New(s)
+ }
+
+ return nil
+}