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"
-
-
- key := []byte("startPos")
-
- id := make([]byte, 4)
- binary.BigEndian.PutUint32(id, uint32(10))
- defer slowpoke.Close("pos/pos.db")
-
-
-
-
-
-
-
-
-
-
- res, err := slowpoke.Get(file, key)
- if err != nil {
- println(err.Error())
- }
- path,_ :=GetCurrentPath()
- fmt.Println(string(res),path)
-
-
-
-
-
-
-
-
- }
- 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
- }
-
- if runtime.GOOS == "windows" {
- path = strings.Replace(path, "\\", "/", -1)
- }
-
- i := strings.LastIndex(path, "/")
- if i < 0 {
- return "", errors.New(`Can't find "/" or "\".`)
- }
-
- return string(path[0 : i+1]), nil
- }
|