cdb_r.go 783 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package main
  2. import (
  3. "fmt"
  4. //"os"
  5. "bytes"
  6. "github.com/repustate/go-cdb"
  7. )
  8. type rec struct {
  9. key string
  10. values []string
  11. }
  12. func main() {
  13. name := "test.cdb"
  14. r, err := cdb.NewReader(name)
  15. if err != nil {
  16. fmt.Printf("Failed opening database %q : %s\n", name, err)
  17. }
  18. defer r.Close()
  19. ok := r.Exists([]byte("two"), 0)
  20. if !ok {
  21. fmt.Printf("Expected to find key 'one' in tag 0 but did not.\n")
  22. }
  23. ok = r.Exists([]byte("two"), 1)
  24. if ok {
  25. fmt.Printf("Expected to not find key 'one' in tag 1 but did.\n")
  26. }
  27. v, ok := r.First([]byte("two"), 0)
  28. if !ok {
  29. fmt.Printf("Expected to find key 'one' in tag 0 but did not.\n")
  30. }
  31. if bytes.Compare(v, []byte("1")) != 0 {
  32. fmt.Printf("Expected value []byte{1} but got %#v.\n", v)
  33. }
  34. fmt.Printf("%s", string(v))
  35. }