podhmo / apikit

api toolkit (WIP)
MIT License
0 stars 0 forks source link

func -> struct transformation #148

Closed podhmo closed 2 years ago

podhmo commented 3 years ago

for these issues

podhmo commented 3 years ago

e.g.

function such as following

func Do(logger *log.Logger, data DoInput, debug *bool, targetID string) (interface{}, error) {

}

transform to

type Input struct {
    Data     DoInput `json:"data"`
    Debug    *bool   `json:"debug"`
    TargetID string  `json:"targetID"`
}

💭 with embedded option, maybe using data as embedded field

podhmo commented 3 years ago

https://docs.aws.amazon.com/lambda/latest/dg/golang-handler.html

lambda handler is also not having path and query-string, so another handling way for the argument that treated as primitive and primitive-pointer is needed. this is same in the situation using cli.

podhmo commented 3 years ago

transform to ??

podhmo commented 3 years ago

func -> reflectshape.Shape is better, I think.

(plus point: reflect-openapi is also using reflect.Shape #122 )

podhmo commented 3 years ago

(additional: with raw field ?)

like go-stripe do

https://github.com/stripe/stripe-go/blob/6be0c4f6f5da607d7e6482d5925ee16c471aa6a6/event.go#L35-L43 https://github.com/stripe/stripe-go/blob/6be0c4f6f5da607d7e6482d5925ee16c471aa6a6/event.go#L81-L91

podhmo commented 3 years ago

validation

hmm https://github.com/podhmo/apikit/issues/147#issuecomment-953762656

if func -> struct transformation automatically, cannot handle validation?

or something like below

g.Generate(pkg, action.Do, WithTag("targetId", `validate: regexp="^[a-f0-9]{24}"`))

or

type ObjectID string
func (id *ObjectId) TagString() string { return `<tag>` }

or

https://github.com/go-playground/validator/blob/b95d43b789d7f058ee3a17f3f1a267379ea024d1/_examples/custom/main.go

podhmo commented 3 years ago

options