35 lines
553 B
Go
35 lines
553 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
// External
|
||
|
"github.com/jmoiron/sqlx"
|
||
|
|
||
|
// Standard
|
||
|
)
|
||
|
|
||
|
type Key struct {
|
||
|
ID int
|
||
|
UserID int `db:"user_id"`
|
||
|
Description string
|
||
|
Key string
|
||
|
}
|
||
|
|
||
|
func (session Session) Keys() (keys []Key, err error) {
|
||
|
var rows *sqlx.Rows
|
||
|
if rows, err = db.Queryx(`SELECT * FROM crypto_key WHERE user_id=$1`, session.UserID); err != nil {
|
||
|
return
|
||
|
}
|
||
|
defer rows.Close()
|
||
|
|
||
|
keys = []Key{}
|
||
|
for rows.Next() {
|
||
|
key := Key{}
|
||
|
if err = rows.StructScan(&key); err != nil {
|
||
|
return
|
||
|
}
|
||
|
keys = append(keys, key)
|
||
|
}
|
||
|
|
||
|
return
|
||
|
}
|