diff options
author | FChannel <> | 2022-05-07 21:21:38 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | f7bf818d29393ceaccf4d2906557351fa6a4f49f (patch) | |
tree | 723e542c8cf0db1e7e64923718977138db77b58d /util/util.go | |
parent | 3c5eebf6275e6d202f8a7b7f027aabcda5c1f332 (diff) |
added error func and general cleanup/organization
Diffstat (limited to 'util/util.go')
-rw-r--r-- | util/util.go | 20 |
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 +} |