Finished first pass on the full cycle

Need to do some testing, then start on the web frontend
This commit is contained in:
Tim Shannon
2016-04-01 19:30:17 +00:00
parent 6f53ea70c0
commit 0472b31877
5 changed files with 323 additions and 95 deletions

View File

@@ -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 {

View File

@@ -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
}