Use pointer receiver more offen
This commit is contained in:
parent
6999b4e728
commit
c7569b5e54
59 changed files with 688 additions and 672 deletions
|
@ -24,14 +24,14 @@ type Certificate struct {
|
|||
}
|
||||
|
||||
// GetCertificates returns the list of all generated certificates.
|
||||
func GetCertificates() (certificates []Certificate, err error) {
|
||||
func GetCertificates() (certificates []*Certificate, err error) {
|
||||
var rows *sql.Rows
|
||||
if rows, err = DBQuery("SELECT id_cert, creation, password, revoked FROM certificates ORDER BY creation"); err == nil {
|
||||
defer rows.Close()
|
||||
|
||||
certificates = make([]Certificate, 0)
|
||||
certificates = []*Certificate{}
|
||||
for rows.Next() {
|
||||
var c Certificate
|
||||
c := &Certificate{}
|
||||
if err = rows.Scan(&c.Id, &c.Creation, &c.Password, &c.Revoked); err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -42,9 +42,9 @@ func GetCertificates() (certificates []Certificate, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
|
||||
// GetCertificate retrieves a certificate from its serial number.
|
||||
func GetCertificate(serial uint64) (c Certificate, err error) {
|
||||
func GetCertificate(serial uint64) (c *Certificate, err error) {
|
||||
c = &Certificate{}
|
||||
err = DBQueryRow("SELECT id_cert, creation, password, revoked FROM certificates WHERE id_cert = ?", serial).Scan(&c.Id, &c.Creation, &c.Password, &c.Revoked)
|
||||
return
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func RegisterCertificate(serial uint64, password string) (Certificate, error) {
|
|||
}
|
||||
|
||||
// Update applies modifications back to the database.
|
||||
func (c Certificate) Update() (int64, error) {
|
||||
func (c *Certificate) Update() (int64, error) {
|
||||
if res, err := DBExec("UPDATE certificates SET creation = ?, password = ?, revoked = ? WHERE id_cert = ?", c.Creation, c.Password, c.Revoked, c.Id); err != nil {
|
||||
return 0, err
|
||||
} else if nb, err := res.RowsAffected(); err != nil {
|
||||
|
@ -100,7 +100,6 @@ func (c Certificate) Delete() (int64, error) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// ClearCertificates removes all certificates from database.
|
||||
func ClearCertificates() (int64, error) {
|
||||
if res, err := DBExec("DELETE FROM certificates"); err != nil {
|
||||
|
|
Reference in a new issue