Finished first pass on the full cycle
Need to do some testing, then start on the web frontend
This commit is contained in:
@@ -64,11 +64,7 @@ func Open(filename string) (*Store, error) {
|
||||
|
||||
// Close closes the bolt datastore
|
||||
func (ds *Store) Close() error {
|
||||
if ds != nil {
|
||||
return ds.Close()
|
||||
}
|
||||
|
||||
return nil
|
||||
return ds.Close()
|
||||
}
|
||||
|
||||
func (ds *Store) get(bucket string, key TimeKey, result interface{}) error {
|
||||
|
@@ -4,7 +4,12 @@
|
||||
|
||||
package datastore
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
)
|
||||
|
||||
type log struct {
|
||||
When time.Time `json:"when"`
|
||||
@@ -28,3 +33,32 @@ func (ds *Store) AddLog(version, stage, entry string) error {
|
||||
|
||||
return ds.put(bucketLog, key, data)
|
||||
}
|
||||
|
||||
// LatestVersion returns the latest version for the current project
|
||||
func (ds *Store) LatestVersion() (string, error) {
|
||||
version := ""
|
||||
|
||||
err := ds.bolt.View(func(tx *bolt.Tx) error {
|
||||
c := tx.Bucket([]byte(bucketLog)).Cursor()
|
||||
|
||||
for k, v := c.Last(); k != nil; k, v = c.Prev() {
|
||||
l := &log{}
|
||||
err := json.Unmarshal(v, l)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if l.Version != "" {
|
||||
version = l.Version
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return ErrNotFound
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return version, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user