Skip to content

Commit a57fa8d

Browse files
Moved database to own module.
This allows go-hash to be used as a library.
1 parent a679ea1 commit a57fa8d

File tree

6 files changed

+15
-6
lines changed

6 files changed

+15
-6
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ vendor: $(GODEP) Gopkg.toml Gopkg.lock
2020
bench: vendor
2121
go test -bench .
2222
cd encryption && go test -bench=.
23+
cd gohash_db && go test -bench=.
2324

2425
# runs all tests
2526
.PHONY: test

commands.go

+7
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@ import (
1212
"time"
1313

1414
"github.com/renatoathaydes/go-hash/encryption"
15+
"github.com/renatoathaydes/go-hash/gohash_db"
1516

1617
"github.com/atotto/clipboard"
1718
"github.com/chzyer/readline"
1819
"golang.org/x/crypto/ssh/terminal"
1920
)
2021

22+
// State local alias
23+
type State = gohash_db.State
24+
25+
// LoginInfo local alias
26+
type LoginInfo = gohash_db.LoginInfo
27+
2128
type command interface {
2229
// run a command with the given state, within the given group.
2330
run(state *State, group string, args string, reader *bufio.Reader)

data.go gohash_db/data.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package gohash_db
22

33
import (
44
"bytes"

database.go gohash_db/database.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package gohash_db
22

33
import (
44
"errors"

database_test.go gohash_db/database_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package gohash_db
22

33
import (
44
"os"

main.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/chzyer/readline"
1616
"github.com/mitchellh/go-homedir"
17+
"github.com/renatoathaydes/go-hash/gohash_db"
1718
"golang.org/x/crypto/ssh/terminal"
1819
)
1920

@@ -89,7 +90,7 @@ func openDatabase(dbFilePath string) (state State, userPass string) {
8990
panic(err)
9091
}
9192
userPass = string(bytePassword)
92-
state, err = ReadDatabase(dbFilePath, userPass)
93+
state, err = gohash_db.ReadDatabase(dbFilePath, userPass)
9394
if err != nil {
9495
println("Error: " + err.Error())
9596
} else {
@@ -177,7 +178,7 @@ Loop:
177178
command := commands[cmd]
178179
if command != nil {
179180
command.run(state, grBox.value, args, reader)
180-
err := WriteDatabase(dbPath, mpBox.value, state)
181+
err := gohash_db.WriteDatabase(dbPath, mpBox.value, state)
181182
if err != nil {
182183
println("Error writing to database: " + err.Error())
183184
}
@@ -191,7 +192,7 @@ Loop:
191192
func main() {
192193
var userPass string
193194
var state State
194-
println("Go-Hash version " + DBVersion)
195+
println("Go-Hash version " + gohash_db.DBVersion)
195196
println("")
196197

197198
var dbFilePath string

0 commit comments

Comments
 (0)