Now stores pub key in db. TODO: Why is priv key not getting stored?

This commit is contained in:
Netscape Navigator 2020-08-31 07:31:41 -05:00
parent da85cfb2b5
commit 8d02024ff9
1 changed files with 8 additions and 15 deletions

View File

@ -2,6 +2,7 @@ package pigeon
import ( import (
"database/sql" "database/sql"
"fmt"
"log" "log"
"modernc.org/ql" "modernc.org/ql"
@ -81,23 +82,15 @@ func SetConfig(key string, value []byte) {
// GetConfig retrieves a key/value pair from the database. // GetConfig retrieves a key/value pair from the database.
func GetConfig(key string) []byte { func GetConfig(key string) []byte {
rows, err := Database.Query("SELECT key FROM configs WHERE value = ?1 LIMIT 1", key)
if err != nil {
log.Fatalf("Unable to retrieve config key(1): %s", err)
}
var result string var result string
row := Database.QueryRow("SELECT value FROM configs WHERE key=$1", key)
if rows.Next() { err := row.Scan(&result)
err := rows.Scan(&result) if err != nil {
if err != nil { if err == sql.ErrNoRows {
log.Fatalf("Unable to retrieve config key(2): %s", err) fmt.Println("Zero rows found")
} else {
panic(err)
} }
} }
if len(result) < 1 {
log.Fatalf("Attempted to retrieve non-existent key: %s", key)
}
return []byte(result) return []byte(result)
} }