-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from Impa10r/v1.5.3
v1.5.3
- Loading branch information
Showing
29 changed files
with
3,735 additions
and
2,518 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
DEBUG=1 | ||
NETWORK="testnet" | ||
NETWORK="testnet" | ||
NO_HTTPS="true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package db | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"path" | ||
"peerswap-web/cmd/psweb/config" | ||
|
||
"go.etcd.io/bbolt" | ||
) | ||
|
||
// Save saves any object to the Bolt database | ||
func Save(bucketName string, key string, value interface{}) error { | ||
// Open the Bolt database | ||
db, err := bbolt.Open(path.Join(config.Config.DataDir, "psweb.db"), 0600, nil) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer db.Close() | ||
|
||
return db.Update(func(tx *bbolt.Tx) error { | ||
b, err := tx.CreateBucketIfNotExists([]byte(bucketName)) | ||
if err != nil { | ||
return err | ||
} | ||
data, err := json.Marshal(value) | ||
if err != nil { | ||
return err | ||
} | ||
return b.Put([]byte(key), data) | ||
}) | ||
} | ||
|
||
// Load loads any object from the Bolt database | ||
func Load(bucketName string, key string, result interface{}) error { | ||
// Open the Bolt database | ||
db, err := bbolt.Open(path.Join(config.Config.DataDir, "psweb.db"), 0600, nil) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer db.Close() | ||
|
||
return db.View(func(tx *bbolt.Tx) error { | ||
b := tx.Bucket([]byte(bucketName)) | ||
if b == nil { | ||
return fmt.Errorf("bucket %s not found", bucketName) | ||
} | ||
data := b.Get([]byte(key)) | ||
if data == nil { | ||
return fmt.Errorf("key %s not found in bucket %s", key, bucketName) | ||
} | ||
return json.Unmarshal(data, result) | ||
}) | ||
} |
Oops, something went wrong.