diff --git a/.gitignore b/.gitignore index 43e7ed4..2718f67 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,5 @@ bin .idea/ .vscode/ -*.iml \ No newline at end of file +*.iml +coverage/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9847d19 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +.PHONY: test-coverage + +test-coverage: + go test -v ./... -covermode=count -coverpkg=./... -coverprofile coverage/coverage.out + go tool cover -html coverage/coverage.out -o coverage/coverage.html \ No newline at end of file diff --git a/tpl/main.go b/tpl/main.go index e7bec03..2d5f969 100644 --- a/tpl/main.go +++ b/tpl/main.go @@ -10,7 +10,7 @@ import ( ) func main() { - server := core.CreateFactory(app.NewModule, "api") + server := core.CreateFactory(app.NewModule) server.Listen(3000) } @@ -62,23 +62,23 @@ import "github.com/tinh-tinh/tinhtinh/core" func NewController(module *core.DynamicModule) *core.DynamicController { ctrl := module.NewController("{{ .ModName }}") - ctrl.Post("/", func(ctx core.Ctx) error { + ctrl.Post("", func(ctx core.Ctx) error { return ctx.JSON(core.Map{"data": "ok"}) }) - ctrl.Get("/", func(ctx core.Ctx) error { + ctrl.Get("", func(ctx core.Ctx) error { return ctx.JSON(core.Map{"data": "ok"}) }) - ctrl.Get("/{id}", func(ctx core.Ctx) error { + ctrl.Get("{id}", func(ctx core.Ctx) error { return ctx.JSON(core.Map{"data": "ok"}) }) - ctrl.Put("/{id}", func(ctx core.Ctx) error { + ctrl.Put("{id}", func(ctx core.Ctx) error { return ctx.JSON(core.Map{"data": "ok"}) }) - ctrl.Delete("/{id}", func(ctx core.Ctx) error { + ctrl.Delete("{id}", func(ctx core.Ctx) error { return ctx.JSON(core.Map{"data": "ok"}) })