Parcourir la source

Add Close to Context.

Kelly Norton il y a 10 ans
Parent
commit
ca5444011f
3 fichiers modifiés avec 8 ajouts et 0 suppressions
  1. 5 0
      context/context.go
  2. 2 0
      context/context_test.go
  3. 1 0
      main.go

+ 5 - 0
context/context.go

@@ -124,6 +124,11 @@ func Open(path string) (*Context, error) {
 	}, nil
 }
 
+// Close the resources associated with this context.
+func (c *Context) Close() error {
+	return c.db.Close()
+}
+
 // Get retreives a shortcut from the data store.
 func (c *Context) Get(name string) (*Route, error) {
 	val, err := c.db.Get([]byte(name), nil)

+ 2 - 0
context/context_test.go

@@ -21,6 +21,7 @@ func TestGetPut(t *testing.T) {
 	if err != nil {
 		t.Fatal(err)
 	}
+	defer ctx.Close()
 
 	if _, err := ctx.Get("not_found"); err != leveldb.ErrNotFound {
 		t.Fatalf("expected ErrNotFound, got \"%v\"", err)
@@ -60,6 +61,7 @@ func TestNextID(t *testing.T) {
 	if err != nil {
 		t.Fatal(err)
 	}
+	defer ctx.Close()
 
 	var e uint64 = 1
 	for i := 0; i < 501; i++ {

+ 1 - 0
main.go

@@ -28,6 +28,7 @@ func main() {
 	if err != nil {
 		log.Panic(err)
 	}
+	defer ctx.Close()
 
 	log.Panic(web.ListenAndServe(*flagAddr, getVersion(), ctx))
 }