github.com/godaddy-x/freego@v1.0.156/node/common/webutil.go (about) 1 package common 2 3 import ( 4 "fmt" 5 "github.com/godaddy-x/freego/cache" 6 "github.com/godaddy-x/freego/utils" 7 "github.com/godaddy-x/freego/utils/crypto" 8 "go.mongodb.org/mongo-driver/bson/primitive" 9 "unsafe" 10 ) 11 12 type Identify struct { 13 ID interface{} 14 } 15 16 func (s *Identify) Int64() int64 { 17 if s.ID == nil { 18 return 0 19 } 20 v, b := s.ID.(string) 21 if !b { 22 return 0 23 } 24 r, err := utils.StrToInt64(v) 25 if err != nil { 26 fmt.Println(err) 27 return 0 28 } 29 return r 30 } 31 32 func (s *Identify) String() string { 33 if s.ID == nil { 34 return "" 35 } 36 v, b := s.ID.(string) 37 if !b { 38 return "" 39 } 40 return v 41 } 42 43 func (s *Identify) ObjectID() primitive.ObjectID { 44 if s.ID == nil { 45 return primitive.ObjectID{} 46 } 47 v, b := s.ID.(string) 48 if !b { 49 return primitive.ObjectID{} 50 } 51 r, err := primitive.ObjectIDFromHex(v) 52 if err != nil { 53 fmt.Println(err) 54 return primitive.ObjectID{} 55 } 56 return r 57 } 58 59 type System struct { 60 Name string // 系统名 61 Version string // 系统版本 62 } 63 64 type Context struct { 65 Identify *Identify 66 CacheAware func(ds ...string) (cache.Cache, error) 67 RSA crypto.Cipher 68 Path string 69 System *System 70 } 71 72 type BaseReq struct { 73 Context Context `json:"-"` 74 PrevID int64 `json:"prevID"` 75 LastID int64 `json:"lastID"` 76 CountQ bool `json:"countQ"` 77 Offset int64 `json:"offset"` 78 Limit int64 `json:"limit"` 79 Cmd string `json:"cmd"` 80 } 81 82 func GetBasePtrReq(ptr uintptr) *BaseReq { 83 return (*BaseReq)(unsafe.Pointer(ptr)) 84 }