Removed old runtime tagging code. Not used anymore

This commit is contained in:
Deluan 2020-01-10 18:38:31 -05:00 committed by Deluan Quintão
parent dbeba1dea9
commit ef79f6342f
2 changed files with 0 additions and 75 deletions

View File

@ -1,42 +0,0 @@
package storm
import (
"reflect"
)
func tag(entity interface{}) interface{} {
st := reflect.TypeOf(entity).Elem()
var fs []reflect.StructField
for i := 0; i < st.NumField(); i++ {
f := st.Field(i)
f.Tag = mapTags(f.Tag)
fs = append(fs, f)
}
st2 := reflect.StructOf(fs)
v := reflect.ValueOf(entity).Elem()
v2 := v.Convert(st2)
vp := reflect.New(st2)
vp.Elem().Set(reflect.ValueOf(v2.Interface()))
return vp.Interface()
}
func mapTags(tags reflect.StructTag) reflect.StructTag {
if tags == `db:"index"` {
return `storm:"index"`
}
return tags
}
func getTypeName(myVar interface{}) string {
if t := reflect.TypeOf(myVar); t.Kind() == reflect.Ptr {
return t.Elem().Name()
} else {
return t.Name()
}
}
func getStructTag(instance interface{}, fieldName string) string {
field, _ := reflect.TypeOf(instance).Elem().FieldByName(fieldName)
return string(field.Tag)
}

View File

@ -1,33 +0,0 @@
package storm
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
type Empty struct {
ID string
Something int
}
type User struct {
ID string
Name string `db:"index"`
}
var _ = Describe("Domain Tagging", func() {
It("does not change a struct that does not have any tag", func() {
empty := &Empty{}
tagged := tag(empty)
Expect(getStructTag(tagged, "ID")).To(BeEmpty())
Expect(getStructTag(tagged, "Something")).To(BeEmpty())
})
It("adds index to indexed fields", func() {
user := &User{}
tagged := tag(user)
Expect(getStructTag(tagged, "ID")).To(BeEmpty())
Expect(getStructTag(tagged, "Name")).To(Equal(`storm:"index"`))
})
})