Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/s-gv/orangeforum
Browse files Browse the repository at this point in the history
  • Loading branch information
s-gv committed Jun 13, 2021
2 parents 045c0bd + 1a6723c commit e6600be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func main() {

views.SecretKey = os.Getenv("SECRET_KEY") // Ex: "s6JM1e8JTAphtKNR2y27XA8kkAaXOSYB" // 32 byte long
if len(views.SecretKey) != 32 {
glog.Errorf("Invalid Secret Key")
glog.Errorf("Invalid Secret Key. Using randomly generated key. This will invalidate any active sessions.")

var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
b := make([]rune, 32)
Expand Down
16 changes: 10 additions & 6 deletions models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package models

import "database/sql"

const (
ForumName = "forum_name"

Expand All @@ -14,10 +16,6 @@ const (
DefaultFromMail = "default_from_mail"
)

func CreateConfigValue(key string, val string) {
DB.Exec("INSERT INTO configs(name, val) VALUES($1, $2);", key, val)
}

func GetConfigValue(key string) string {
var val string
err := DB.Get(&val, "SELECT val FROM configs WHERE name=$1;", key)
Expand All @@ -27,6 +25,12 @@ func GetConfigValue(key string) string {
return val
}

func UpdateConfigValue(key string, val string) {
DB.Exec("UPDATE configs SET val = $1 WHERE name=$2;", val, key)
func SetConfigValue(key string, val string) {
var dummy string
err := DB.Get(&dummy, "SELECT val FROM configs WHERE name=$1;", key)
if err == sql.ErrNoRows {
DB.Exec("INSERT INTO configs(name, val) VALUES($1, $2);", key, val)
} else {
DB.Exec("UPDATE configs SET val = $1 WHERE name=$2;", val, key)
}
}

0 comments on commit e6600be

Please sign in to comment.