remove tons of commented-out code, general cleanup
This commit is contained in:
parent
f9aa34ef12
commit
15d032459a
@ -39,21 +39,6 @@ func serializeIDs(input interface{}) interface{} {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*var itagged interface{}
|
|
||||||
if reflect.ValueOf(itagged).Kind() != reflect.Pointer {
|
|
||||||
itagged = incrementTagged(&input)
|
|
||||||
} else {
|
|
||||||
itagged = incrementTagged(input)
|
|
||||||
}
|
|
||||||
taggedVal := reflect.ValueOf(reflect.ValueOf(itagged).Interface()).Elem()
|
|
||||||
if vp.Kind() == reflect.Ptr {
|
|
||||||
tmp := reflect.ValueOf(taggedVal.Interface())
|
|
||||||
if tmp.Kind() == reflect.Pointer {
|
|
||||||
vp.Elem().Set(tmp.Elem())
|
|
||||||
} else {
|
|
||||||
vp.Elem().Set(tmp)
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
switch vp.Elem().Kind() {
|
switch vp.Elem().Kind() {
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
ret0 := bson.M{}
|
ret0 := bson.M{}
|
||||||
@ -72,10 +57,6 @@ func serializeIDs(input interface{}) interface{} {
|
|||||||
bson.Unmarshal(marsh, &unmarsh)
|
bson.Unmarshal(marsh, &unmarsh)
|
||||||
for k, v := range unmarsh {
|
for k, v := range unmarsh {
|
||||||
ret0[k] = v
|
ret0[k] = v
|
||||||
/*if t, ok := v.(primitive.DateTime); ok {
|
|
||||||
ret0
|
|
||||||
} else {
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_, terr := tag.Get("ref")
|
_, terr := tag.Get("ref")
|
||||||
@ -92,8 +73,6 @@ func serializeIDs(input interface{}) interface{} {
|
|||||||
rarr = append(rarr, getID(fv.Index(j).Interface()))
|
rarr = append(rarr, getID(fv.Index(j).Interface()))
|
||||||
}
|
}
|
||||||
ret0[bbson.Name] = rarr
|
ret0[bbson.Name] = rarr
|
||||||
/*ret0[bbson.Name] = serializeIDs(fv.Interface())
|
|
||||||
break*/
|
|
||||||
} else if !ok {
|
} else if !ok {
|
||||||
panic(fmt.Sprintf("referenced model slice at '%s.%s' does not implement HasID", nameOf(input), ft.Name))
|
panic(fmt.Sprintf("referenced model slice at '%s.%s' does not implement HasID", nameOf(input), ft.Name))
|
||||||
} else {
|
} else {
|
||||||
|
10
query.go
10
query.go
@ -290,21 +290,11 @@ func (q *Query) reOrganize() {
|
|||||||
slic := reflect.New(reflect.SliceOf(typ))
|
slic := reflect.New(reflect.SliceOf(typ))
|
||||||
for _, v2 := range arr {
|
for _, v2 := range arr {
|
||||||
inter := reflect.ValueOf(rerere(v2, typ))
|
inter := reflect.ValueOf(rerere(v2, typ))
|
||||||
/*if inter.Kind() == reflect.Pointer {
|
|
||||||
inter = inter.Elem()
|
|
||||||
}*/
|
|
||||||
slic.Elem().Set(reflect.Append(slic.Elem(), inter))
|
slic.Elem().Set(reflect.Append(slic.Elem(), inter))
|
||||||
}
|
}
|
||||||
trvo = slic.Elem()
|
trvo = slic.Elem()
|
||||||
} else {
|
} else {
|
||||||
trvo = reflect.ValueOf(rerere(q.rawDoc, reflect.TypeOf(q.doc)))
|
trvo = reflect.ValueOf(rerere(q.rawDoc, reflect.TypeOf(q.doc)))
|
||||||
/*for {
|
|
||||||
if trvo.Kind() == reflect.Pointer {
|
|
||||||
trvo = trvo.Elem()
|
|
||||||
} else {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resV := reflect.ValueOf(q.doc)
|
resV := reflect.ValueOf(q.doc)
|
||||||
|
27
registry.go
27
registry.go
@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/fatih/structtag"
|
"github.com/fatih/structtag"
|
||||||
@ -45,7 +44,7 @@ type TModelRegistry map[string]*Model
|
|||||||
// ModelRegistry - the ModelRegistry stores a map containing
|
// ModelRegistry - the ModelRegistry stores a map containing
|
||||||
// pointers to Model instances, keyed by an associated
|
// pointers to Model instances, keyed by an associated
|
||||||
// model name
|
// model name
|
||||||
var ModelRegistry = make(TModelRegistry, 0)
|
var ModelRegistry = make(TModelRegistry)
|
||||||
|
|
||||||
// DB - The mongodb database handle
|
// DB - The mongodb database handle
|
||||||
var DB *mongo.Database
|
var DB *mongo.Database
|
||||||
@ -59,26 +58,6 @@ var NextStringID func() string
|
|||||||
|
|
||||||
var mutex sync.Mutex
|
var mutex sync.Mutex
|
||||||
|
|
||||||
func getRawTypeFromTag(tagOpt string, slice bool) reflect.Type {
|
|
||||||
var t reflect.Type
|
|
||||||
switch strings.ToLower(tagOpt) {
|
|
||||||
case "int":
|
|
||||||
var v int64 = 0
|
|
||||||
t = reflect.TypeOf(v)
|
|
||||||
case "uint":
|
|
||||||
var v uint = 0
|
|
||||||
t = reflect.TypeOf(v)
|
|
||||||
case "string":
|
|
||||||
var v = "0"
|
|
||||||
t = reflect.TypeOf(v)
|
|
||||||
|
|
||||||
}
|
|
||||||
if slice {
|
|
||||||
return reflect.SliceOf(t)
|
|
||||||
}
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
func makeGfsRef(tag *structtag.Tag, idx int) gridFSReference {
|
func makeGfsRef(tag *structtag.Tag, idx int) gridFSReference {
|
||||||
opts := tag.Options
|
opts := tag.Options
|
||||||
var ffmt string
|
var ffmt string
|
||||||
@ -183,10 +162,6 @@ func parseTags(t reflect.Type, v reflect.Value) (map[string][]InternalIndex, map
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if refTag, ok := tags.Get("ref"); ok == nil {
|
if refTag, ok := tags.Get("ref"); ok == nil {
|
||||||
// ref:"ModelName,refType"
|
|
||||||
/* if len(refTag.Options) < 1 {
|
|
||||||
panic("no raw type provided for ref")
|
|
||||||
} */
|
|
||||||
sname := sft.Name + "@" + refTag.Name
|
sname := sft.Name + "@" + refTag.Name
|
||||||
refs[sname] = makeRef(i, refTag.Name, sft.Name, sft.Type)
|
refs[sname] = makeRef(i, refTag.Name, sft.Name, sft.Type)
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ func genChaps(single bool) []chapter {
|
|||||||
ret = append(ret, chapter{
|
ret = append(ret, chapter{
|
||||||
ID: primitive.NewObjectID(),
|
ID: primitive.NewObjectID(),
|
||||||
Title: fmt.Sprintf("-%d-", i+1),
|
Title: fmt.Sprintf("-%d-", i+1),
|
||||||
Index: int(i + 1),
|
Index: i + 1,
|
||||||
Words: 50,
|
Words: 50,
|
||||||
Notes: "notenotenote !!!",
|
Notes: "notenotenote !!!",
|
||||||
Genre: []string{"Slash"},
|
Genre: []string{"Slash"},
|
||||||
@ -202,10 +202,6 @@ func initTest() {
|
|||||||
author.ID = 696969
|
author.ID = 696969
|
||||||
ModelRegistry.Model(band{}, user{}, story{})
|
ModelRegistry.Model(band{}, user{}, story{})
|
||||||
}
|
}
|
||||||
func after() {
|
|
||||||
err := DBClient.Disconnect(context.TODO())
|
|
||||||
panik(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var metallica = band{
|
var metallica = band{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
|
23
util.go
23
util.go
@ -64,7 +64,7 @@ func getNested(field string, aValue reflect.Value) (*reflect.Type, *reflect.Valu
|
|||||||
}
|
}
|
||||||
aft := value.Type()
|
aft := value.Type()
|
||||||
dots := strings.Split(field, ".")
|
dots := strings.Split(field, ".")
|
||||||
if value.Kind() != reflect.Struct /*&& arrRegex.FindString(dots[0]) == ""*/ {
|
if value.Kind() != reflect.Struct {
|
||||||
if value.Kind() == reflect.Slice {
|
if value.Kind() == reflect.Slice {
|
||||||
st := reflect.MakeSlice(value.Type().Elem(), 0, 0)
|
st := reflect.MakeSlice(value.Type().Elem(), 0, 0)
|
||||||
for i := 0; i < value.Len(); i++ {
|
for i := 0; i < value.Len(); i++ {
|
||||||
@ -85,8 +85,6 @@ func getNested(field string, aValue reflect.Value) (*reflect.Type, *reflect.Valu
|
|||||||
} else {
|
} else {
|
||||||
return &aft, &value, nil
|
return &aft, &value, nil
|
||||||
}
|
}
|
||||||
/*ft := value.Type()
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
ref := value
|
ref := value
|
||||||
if ref.Kind() == reflect.Pointer {
|
if ref.Kind() == reflect.Pointer {
|
||||||
@ -96,7 +94,7 @@ func getNested(field string, aValue reflect.Value) (*reflect.Type, *reflect.Valu
|
|||||||
if arrRegex.FindString(dots[0]) != "" && fv.Kind() == reflect.Slice {
|
if arrRegex.FindString(dots[0]) != "" && fv.Kind() == reflect.Slice {
|
||||||
matches := arrRegex.FindStringSubmatch(dots[0])
|
matches := arrRegex.FindStringSubmatch(dots[0])
|
||||||
ridx, _ := strconv.Atoi(matches[0])
|
ridx, _ := strconv.Atoi(matches[0])
|
||||||
idx := int(ridx)
|
idx := ridx
|
||||||
fv = fv.Index(idx)
|
fv = fv.Index(idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,20 +192,3 @@ func normalizeSliceToDocumentSlice(in any) *DocumentSlice {
|
|||||||
}
|
}
|
||||||
return &ret
|
return &ret
|
||||||
}
|
}
|
||||||
|
|
||||||
/*func normalizeDocSlice(iput reflect.Value) reflect.Value {
|
|
||||||
idslice, idsliceOk := iput.Interface().(IDocumentSlice)
|
|
||||||
dslice, dsliceOk := resV.Interface().(DocumentSlice)
|
|
||||||
switch {
|
|
||||||
case idsliceOk:
|
|
||||||
|
|
||||||
case dsliceOk:
|
|
||||||
default:
|
|
||||||
return iput
|
|
||||||
}
|
|
||||||
//if {
|
|
||||||
// resV.Set(trvo.Elem())
|
|
||||||
//} else {
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
}*/
|
|
||||||
|
Loading…
Reference in New Issue
Block a user