Skip to content

Commit

Permalink
fix:remove unwanted panic
Browse files Browse the repository at this point in the history
  • Loading branch information
eeczw committed Feb 24, 2022
1 parent ac5ec26 commit e04933d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/leveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ var dbPath = "/var/lib/trojan-manager"
// GetValue 获取leveldb值
func GetValue(key string) (string, error) {
db, err := leveldb.OpenFile(dbPath, nil)
defer db.Close()
if err != nil {
return "", err
}
defer db.Close()
result, err := db.Get([]byte(key), nil)
if err != nil {
return "", err
Expand All @@ -23,19 +23,19 @@ func GetValue(key string) (string, error) {
// SetValue 设置leveldb值
func SetValue(key string, value string) error {
db, err := leveldb.OpenFile(dbPath, nil)
defer db.Close()
if err != nil {
return err
}
defer db.Close()
return db.Put([]byte(key), []byte(value), nil)
}

// DelValue 删除值
func DelValue(key string) error {
db, err := leveldb.OpenFile(dbPath, nil)
defer db.Close()
if err != nil {
return err
}
defer db.Close()
return db.Delete([]byte(key), nil)
}

0 comments on commit e04933d

Please sign in to comment.