-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (54 loc) · 1.16 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"container/list"
"errors"
"reflect"
)
type Op struct {
Operation string
From string
Path string
Value interface{}
}
var (
TagName = "patchy"
)
func NewPatchSpec(model interface{}) (*PatchSpec, error) {
if model == nil {
return nil, errors.New("patchy: 'Model' is a required field")
}
t := reflect.TypeOf(model)
if t.Kind() != reflect.Struct {
return nil, errors.New("patchy: 'Model' must be a struct type")
}
fields := list.New()
for i := 0; i < t.NumField(); i++ {
l.PushFront(t.Field(i))
}
for l.Len() > 0 {
f := l.Remove(l.Front()).(reflect.StructField)
_, ok := f.Tag.Lookup(TagName)
// TODO: loop through fields check types create spec, enable field nesting
}
return nil, nil
}
// created using reflection once, then used every query to generate sql.
type PatchSpec struct {
TargetResource string
Fields []PatchField
}
type PatchField struct {
AllowedOps string
TargetType string
// Validator func // only need two funcs
// Converter func
// Filter func
}
func (op *Op) GetValue() interface{} {
return nil
}
type Error struct {
Attempted Op
Reason string
Code int // custom
}