podhmo / apikit

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

support simple cli #142

Open podhmo opened 2 years ago

podhmo commented 2 years ago

like net/http handler, lift action to simple cli interface.

podhmo commented 2 years ago

maybe use translate package internally

podhmo commented 2 years ago

simulation

if taking the action, definition is following.

type HelloOutput struct {
        Message string `json: "message"`
}

type HelloInput struct {
     Name string `json:"name"`
}
func Hello(ctx context.Context, logger *log.Logger, input HelloInput) (*HelloOutput, error) {
        logger.Printf("hello")
        return &HelloOutput{Message: "hello " + input.Name}, nil
}
podhmo commented 2 years ago
podhmo commented 2 years ago

If implements correctly, be able to run generated code, like something below.

$ hello -name foo
hello
{"message": "hello foo"}

But, but How should I handle primitive arguments (and primitive pointer arguments) ?

podhmo commented 2 years ago

And how should I handling config for components ? (e.g. log.NewLogger() 's io.Writer and flags)

podhmo commented 2 years ago
$ DEBUG=1 hello --data <(echo '{"name": "foo"}') --verbose 111
podhmo commented 2 years ago

more simply, all value is passed by stdin.

$ echo '{"data": {"name": "foo"}, "verbose": true}' | hello -debug
podhmo commented 2 years ago

https://github.com/podhmo/apikit/blob/70d7902ea2b309d3d90d610c3072e836f4be15d5/resolve/def.go#L54-L63