Re-arrange modules
This commit is contained in:
parent
d86e3cd944
commit
b965fece13
|
@ -42,14 +42,14 @@ Don't use the Go version yet. If you want something stable, there is a [Ruby ver
|
|||
Without coverage:
|
||||
|
||||
```
|
||||
cd
|
||||
go test -run pigeon
|
||||
go test -v ./...
|
||||
```
|
||||
|
||||
With coverage:
|
||||
|
||||
```
|
||||
go test -run pigeon -coverprofile cp.out
|
||||
go test -v ./... -coverprofile coverage.out
|
||||
go tool cover -html=coverage.out
|
||||
```
|
||||
|
||||
# Build Project
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
mode: set
|
||||
pigeon/pigeon/version.go:13.47,16.3 2 0
|
||||
pigeon/pigeon/version.go:19.13,21.2 1 1
|
||||
pigeon/pigeon/b32.go:12.36,14.2 1 1
|
||||
pigeon/pigeon/b32.go:18.37,20.18 2 1
|
||||
pigeon/pigeon/b32.go:25.2,25.15 1 1
|
||||
pigeon/pigeon/b32.go:20.18,22.13 2 0
|
||||
pigeon/pigeon/create.go:13.47,15.3 1 0
|
||||
pigeon/pigeon/create.go:22.47,24.3 1 0
|
||||
pigeon/pigeon/create.go:27.13,30.2 2 1
|
||||
pigeon/pigeon/db.go:7.30,9.16 2 0
|
||||
pigeon/pigeon/db.go:12.2,21.16 2 0
|
||||
pigeon/pigeon/db.go:24.2,24.35 1 0
|
||||
pigeon/pigeon/db.go:27.2,27.12 1 0
|
||||
pigeon/pigeon/db.go:9.16,11.3 1 0
|
||||
pigeon/pigeon/db.go:21.16,23.3 1 0
|
||||
pigeon/pigeon/db.go:24.35,26.3 1 0
|
||||
pigeon/pigeon/db.go:30.33,32.16 2 0
|
||||
pigeon/pigeon/db.go:35.2,38.16 2 0
|
||||
pigeon/pigeon/db.go:41.2,41.35 1 0
|
||||
pigeon/pigeon/db.go:44.2,44.12 1 0
|
||||
pigeon/pigeon/db.go:32.16,34.3 1 0
|
||||
pigeon/pigeon/db.go:38.16,40.3 1 0
|
||||
pigeon/pigeon/db.go:41.35,43.3 1 0
|
||||
pigeon/pigeon/root.go:22.47,24.3 1 0
|
||||
pigeon/pigeon/root.go:29.16,30.42 1 0
|
||||
pigeon/pigeon/root.go:30.42,33.3 2 0
|
||||
pigeon/pigeon/root.go:36.13,48.2 3 1
|
||||
pigeon/pigeon/root.go:51.19,52.19 1 0
|
||||
pigeon/pigeon/root.go:68.2,71.45 2 0
|
||||
pigeon/pigeon/root.go:52.19,55.3 1 0
|
||||
pigeon/pigeon/root.go:55.8,58.17 2 0
|
||||
pigeon/pigeon/root.go:64.3,65.33 2 0
|
||||
pigeon/pigeon/root.go:58.17,61.4 2 0
|
||||
pigeon/pigeon/root.go:71.45,73.3 1 0
|
||||
pigeon/pigeon/util.go:12.62,14.16 2 0
|
||||
pigeon/pigeon/util.go:19.2,19.18 1 0
|
||||
pigeon/pigeon/util.go:14.16,17.3 2 0
|
||||
pigeon/pigeon/util.go:25.63,29.2 3 0
|
||||
pigeon/pigeon/util.go:32.27,35.2 2 0
|
||||
pigeon/pigeon/util.go:39.44,43.21 3 0
|
||||
pigeon/pigeon/util.go:48.2,48.44 1 0
|
||||
pigeon/pigeon/util.go:43.21,46.3 2 0
|
|
@ -1,5 +1,8 @@
|
|||
package pigeon
|
||||
|
||||
// Version is the current version of Pigeon CLI
|
||||
const Version = "0.0.0"
|
||||
|
||||
// BlobSigil is a string identifier that precedes a base32
|
||||
// hash (SHA256) representing arbitrary data.
|
||||
const BlobSigil = "FILE."
|
||||
|
@ -15,3 +18,7 @@ const UserSigil = "USER."
|
|||
// StringSigil is a character used to identify strings as
|
||||
// defined by the pigeon protocol spec.
|
||||
const StringSigil = "\""
|
||||
|
||||
// DefaultDBPath describes the default storage location for
|
||||
// the database instance.
|
||||
const DefaultDBPath = "./pigeondb"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package cmd
|
||||
package pigeon
|
||||
|
||||
import (
|
||||
"fmt"
|
88
pigeon/db.go
88
pigeon/db.go
|
@ -1,63 +1,45 @@
|
|||
package pigeon
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/xujiajun/nutsdb"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
// Database will open the NutsDB database.
|
||||
func createDB() *nutsdb.DB {
|
||||
// Open the database located in the /tmp/nutsdb directory.
|
||||
// It will be created if it doesn't exist.
|
||||
opt := nutsdb.DefaultOptions
|
||||
opt.Dir = "./pigeondb"
|
||||
db, err := nutsdb.Open(opt)
|
||||
func setUp(db *sql.DB) error {
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
return db
|
||||
_, err = tx.Exec(`
|
||||
CREATE TABLE note (
|
||||
id BIGINT
|
||||
,title STRING
|
||||
,body STRING
|
||||
,created_at STRING
|
||||
,updated_at STRING
|
||||
);
|
||||
`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var database = createDB()
|
||||
var configBucket = "config"
|
||||
|
||||
// A ConfigKey represents a key used within the NutsDB
|
||||
// "config" bucket.
|
||||
type ConfigKey string
|
||||
|
||||
const (
|
||||
// ConfigSecret is the binary representation of the users
|
||||
// ED25519 secret key.
|
||||
ConfigSecret ConfigKey = "secret"
|
||||
)
|
||||
|
||||
// PutConfig writes a configuration value to NutsDB
|
||||
func PutConfig(k ConfigKey, v []byte) {
|
||||
database.Update(func(tx *nutsdb.Tx) error {
|
||||
err1 := tx.Put(configBucket, []byte(k), v, 0)
|
||||
if err1 != nil {
|
||||
log.Fatal(err1)
|
||||
}
|
||||
err2 := tx.Commit()
|
||||
if err2 != nil {
|
||||
log.Fatal(err2)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// GetConfig retrieves aconfiguration key from NutsDB
|
||||
func GetConfig(k ConfigKey) []byte {
|
||||
var output []byte
|
||||
database.View(
|
||||
func(tx *nutsdb.Tx) error {
|
||||
val, err1 := tx.Get(configBucket, []byte(k))
|
||||
if err1 != nil {
|
||||
log.Fatal(err1)
|
||||
}
|
||||
output = val.Value
|
||||
return nil
|
||||
})
|
||||
return output
|
||||
func tearDown(db *sql.DB) error {
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(`
|
||||
DROP TABLE note;
|
||||
`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package cmd
|
||||
package pigeon
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -7,9 +7,6 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
// Version is the current version of Pigeon CLI
|
||||
const Version = "0.0.0"
|
||||
|
||||
// CreateKeypair makes a new ED25519 key pair. Just a thin
|
||||
// wrapper around crypto/ed25519.
|
||||
func createKeypair() (ed25519.PublicKey, ed25519.PrivateKey) {
|
||||
|
@ -27,13 +24,14 @@ func createKeypair() (ed25519.PublicKey, ed25519.PrivateKey) {
|
|||
// as a Base32 encoded string
|
||||
func CreateIdentity() (ed25519.PublicKey, ed25519.PrivateKey) {
|
||||
pub, priv := createKeypair()
|
||||
PutConfig(ConfigSecret, priv)
|
||||
fmt.Println("Add persistence here")
|
||||
return pub, priv
|
||||
}
|
||||
|
||||
// GetIdentity retrieves the user's signing key
|
||||
func GetIdentity() []byte {
|
||||
return GetConfig(ConfigSecret)
|
||||
fmt.Println("Add database query here")
|
||||
return []byte{}
|
||||
}
|
||||
|
||||
// EncodeUserMhash Takes a []byte and converts it to a B32
|
||||
|
|
|
@ -74,7 +74,8 @@ func TestB32Decode(t *testing.T) {
|
|||
}
|
||||
for j, x := range expected {
|
||||
if actual[j] != x {
|
||||
fmt.Printf("tests[%d].encoded[%d] did not decode B32 properly (%s)", j, i, test.encoded)
|
||||
msg := "tests[%d].encoded[%d] did not decode B32 properly (%s)"
|
||||
fmt.Printf(msg, j, i, test.encoded)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package cmd
|
||||
package pigeon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"pigeon/pigeon"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -12,7 +11,7 @@ var versionCmd = &cobra.Command{
|
|||
Short: "Show the version of the Pigeon CLI tool.",
|
||||
Long: ``,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
result := fmt.Sprintf("Pigeon v%s", pigeon.Version)
|
||||
result := fmt.Sprintf("Pigeon v%s", Version)
|
||||
fmt.Println(result)
|
||||
},
|
||||
}
|
Loading…
Reference in New Issue