update
This commit is contained in:
+2
-1
@@ -15,4 +15,5 @@ qinglongs
|
||||
sets.conf
|
||||
*.exe
|
||||
yummy
|
||||
_stc
|
||||
_*
|
||||
fanli_vip
|
||||
+11
-1
@@ -24,7 +24,12 @@ func init() {
|
||||
}()
|
||||
}
|
||||
|
||||
var OttoFuncs = map[string]func(string) string{}
|
||||
var OttoFuncs = map[string]func(string) string{
|
||||
"machineId": func(_ string) string {
|
||||
data, _ := os.ReadFile("/var/lib/dbus/machine-id")
|
||||
return string(data)
|
||||
},
|
||||
}
|
||||
|
||||
func init123() {
|
||||
files, err := ioutil.ReadDir("develop/replies")
|
||||
@@ -40,6 +45,10 @@ func init123() {
|
||||
result, _ = otto.ToValue(o.Get(key, value))
|
||||
return
|
||||
}
|
||||
bucket := func(bucket otto.Value, key otto.Value) (result otto.Value) {
|
||||
result, _ = otto.ToValue(o.Get(key, Bucket(bucket.String()).Get(key.String())))
|
||||
return
|
||||
}
|
||||
set := func(key otto.Value, value otto.Value) interface{} {
|
||||
o.Set(key.String(), value.String())
|
||||
return otto.Value{}
|
||||
@@ -187,6 +196,7 @@ func init123() {
|
||||
vm.Set("set", set)
|
||||
vm.Set("param", param)
|
||||
vm.Set("get", get)
|
||||
vm.Set("bucket", bucket)
|
||||
vm.Set("request", request)
|
||||
vm.Set("push", push)
|
||||
vm.Set("sendText", func(call otto.Value) interface{} {
|
||||
|
||||
+13
-4
@@ -2,6 +2,7 @@ package core
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"runtime"
|
||||
@@ -136,13 +137,17 @@ func (bucket Bucket) Create(i interface{}) error {
|
||||
if b == nil {
|
||||
b, _ = tx.CreateBucket([]byte(bucket))
|
||||
}
|
||||
sq, _ := b.NextSequence()
|
||||
id.SetInt(int64(sq))
|
||||
key := id.Int()
|
||||
if key == 0 {
|
||||
sq, _ := b.NextSequence()
|
||||
key = int64(sq)
|
||||
id.SetInt(key)
|
||||
}
|
||||
buf, err := json.Marshal(i)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return b.Put(itob(sq), buf)
|
||||
return b.Put(itob(uint64(key)), buf)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -150,20 +155,24 @@ func itob(i uint64) []byte {
|
||||
return []byte(fmt.Sprint(i))
|
||||
}
|
||||
|
||||
func (bucket Bucket) First(i interface{}) {
|
||||
func (bucket Bucket) First(i interface{}) error {
|
||||
var err error
|
||||
id := reflect.ValueOf(i).Elem().FieldByName("ID").Int()
|
||||
db.View(func(tx *bolt.Tx) error {
|
||||
b := tx.Bucket([]byte(bucket))
|
||||
if b == nil {
|
||||
err = errors.New("bucket not find")
|
||||
return nil
|
||||
}
|
||||
data := b.Get(itob(uint64(id)))
|
||||
if len(data) == 0 {
|
||||
err = errors.New("record not find")
|
||||
return nil
|
||||
}
|
||||
json.Unmarshal(data, i)
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
// func (bucket Bucket) Find(o interface{}) {
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func GetUUID() string {
|
||||
u2, _ := uuid.NewUUID()
|
||||
return u2.String()
|
||||
}
|
||||
@@ -14,6 +14,7 @@ require (
|
||||
github.com/boltdb/bolt v1.3.1
|
||||
github.com/buger/jsonparser v1.1.1
|
||||
github.com/gin-gonic/gin v1.7.0
|
||||
github.com/google/uuid v1.1.1
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/guonaihong/gout v0.2.7 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
|
||||
Reference in New Issue
Block a user