| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 | 
							- package main
 
- import (
 
- 	"encoding/binary"
 
- 	"errors"
 
- 	"fmt"
 
- 	"github.com/recoilme/slowpoke"
 
- 	"os"
 
- 	"os/exec"
 
- 	"path/filepath"
 
- 	"runtime"
 
- 	"strings"
 
- )
 
- func main(){
 
- 	file := "pos/pos.db"
 
- 	// close all opened database
 
- 	// init key/val
 
- 	key := []byte("startPos")
 
- 	//val := []byte("bar")
 
- 	id := make([]byte, 4)
 
- 	binary.BigEndian.PutUint32(id, uint32(10))
 
- 	defer slowpoke.Close("pos/pos.db")
 
- 	//for i:=0;i<10 ; i++ {
 
- 	//	slowpoke.Set(file, []byte(strconv.Itoa(i)) , []byte(strconv.Itoa(i)))
 
- 	//}
 
- 	////slowpoke.Close("pos/pos.db")
 
- 	//store
 
- 	//err :=slowpoke.Set(file, []byte("startPos"), []byte("startPos"))
 
- 	//if err != nil{
 
- 	//	fmt.Println(err.Error())
 
- 	//}
 
- 	// get
 
- 	res, err := slowpoke.Get(file, key)
 
- 	if err != nil {
 
- 		println(err.Error())
 
- 	}
 
- 	path,_ :=GetCurrentPath()
 
- 	fmt.Println(string(res),path)
 
- 	//res, err = slowpoke.Get(file, []byte("4"))
 
- 	//
 
- 	//if err != nil {
 
- 	//	println(err.Error())
 
- 	//}
 
- 	////path,_ :=GetCurrentPath()
 
- 	//
 
- 	//fmt.Println(string(res))
 
- }
 
- func GetCurrentPath() (string, error) {
 
- 	file, err := exec.LookPath(os.Args[0])
 
- 	if err != nil {
 
- 		return "", err
 
- 	}
 
- 	path, err := filepath.Abs(file)
 
- 	if err != nil {
 
- 		return "", err
 
- 	}
 
- 	//fmt.Println("path111:", path)
 
- 	if runtime.GOOS == "windows" {
 
- 		path = strings.Replace(path, "\\", "/", -1)
 
- 	}
 
- 	//fmt.Println("path222:", path)
 
- 	i := strings.LastIndex(path, "/")
 
- 	if i < 0 {
 
- 		return "", errors.New(`Can't find "/" or "\".`)
 
- 	}
 
- 	//fmt.Println("path333:", path)
 
- 	return string(path[0 : i+1]), nil
 
- }
 
 
  |