-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
65 additions
and
11 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,24 +1,43 @@ | ||
package diskv_wrapper | ||
|
||
import ( | ||
"strings" | ||
"errors" | ||
|
||
"github.com/peterbourgon/diskv/v3" | ||
) | ||
|
||
func Init(basePath string) *diskv.Diskv { | ||
type DiskvWrapper struct { | ||
Disk *diskv.Diskv | ||
} | ||
|
||
// New will initialize diskv, if basepath is empty it will return nil, error | ||
func New(basePath string) (*DiskvWrapper, error) { | ||
if basePath == "" { | ||
return nil, errors.New("please provide basepath for main store") | ||
} | ||
|
||
disk := diskv.New(diskv.Options{ | ||
BasePath: basePath, | ||
AdvancedTransform: AdvanceTransform, | ||
InverseTransform: InverseTransform, | ||
CacheSizeMax: 1024 * 1024, | ||
}) | ||
|
||
return disk | ||
wrapper := &DiskvWrapper{ | ||
Disk: disk, | ||
} | ||
|
||
return wrapper, nil | ||
} | ||
|
||
func GetKeyVersion(d *diskv.Diskv, version string, key string) string { | ||
path := strings.Join([]string{version, key}, "/") | ||
// Init can be used as single method that will return *diskv.Diskv | ||
func Init(basePath string) *diskv.Diskv { | ||
disk := diskv.New(diskv.Options{ | ||
BasePath: basePath, | ||
AdvancedTransform: AdvanceTransform, | ||
InverseTransform: InverseTransform, | ||
CacheSizeMax: 1024 * 1024, | ||
}) | ||
|
||
return path | ||
return disk | ||
} |
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