├── .gitattributes ├── .github ├── CONTRIBUTING.md ├── workflow-templates │ ├── mify-cloud-ci copy.properties.json │ └── mify-cloud-ci.yml └── workflows │ └── go.yml ├── .gitignore ├── .golangci.yml ├── .goreleaser.yaml ├── LICENSE ├── Makefile ├── README.md ├── assets ├── assets.go └── openapi │ ├── client-template │ ├── go │ │ ├── .travis.yml │ │ ├── api.mustache │ │ ├── client.mustache │ │ ├── config.yaml │ │ ├── configuration.mustache │ │ ├── gitignore.mustache │ │ ├── ignore-list.txt │ │ ├── model.mustache │ │ ├── model_anyof.mustache │ │ ├── model_doc.mustache │ │ ├── model_enum.mustache │ │ ├── model_oneof.mustache │ │ ├── model_simple.mustache │ │ ├── nullable_model.mustache │ │ ├── openapi.mustache │ │ ├── partial_header.mustache │ │ ├── response.mustache │ │ ├── signing.mustache │ │ └── utils.mustache │ ├── js │ │ ├── ApiClient.mustache │ │ ├── api.mustache │ │ ├── config.yaml │ │ ├── enumClass.mustache │ │ ├── ignore-list.txt │ │ ├── index.mustache │ │ ├── licenseInfo.mustache │ │ ├── model.mustache │ │ ├── package.mustache │ │ ├── partial_model_enum_class.mustache │ │ ├── partial_model_generic.mustache │ │ └── partial_model_inner_enum.mustache │ └── python │ │ ├── __init__.handlebars │ │ ├── __init__apis.handlebars │ │ ├── __init__apis_tags.handlebars │ │ ├── __init__model.handlebars │ │ ├── __init__models.handlebars │ │ ├── __init__package.handlebars │ │ ├── __init__paths.handlebars │ │ ├── __init__paths_enum.handlebars │ │ ├── __init__paths_x.handlebars │ │ ├── api.handlebars │ │ ├── api_client.handlebars │ │ ├── apis_path_module.handlebars │ │ ├── apis_path_to_api.handlebars │ │ ├── apis_tag_to_api.handlebars │ │ ├── comma.handlebars │ │ ├── config.yaml │ │ ├── configuration.handlebars │ │ ├── endpoint.handlebars │ │ ├── endpoint_args.handlebars │ │ ├── endpoint_args_passed.handlebars │ │ ├── endpoint_body_serialization.handlebars │ │ ├── endpoint_parameter.handlebars │ │ ├── endpoint_stub.handlebars │ │ ├── exceptions.handlebars │ │ ├── ignore-list.txt │ │ ├── model.handlebars │ │ ├── model_doc.handlebars │ │ ├── model_stub.handlebars │ │ ├── model_templates │ │ ├── classname.handlebars │ │ ├── composed_schemas.handlebars │ │ ├── dict_partial.handlebars │ │ ├── enums.handlebars │ │ ├── format_base.handlebars │ │ ├── imports_schema_types.handlebars │ │ ├── imports_schemas.handlebars │ │ ├── list_partial.handlebars │ │ ├── new.handlebars │ │ ├── notes_msg.handlebars │ │ ├── payload_renderer.handlebars │ │ ├── property_getitems_with_addprops.handlebars │ │ ├── property_getitems_with_addprops_getitem.handlebars │ │ ├── property_getitems_without_addprops.handlebars │ │ ├── property_type_hints.handlebars │ │ ├── property_type_hints_required.handlebars │ │ ├── schema.handlebars │ │ ├── schema_accessed_types.handlebars │ │ ├── schema_composed_or_anytype.handlebars │ │ ├── schema_dict.handlebars │ │ ├── schema_list.handlebars │ │ ├── schema_python_types.handlebars │ │ ├── schema_simple.handlebars │ │ ├── validations.handlebars │ │ ├── var_equals_cls.handlebars │ │ └── xbase_schema.handlebars │ │ ├── model_test.handlebars │ │ ├── partial_header.handlebars │ │ ├── rest.handlebars │ │ ├── schemas.handlebars │ │ ├── setup.handlebars │ │ ├── setup_cfg.handlebars │ │ └── signing.handlebars │ └── server-template │ ├── go │ ├── api.mustache │ ├── auth │ │ ├── auth.mustache │ │ ├── jwt.mustache │ │ └── security-schemas.mustache │ ├── config.yaml │ ├── controller-api.mustache │ ├── cors.mustache │ ├── error.mustache │ ├── helpers.mustache │ ├── ignore-list.txt │ ├── impl.mustache │ ├── init │ │ └── routes.mustache │ ├── logger.mustache │ ├── metrics.mustache │ ├── model.mustache │ ├── openapi.mustache │ ├── partial_header.mustache │ ├── public │ │ └── req_ctx_access.mustache │ ├── recoverer.mustache │ ├── request_context.mustache │ ├── routers.mustache │ ├── service.mustache │ └── swaggerui.mustache │ ├── js │ ├── README.mustache │ ├── app.mustache │ ├── config.mustache │ ├── config.yaml │ ├── controller.mustache │ ├── controllers │ │ ├── Controller.mustache │ │ ├── index.mustache │ │ └── test.mustache │ ├── eslintrc.mustache │ ├── expressServer.mustache │ ├── ignore-list.txt │ ├── index.mustache │ ├── logger.mustache │ ├── openapi.mustache │ ├── package.mustache │ ├── service.mustache │ ├── services │ │ ├── Service.mustache │ │ └── index.mustache │ └── utils │ │ ├── openapiRouter.mustache │ │ └── writer.mustache │ └── python │ ├── __init__.mustache │ ├── __init__main.mustache │ ├── __init__model.mustache │ ├── __main__.mustache │ ├── base_model_.mustache │ ├── config.yaml │ ├── conftest.mustache │ ├── controller.mustache │ ├── ignore-list.txt │ ├── model.mustache │ ├── openapi.mustache │ ├── param_type.mustache │ ├── partial_header.mustache │ ├── security_controller_.mustache │ ├── service.mustache │ ├── typing_utils.mustache │ └── util.mustache ├── cmd └── mify │ ├── cmd │ ├── add.go │ ├── generate.go │ ├── init.go │ ├── remove.go │ ├── root.go │ ├── run.go │ └── tool.go │ └── main.go ├── docs ├── .gitignore ├── Dockerfile ├── README.md ├── babel.config.js ├── docs │ ├── components │ │ ├── _category_.json │ │ ├── configs.md │ │ ├── openapi.md │ │ └── postgres.md │ ├── getting-started │ │ ├── _category_.json │ │ ├── cli.md │ │ ├── index.mdx │ │ └── overview.md │ ├── guides │ │ ├── _category_.json │ │ ├── create-frontend │ │ │ ├── _category_.json │ │ │ ├── building-and-testing-all-together.mdx │ │ │ ├── calling-backend-service.mdx │ │ │ └── skeleton.mdx │ │ ├── create-service │ │ │ ├── _category_.json │ │ │ ├── api-layout.mdx │ │ │ ├── building-and-testing.mdx │ │ │ └── implementing-counter-handler.mdx │ │ └── overview.md │ └── roadmap.md ├── docusaurus.config.js ├── package.json ├── sidebars.js ├── src │ ├── components │ │ └── github.js │ ├── css │ │ └── custom.css │ └── pages1 │ │ ├── index.js │ │ └── index.module.css ├── static │ ├── .nojekyll │ └── img │ │ ├── docs │ │ ├── cloud-get-token.png │ │ └── frontend-result.png │ │ ├── favicon.ico │ │ ├── logo-white.png │ │ └── logo.png └── yarn.lock ├── go.mod ├── go.sum ├── internal └── mify │ ├── client.go │ ├── cloud │ └── auth │ │ └── auth.go │ ├── config │ └── assets.go │ ├── context.go │ ├── database.go │ ├── generator.go │ ├── run.go │ ├── service.go │ ├── stats │ ├── collector.go │ └── sender.go │ ├── status │ ├── generator_status.go │ └── tui.go │ ├── tests │ └── integration │ │ ├── .gitignore │ │ ├── data │ │ └── TestFullFlow1 │ │ │ ├── TestFullFlow1.0.approved.tar │ │ │ ├── TestFullFlow1.1.approved.tar │ │ │ ├── TestFullFlow1.10.approved.tar │ │ │ ├── TestFullFlow1.11.approved.tar │ │ │ ├── TestFullFlow1.12.approved.tar │ │ │ ├── TestFullFlow1.13.approved.tar │ │ │ ├── TestFullFlow1.14.approved.tar │ │ │ ├── TestFullFlow1.2.approved.tar │ │ │ ├── TestFullFlow1.3.approved.tar │ │ │ ├── TestFullFlow1.4.approved.tar │ │ │ ├── TestFullFlow1.5.approved.tar │ │ │ ├── TestFullFlow1.6.approved.tar │ │ │ ├── TestFullFlow1.7.approved.tar │ │ │ ├── TestFullFlow1.8.approved.tar │ │ │ └── TestFullFlow1.9.approved.tar │ │ ├── dir_approval.go │ │ └── flow_test.go │ ├── tool.go │ ├── userinput │ └── userinput.go │ ├── util │ ├── args.go │ ├── atomic_bool.go │ ├── cmd.go │ ├── docker │ │ └── docker.go │ ├── safe_names.go │ ├── set.go │ └── yaml.go │ └── workspace.go ├── pkg ├── cloudconfig │ ├── api.go │ └── config.go ├── generator │ ├── core │ │ ├── pipeline.go │ │ ├── pipeline_builder.go │ │ └── step.go │ ├── gen-context │ │ ├── execute_pool.go │ │ ├── gen_context.go │ │ ├── logger.go │ │ └── vcs.go │ ├── lib │ │ └── endpoints │ │ │ ├── endpoints.go │ │ │ └── env_helper.go │ ├── migrate │ │ └── migrator.go │ ├── pipelines.go │ └── steps │ │ ├── api-gateway │ │ ├── context │ │ │ └── context.go │ │ ├── impl.go │ │ ├── openapi_mutator.go │ │ ├── public_api_scan.go │ │ └── step.go │ │ ├── dev-runner │ │ ├── context │ │ │ └── context.go │ │ ├── impl.go │ │ ├── step.go │ │ └── tpl │ │ │ ├── main.go │ │ │ └── main.go.tpl │ │ ├── layout │ │ ├── helpers │ │ │ ├── base_model.go │ │ │ └── js │ │ │ │ └── names.go │ │ ├── impl.go │ │ ├── step.go │ │ └── tpl-new │ │ │ ├── go-services │ │ │ ├── cmd │ │ │ │ ├── _service_ │ │ │ │ │ ├── Dockerfile.tpl │ │ │ │ │ ├── main.go.tpl │ │ │ │ │ └── render.go │ │ │ │ └── render.go │ │ │ ├── go.mod.go │ │ │ ├── go.mod.tpl │ │ │ ├── go.sum.go │ │ │ ├── go.sum.tpl │ │ │ ├── internal │ │ │ │ ├── _service_ │ │ │ │ │ ├── app │ │ │ │ │ │ ├── migrate.go │ │ │ │ │ │ ├── render.go │ │ │ │ │ │ ├── request_extra.go │ │ │ │ │ │ ├── request_extra.go.tpl │ │ │ │ │ │ ├── router │ │ │ │ │ │ │ ├── render.go │ │ │ │ │ │ │ ├── router.go │ │ │ │ │ │ │ └── router.go.tpl │ │ │ │ │ │ ├── service_extra.go │ │ │ │ │ │ └── service_extra.go.tpl │ │ │ │ │ └── render.go │ │ │ │ ├── mify-generated │ │ │ │ │ ├── render.go │ │ │ │ │ └── services │ │ │ │ │ │ ├── _service_ │ │ │ │ │ │ ├── app │ │ │ │ │ │ │ ├── mify_app.go │ │ │ │ │ │ │ ├── mify_app.go.tpl │ │ │ │ │ │ │ └── render.go │ │ │ │ │ │ ├── apputil │ │ │ │ │ │ │ ├── apputil.go │ │ │ │ │ │ │ ├── apputil.go.tpl │ │ │ │ │ │ │ └── render.go │ │ │ │ │ │ └── render.go │ │ │ │ │ │ └── render.go │ │ │ │ └── render.go │ │ │ └── render.go │ │ │ ├── js-services │ │ │ ├── _service_ │ │ │ │ ├── nuxtjs │ │ │ │ │ ├── components │ │ │ │ │ │ ├── render.go │ │ │ │ │ │ ├── sample.vue.go │ │ │ │ │ │ └── sample.vue.tpl │ │ │ │ │ ├── dockerfile.go │ │ │ │ │ ├── dockerfile.tpl │ │ │ │ │ ├── generated │ │ │ │ │ │ └── core │ │ │ │ │ │ │ ├── context.js.tpl │ │ │ │ │ │ │ └── render.go │ │ │ │ │ ├── nuxt.config.go │ │ │ │ │ ├── nuxt.config.js.tpl │ │ │ │ │ ├── package.go │ │ │ │ │ ├── package.json.tpl │ │ │ │ │ ├── pages │ │ │ │ │ │ ├── index.go │ │ │ │ │ │ ├── index.vue │ │ │ │ │ │ └── render.go │ │ │ │ │ ├── plugins │ │ │ │ │ │ ├── mifycontext.js.tpl │ │ │ │ │ │ └── render.go │ │ │ │ │ ├── render.go │ │ │ │ │ ├── store │ │ │ │ │ │ ├── index.js.tpl │ │ │ │ │ │ ├── mifycontext.js.tpl │ │ │ │ │ │ └── render.go │ │ │ │ │ ├── yarn.lock.go │ │ │ │ │ └── yarn.lock.tpl │ │ │ │ ├── react-ts │ │ │ │ │ ├── Dockerfile-nginx.tpl │ │ │ │ │ ├── Dockerfile.tpl │ │ │ │ │ ├── package.json.tpl │ │ │ │ │ ├── public │ │ │ │ │ │ ├── index.html.tpl │ │ │ │ │ │ ├── manifest.json.tpl │ │ │ │ │ │ ├── render.go │ │ │ │ │ │ └── robots.txt.tpl │ │ │ │ │ ├── render.go │ │ │ │ │ ├── src │ │ │ │ │ │ ├── App.css.tpl │ │ │ │ │ │ ├── App.test.tsx.tpl │ │ │ │ │ │ ├── App.tsx.tpl │ │ │ │ │ │ ├── app │ │ │ │ │ │ │ ├── hooks.ts.tpl │ │ │ │ │ │ │ ├── render.go │ │ │ │ │ │ │ └── store.ts.tpl │ │ │ │ │ │ ├── generated │ │ │ │ │ │ │ └── core │ │ │ │ │ │ │ │ ├── context.js.tpl │ │ │ │ │ │ │ │ ├── render.go │ │ │ │ │ │ │ │ └── state.ts.tpl │ │ │ │ │ │ ├── index.css.tpl │ │ │ │ │ │ ├── index.tsx.tpl │ │ │ │ │ │ ├── react-app-env.d.ts.tpl │ │ │ │ │ │ ├── render.go │ │ │ │ │ │ ├── reportWebVitals.ts.tpl │ │ │ │ │ │ └── setupTests.ts.tpl │ │ │ │ │ └── tsconfig.json.tpl │ │ │ │ └── render.go │ │ │ ├── package.go │ │ │ ├── package.json.tpl │ │ │ └── render.go │ │ │ ├── py-services │ │ │ ├── _service_ │ │ │ │ ├── Dockerfile.go │ │ │ │ ├── Dockerfile.tpl │ │ │ │ ├── __init__.py.tpl │ │ │ │ ├── __main__.py.tpl │ │ │ │ ├── app │ │ │ │ │ ├── __init__.py.tpl │ │ │ │ │ ├── render.go │ │ │ │ │ ├── request_extra.go │ │ │ │ │ ├── request_extra.py.tpl │ │ │ │ │ ├── service_extra.go │ │ │ │ │ └── service_extra.py.tpl │ │ │ │ ├── main.go │ │ │ │ └── render.go │ │ │ └── render.go │ │ │ ├── render.go │ │ │ └── workspace │ │ │ ├── dotmify │ │ │ └── gitignore.tpl │ │ │ └── render.go │ │ ├── mify-generated │ │ ├── helpers │ │ │ ├── base_model.go │ │ │ └── js │ │ │ │ └── names.go │ │ ├── impl.go │ │ ├── step.go │ │ └── tpl │ │ │ ├── go-services │ │ │ ├── internal │ │ │ │ ├── mify-generated │ │ │ │ │ ├── common │ │ │ │ │ │ ├── configs │ │ │ │ │ │ │ ├── common.go.tpl │ │ │ │ │ │ │ ├── dynamic_config.go.tpl │ │ │ │ │ │ │ ├── render.go │ │ │ │ │ │ │ └── static_config.go.tpl │ │ │ │ │ │ ├── consul │ │ │ │ │ │ │ ├── consul_config.go.tpl │ │ │ │ │ │ │ └── render.go │ │ │ │ │ │ ├── logs │ │ │ │ │ │ │ ├── logger.go.tpl │ │ │ │ │ │ │ └── render.go │ │ │ │ │ │ ├── metrics │ │ │ │ │ │ │ ├── client_metrics.go.tpl │ │ │ │ │ │ │ ├── metrics.go.tpl │ │ │ │ │ │ │ ├── render.go │ │ │ │ │ │ │ └── request_metrics.go.tpl │ │ │ │ │ │ └── render.go │ │ │ │ │ ├── render.go │ │ │ │ │ └── services │ │ │ │ │ │ ├── _service_ │ │ │ │ │ │ ├── app │ │ │ │ │ │ │ ├── render.go │ │ │ │ │ │ │ ├── server.go │ │ │ │ │ │ │ └── server.go.tpl │ │ │ │ │ │ ├── core │ │ │ │ │ │ │ ├── helpers.go │ │ │ │ │ │ │ ├── helpers.go.tpl │ │ │ │ │ │ │ ├── render.go │ │ │ │ │ │ │ ├── request_context.go │ │ │ │ │ │ │ ├── request_context.go.tpl │ │ │ │ │ │ │ ├── service_context.go │ │ │ │ │ │ │ └── service_context.go.tpl │ │ │ │ │ │ └── render.go │ │ │ │ │ │ └── render.go │ │ │ │ └── render.go │ │ │ └── render.go │ │ │ ├── py-services │ │ │ ├── mify_generated │ │ │ │ ├── common │ │ │ │ │ ├── __init__.py.tpl │ │ │ │ │ ├── configs │ │ │ │ │ │ ├── dynamic.py.tpl │ │ │ │ │ │ ├── render.go │ │ │ │ │ │ └── static.py.tpl │ │ │ │ │ ├── logs │ │ │ │ │ │ ├── logger.py.tpl │ │ │ │ │ │ └── render.go │ │ │ │ │ ├── metrics │ │ │ │ │ │ ├── client_metrics.py.tpl │ │ │ │ │ │ ├── metrics.py.tpl │ │ │ │ │ │ ├── render.go │ │ │ │ │ │ ├── request_metrics.py.tpl │ │ │ │ │ │ └── server.py.tpl │ │ │ │ │ └── render.go │ │ │ │ ├── render.go │ │ │ │ └── services │ │ │ │ │ ├── _service_ │ │ │ │ │ ├── app │ │ │ │ │ │ ├── __init__.py.tpl │ │ │ │ │ │ ├── mify_app.py.tpl │ │ │ │ │ │ ├── render.go │ │ │ │ │ │ └── server.py.tpl │ │ │ │ │ ├── core │ │ │ │ │ │ ├── __init__.py.tpl │ │ │ │ │ │ ├── clients.go │ │ │ │ │ │ ├── clients.py.tpl │ │ │ │ │ │ ├── render.go │ │ │ │ │ │ ├── request_context.py.tpl │ │ │ │ │ │ └── service_context.py.tpl │ │ │ │ │ ├── openapi │ │ │ │ │ │ ├── app.py.tpl │ │ │ │ │ │ └── render.go │ │ │ │ │ └── render.go │ │ │ │ │ └── render.go │ │ │ └── render.go │ │ │ └── render.go │ │ ├── migrate │ │ ├── impl.go │ │ └── step.go │ │ ├── openapi │ │ ├── clients.go │ │ ├── clients_cache.go │ │ ├── clients_diff.go │ │ ├── context │ │ │ └── context.go │ │ ├── generation_metadata.go │ │ ├── impl.go │ │ ├── openapi.go │ │ ├── openapi_client.go │ │ ├── openapi_server.go │ │ ├── processors │ │ │ ├── golang.go │ │ │ ├── js.go │ │ │ ├── processor.go │ │ │ ├── python.go │ │ │ └── string_utils_test.go │ │ ├── step.go │ │ └── tpl │ │ │ ├── go_clients.go │ │ │ ├── go_clients.go.tpl │ │ │ ├── js_clients.go │ │ │ └── js_clients.js.tpl │ │ ├── postgres │ │ ├── impl.go │ │ ├── step.go │ │ └── tpl │ │ │ ├── go │ │ │ ├── config │ │ │ │ ├── config.go │ │ │ │ ├── config.go.tpl │ │ │ │ └── render.go │ │ │ ├── queries.sql.example.tpl │ │ │ ├── render.go │ │ │ ├── sqlc.go │ │ │ └── sqlc.yaml.tpl │ │ │ └── render.go │ │ ├── prepare │ │ ├── impl.go │ │ ├── python.go │ │ ├── requirements.txt.tpl │ │ └── step.go │ │ └── schema │ │ ├── context │ │ ├── context.go │ │ ├── openapi.go │ │ └── schemas.go │ │ ├── impl.go │ │ ├── step.go │ │ └── validation.go ├── mifyconfig │ ├── service_config.go │ └── workspace_config.go ├── util │ ├── logging │ │ └── files.go │ ├── render │ │ ├── helpers.go │ │ ├── render.go │ │ ├── service_model.go │ │ └── workspace_model.go │ └── threading │ │ └── lock.go └── workspace │ ├── description.go │ ├── helpers.go │ ├── mify-generated.go │ ├── mutators │ ├── client │ │ └── client.go │ ├── cloud │ │ ├── init.go │ │ └── public.go │ ├── database │ │ └── database.go │ ├── mutator_context.go │ ├── service │ │ ├── creator.go │ │ └── tpl │ │ │ ├── api.yaml.go │ │ │ └── api.yaml.tpl │ └── workspace │ │ ├── creator.go │ │ ├── tpl │ │ └── gitignore.tpl │ │ └── vcs.go │ └── tpl-helpers │ ├── go.go │ ├── helpers.go │ ├── js.go │ └── python.go └── scripts ├── debug.sh ├── dev-runner ├── bind │ ├── identity.schema.json │ └── kratos.yml └── docker-compose.yml ├── init.sh ├── makepkg.sh ├── release.sh └── run.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | *.tpl -linguist-detectable 2 | *.mustache -linguist-detectable 3 | -------------------------------------------------------------------------------- /.github/workflow-templates/mify-cloud-ci copy.properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "name: Mify cloud CI/CD", 3 | "description": "Mify cloud CI/CD starter workflow.", 4 | "categories": [ 5 | "Go" 6 | ], 7 | "filePatterns": [ 8 | "^workspace.mify.yaml$" 9 | ] 10 | } -------------------------------------------------------------------------------- /.github/workflow-templates/mify-cloud-ci.yml: -------------------------------------------------------------------------------- 1 | name: Mify cloud CI/CD 2 | 3 | on: 4 | push: 5 | branches: [ $default-branch ] 6 | pull_request: 7 | branches: [ $default-branch ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Run a one-line script 17 | run: echo Hello from mify 18 | -------------------------------------------------------------------------------- /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | tags: ['*'] 7 | pull_request: 8 | branches: [ main ] 9 | 10 | permissions: 11 | contents: write 12 | 13 | jobs: 14 | build-and-test: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v3 18 | 19 | - name: Set up Go 20 | uses: actions/setup-go@v4 21 | with: 22 | go-version-file: go.mod 23 | check-latest: true 24 | 25 | - name: Test 26 | run: make test 27 | 28 | - uses: goreleaser/goreleaser-action@v5 29 | if: startsWith(github.ref, 'refs/tags/') 30 | with: 31 | distribution: goreleaser 32 | version: latest 33 | args: release --clean 34 | env: 35 | GITHUB_TOKEN: ${{ secrets.PUBLISHER_TOKEN }} 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /mify 2 | /build 3 | 4 | dist/ 5 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | run: 2 | deadline: 5m 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | GOOS?=linux 2 | GOARCH?=amd64 3 | MIFY_VERSION=$(shell git describe --tags --always) 4 | 5 | SUPPORTED_OS_LIST=linux darwin 6 | SUPPORTED_ARCH_LIST=amd64 arm64 7 | 8 | all: build lint 9 | 10 | build: 11 | GOOS=$(GOOS) GOARCH=$(GOARCH) go build -v -ldflags "-X github.com/mify-io/mify/cmd/mify/cmd.MIFY_VERSION=$(MIFY_VERSION)" ./cmd/mify 12 | 13 | build-packages: 14 | for os in $(SUPPORTED_OS_LIST); do \ 15 | for arch in $(SUPPORTED_ARCH_LIST); do \ 16 | echo "making package for os: $$os, arch: $$arch"; \ 17 | GOOS=$$os GOARCH=$$arch go build -v -ldflags "-X github.com/mify-io/mify/cmd/mify/cmd.MIFY_VERSION=$(MIFY_VERSION)" ./cmd/mify; \ 18 | ./scripts/makepkg.sh $$os $$arch; \ 19 | echo "done os: $$os, arch: $$arch"; \ 20 | done \ 21 | done 22 | 23 | test: 24 | go test -v ./... 25 | 26 | lint: 27 | go vet ./... 28 | staticcheck ./... 29 | -------------------------------------------------------------------------------- /assets/assets.go: -------------------------------------------------------------------------------- 1 | package assets 2 | 3 | import "embed" 4 | 5 | //go:embed * 6 | var assets embed.FS 7 | 8 | func GetAssetsFs() embed.FS { 9 | return assets 10 | } 11 | -------------------------------------------------------------------------------- /assets/openapi/client-template/go/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | install: 4 | - go get -d -v . 5 | 6 | script: 7 | - go build -v ./ 8 | 9 | -------------------------------------------------------------------------------- /assets/openapi/client-template/go/config.yaml: -------------------------------------------------------------------------------- 1 | generatorName: go 2 | templateDir: /repo/.mify/assets/openapi/client-template/go 3 | enableMinimalUpdate: true 4 | globalProperties: 5 | apiDocs: false 6 | modelDocs: false 7 | apiTests: false 8 | modelTests: false 9 | additionalProperties: 10 | addResponseHeaders: true 11 | enumClassPrefix: true 12 | # featureCORS: true 13 | hideGenerationTimestamp: false 14 | packageName: openapi 15 | packageVersion: 1.0.0 16 | files: 17 | ignore-list.txt: 18 | destinationFilename: .openapi-generator-ignore 19 | 20 | releaseNote: Release note 21 | httpUserAgent: User Agent 22 | 23 | apiPackage: handlers 24 | modelPackage: models 25 | 26 | invokerPackage: unused 27 | apiNameSuffix: "_" 28 | modelNamePrefix: "" 29 | modelNameSuffix: "" 30 | library: "" 31 | 32 | instantiationTypes: {} 33 | typeMappings: {} 34 | importMappings: {} 35 | languageSpecificPrimitives: [] 36 | reservedWordMappings: {} 37 | serverVariables: {} 38 | 39 | verbose: false 40 | skipOverwrite: false 41 | removeOperationIdPrefix: false 42 | skipOperationExample: false 43 | logToStderr: false 44 | validateSpec: true 45 | enablePostProcessFile: false 46 | strictSpecBehavior: true 47 | generateAliasAsModel: false 48 | templatingEngineName: mustache 49 | -------------------------------------------------------------------------------- /assets/openapi/client-template/go/gitignore.mustache: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /assets/openapi/client-template/go/ignore-list.txt: -------------------------------------------------------------------------------- 1 | /README.md 2 | /.travis.yml 3 | /api 4 | /api/** 5 | /go.mod 6 | /go.sum 7 | /.gitignore 8 | /git_push.sh 9 | -------------------------------------------------------------------------------- /assets/openapi/client-template/go/model.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | // vim: set ft=go: 3 | package {{packageName}} 4 | 5 | {{#models}} 6 | import ( 7 | "encoding/json" 8 | {{#imports}} 9 | "{{import}}" 10 | {{/imports}} 11 | ) 12 | 13 | {{#model}} 14 | {{#isEnum}} 15 | {{>model_enum}} 16 | {{/isEnum}} 17 | {{^isEnum}} 18 | {{#oneOf}}{{#-first}}{{>model_oneof}}{{/-first}}{{/oneOf}}{{^oneOf}}{{#anyOf}}{{#-first}}{{>model_anyof}}{{/-first}}{{/anyOf}}{{^anyOf}}{{>model_simple}}{{/anyOf}}{{/oneOf}} 19 | {{/isEnum}} 20 | {{/model}} 21 | {{/models}} 22 | -------------------------------------------------------------------------------- /assets/openapi/client-template/go/nullable_model.mustache: -------------------------------------------------------------------------------- 1 | type Nullable{{{classname}}} struct { 2 | value *{{{classname}}} 3 | isSet bool 4 | } 5 | 6 | func (v Nullable{{classname}}) Get() *{{classname}} { 7 | return v.value 8 | } 9 | 10 | func (v *Nullable{{classname}}) Set(val *{{classname}}) { 11 | v.value = val 12 | v.isSet = true 13 | } 14 | 15 | func (v Nullable{{classname}}) IsSet() bool { 16 | return v.isSet 17 | } 18 | 19 | func (v *Nullable{{classname}}) Unset() { 20 | v.value = nil 21 | v.isSet = false 22 | } 23 | 24 | func NewNullable{{classname}}(val *{{classname}}) *Nullable{{classname}} { 25 | return &Nullable{{classname}}{value: val, isSet: true} 26 | } 27 | 28 | func (v Nullable{{{classname}}}) MarshalJSON() ([]byte, error) { 29 | return json.Marshal(v.value) 30 | } 31 | 32 | func (v *Nullable{{{classname}}}) UnmarshalJSON(src []byte) error { 33 | v.isSet = true 34 | return json.Unmarshal(src, &v.value) 35 | } 36 | -------------------------------------------------------------------------------- /assets/openapi/client-template/go/openapi.mustache: -------------------------------------------------------------------------------- 1 | {{{openapi-yaml}}} -------------------------------------------------------------------------------- /assets/openapi/client-template/go/partial_header.mustache: -------------------------------------------------------------------------------- 1 | // THIS FILE IS AUTOGENERATED, DO NOT EDIT 2 | // Generated by mify via OpenAPI Generator 3 | -------------------------------------------------------------------------------- /assets/openapi/client-template/js/config.yaml: -------------------------------------------------------------------------------- 1 | generatorName: javascript 2 | templateDir: /repo/.mify/assets/openapi/client-template/js 3 | enableMinimalUpdate: true 4 | globalProperties: 5 | apiTests: false 6 | modelTests: false 7 | apiDocs: false 8 | modelDocs: false 9 | additionalProperties: 10 | usePromises: true 11 | packageName: openapi 12 | files: 13 | ignore-list.txt: 14 | destinationFilename: .openapi-generator-ignore 15 | 16 | releaseNote: Release note 17 | httpUserAgent: User Agent 18 | 19 | apiPackage: handlers 20 | modelPackage: models 21 | invokerPackage: null 22 | sourceFolder: null 23 | 24 | apiNameSuffix: "_" 25 | modelNamePrefix: "" 26 | modelNameSuffix: "" 27 | library: "" 28 | 29 | instantiationTypes: {} 30 | typeMappings: {} 31 | importMappings: {} 32 | languageSpecificPrimitives: [] 33 | reservedWordMappings: {} 34 | serverVariables: {} 35 | 36 | verbose: false 37 | skipOverwrite: false 38 | removeOperationIdPrefix: false 39 | skipOperationExample: false 40 | logToStderr: false 41 | validateSpec: true 42 | enablePostProcessFile: false 43 | strictSpecBehavior: true 44 | generateAliasAsModel: false 45 | templatingEngineName: mustache 46 | -------------------------------------------------------------------------------- /assets/openapi/client-template/js/enumClass.mustache: -------------------------------------------------------------------------------- 1 | {{#emitJSDoc}}/** 2 | * Allowed values for the {{baseName}} property. 3 | * @enum {{=<% %>=}}{<%datatype%>}<%={{ }}=%> 4 | * @readonly 5 | */{{/emitJSDoc}} 6 | export default {{datatypeWithEnum}} = { 7 | {{#allowableValues}}{{#enumVars}} 8 | {{#emitJSDoc}}/** 9 | * value: {{{value}}} 10 | * @const 11 | */{{/emitJSDoc}} 12 | "{{name}}": {{{value}}}{{^-last}}, 13 | {{/-last}} 14 | {{/enumVars}}{{/allowableValues}} 15 | }; 16 | -------------------------------------------------------------------------------- /assets/openapi/client-template/js/ignore-list.txt: -------------------------------------------------------------------------------- 1 | /README.md 2 | /.travis.yml 3 | /.gitignore 4 | /.babelrc 5 | /git_push.sh 6 | /mocha.opts 7 | -------------------------------------------------------------------------------- /assets/openapi/client-template/js/licenseInfo.mustache: -------------------------------------------------------------------------------- 1 | // THIS FILE IS AUTOGENERATED, DO NOT EDIT 2 | // Generated by mify via OpenAPI Generator 3 | -------------------------------------------------------------------------------- /assets/openapi/client-template/js/model.mustache: -------------------------------------------------------------------------------- 1 | {{>licenseInfo}} 2 | // vim: set ft=javascript: 3 | import ApiClient from '../ApiClient.js'; 4 | {{#imports}}import {{import}} from './{{import}}.js'; 5 | {{/imports}}{{#models}}{{#model}}{{#isEnum}}{{>partial_model_enum_class}}{{/isEnum}}{{^isEnum}}{{>partial_model_generic}}{{/isEnum}}{{/model}}{{/models}} 6 | -------------------------------------------------------------------------------- /assets/openapi/client-template/js/partial_model_enum_class.mustache: -------------------------------------------------------------------------------- 1 | {{#emitJSDoc}}/** 2 | * Enum class {{classname}}. 3 | * @enum {{=<% %>=}}{<%datatype%>}<%={{ }}=%> 4 | * @readonly 5 | */{{/emitJSDoc}} 6 | export default class {{classname}} { 7 | {{#allowableValues}}{{#enumVars}} 8 | {{#emitJSDoc}}/** 9 | * value: {{{value}}} 10 | * @const 11 | */{{/emitJSDoc}} 12 | "{{name}}" = {{{value}}}; 13 | 14 | {{/enumVars}}{{/allowableValues}} 15 | 16 | {{#emitJSDoc}}/** 17 | * Returns a {{classname}} enum value from a Javascript object name. 18 | * @param {Object} data The plain JavaScript object containing the name of the enum value. 19 | * @return {{=< >=}}{module:<#invokerPackage>/<#modelPackage>/}<={{ }}=> The enum {{classname}} value. 20 | */{{/emitJSDoc}} 21 | static constructFromObject(object) { 22 | return object; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /assets/openapi/client-template/js/partial_model_inner_enum.mustache: -------------------------------------------------------------------------------- 1 | {{#emitJSDoc}}/** 2 | * Allowed values for the {{baseName}} property. 3 | * @enum {{=<% %>=}}{<%datatype%>}<%={{ }}=%> 4 | * @readonly 5 | */{{/emitJSDoc}} 6 | {{classname}}['{{datatypeWithEnum}}'] = { 7 | {{#allowableValues}}{{#enumVars}} 8 | {{#emitJSDoc}}/** 9 | * value: {{{value}}} 10 | * @const 11 | */{{/emitJSDoc}} 12 | "{{name}}": {{{value}}}{{^-last}}, 13 | {{/-last}} 14 | {{/enumVars}}{{/allowableValues}} 15 | }; 16 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/__init__.handlebars: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/assets/openapi/client-template/python/__init__.handlebars -------------------------------------------------------------------------------- /assets/openapi/client-template/python/__init__apis.handlebars: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | # do not import all endpoints into this module because that uses a lot of memory and stack frames 4 | # if you need the ability to import all endpoints then import them from 5 | # tags, paths, or path_to_api, or tag_to_api -------------------------------------------------------------------------------- /assets/openapi/client-template/python/__init__apis_tags.handlebars: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | # do not import all endpoints into this module because that uses a lot of memory and stack frames 4 | # if you need the ability to import all endpoints from this module, import them with 5 | # from {{packageName}}.apis.tag_to_api import tag_to_api 6 | 7 | import enum 8 | 9 | 10 | class TagValues(str, enum.Enum): 11 | {{#each enumToTag}} 12 | {{@key}} = "{{this}}" 13 | {{/each}} -------------------------------------------------------------------------------- /assets/openapi/client-template/python/__init__model.handlebars: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | # we can not import model classes here because that would create a circular 4 | # reference which would not work in python2 5 | # do not import all models into this module because that uses a lot of memory and stack frames 6 | # if you need the ability to import all models from one package, import them with 7 | # from {{packageName}}.models import ModelA, ModelB 8 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/__init__models.handlebars: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | # coding: utf-8 4 | 5 | # flake8: noqa 6 | 7 | # import all models into this package 8 | # if you have many models here with many references from one model to another this may 9 | # raise a RecursionError 10 | # to avoid this, import only the models that you directly need like: 11 | # from from {{packageName}}.{{modelPackage}}.pet import Pet 12 | # or import this package, but before doing it, use: 13 | # import sys 14 | # sys.setrecursionlimit(n) 15 | 16 | {{#each models}} 17 | {{#with model}} 18 | from {{packageName}}.{{modelPackage}}.{{classFilename}} import {{classname}} 19 | {{/with}} 20 | {{/each}} 21 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/__init__package.handlebars: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | # coding: utf-8 4 | 5 | # flake8: noqa 6 | 7 | {{>partial_header}} 8 | 9 | __version__ = "{{packageVersion}}" 10 | 11 | # import ApiClient 12 | from {{packageName}}.api_client import ApiClient 13 | 14 | # import Configuration 15 | from {{packageName}}.configuration import Configuration 16 | {{#if hasHttpSignatureMethods}} 17 | from {{packageName}}.signing import HttpSigningConfiguration 18 | {{/if}} 19 | 20 | # import exceptions 21 | from {{packageName}}.exceptions import OpenApiException 22 | from {{packageName}}.exceptions import ApiAttributeError 23 | from {{packageName}}.exceptions import ApiTypeError 24 | from {{packageName}}.exceptions import ApiValueError 25 | from {{packageName}}.exceptions import ApiKeyError 26 | from {{packageName}}.exceptions import ApiException 27 | {{#if recursionLimit}} 28 | 29 | __import__('sys').setrecursionlimit({{recursionLimit}}) 30 | {{/if}} 31 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/__init__paths.handlebars: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | # do not import all endpoints into this module because that uses a lot of memory and stack frames 4 | # if you need the ability to import all endpoints from this module, import them with 5 | # from {{packageName}}.apis.path_to_api import path_to_api 6 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/__init__paths_enum.handlebars: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | # do not import all endpoints into this module because that uses a lot of memory and stack frames 4 | # if you need the ability to import all endpoints from this module, import them with 5 | # from {{packageName}}.apis.path_to_api import path_to_api 6 | 7 | import enum 8 | 9 | 10 | class PathValues(str, enum.Enum): 11 | {{#each pathValToVar}} 12 | {{this}} = "{{@key}}" 13 | {{/each}} -------------------------------------------------------------------------------- /assets/openapi/client-template/python/__init__paths_x.handlebars: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | # do not import all endpoints into this module because that uses a lot of memory and stack frames 4 | # if you need the ability to import all endpoints from this module, import them with 5 | # from {{packageName}}.paths.{{pathModule}} import {{apiClassName}} 6 | 7 | from {{packageName}}.paths import PathValues 8 | 9 | path = PathValues.{{{pathVar}}} -------------------------------------------------------------------------------- /assets/openapi/client-template/python/api.handlebars: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | 4 | {{#with operations}} 5 | {{#each operation}} 6 | from {{packageName}}.paths.{{nickname}}.{{httpMethod}} import {{operationIdCamelCase}} 7 | {{/each}} 8 | {{/with}} 9 | 10 | 11 | {{#with operations}} 12 | class {{classname}}( 13 | {{#each operation}} 14 | {{operationIdCamelCase}}, 15 | {{/each}} 16 | ): 17 | """NOTE: This class is auto generated by OpenAPI Generator 18 | Ref: https://openapi-generator.tech 19 | 20 | Do not edit the class manually. 21 | """ 22 | pass 23 | {{/with}} 24 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/apis_path_to_api.handlebars: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | import typing_extensions 4 | 5 | from {{packageName}}.paths import PathValues 6 | {{#each pathModuleToApiClassname}} 7 | from {{packageName}}.apis.paths.{{@key}} import {{this}} 8 | {{/each}} 9 | 10 | PathToApi = typing_extensions.TypedDict( 11 | 'PathToApi', 12 | { 13 | {{#each pathEnumToApiClassname}} 14 | PathValues.{{@key}}: {{this}}, 15 | {{/each}} 16 | } 17 | ) 18 | 19 | path_to_api = PathToApi( 20 | { 21 | {{#each pathEnumToApiClassname}} 22 | PathValues.{{@key}}: {{this}}, 23 | {{/each}} 24 | } 25 | ) 26 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/apis_tag_to_api.handlebars: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | import typing_extensions 4 | 5 | from {{packageName}}.apis.tags import TagValues 6 | {{#each tagModuleNameToApiClassname}} 7 | from {{packageName}}.apis.tags.{{@key}} import {{this}} 8 | {{/each}} 9 | 10 | TagToApi = typing_extensions.TypedDict( 11 | 'TagToApi', 12 | { 13 | {{#each tagEnumToApiClassname}} 14 | TagValues.{{@key}}: {{this}}, 15 | {{/each}} 16 | } 17 | ) 18 | 19 | tag_to_api = TagToApi( 20 | { 21 | {{#each tagEnumToApiClassname}} 22 | TagValues.{{@key}}: {{this}}, 23 | {{/each}} 24 | } 25 | ) 26 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/comma.handlebars: -------------------------------------------------------------------------------- 1 | , -------------------------------------------------------------------------------- /assets/openapi/client-template/python/config.yaml: -------------------------------------------------------------------------------- 1 | generatorName: python 2 | templateDir: /repo/.mify/assets/openapi/client-template/python 3 | enableMinimalUpdate: true 4 | globalProperties: 5 | apiDocs: false 6 | modelDocs: false 7 | apiTests: false 8 | modelTests: false 9 | additionalProperties: 10 | packageVersion: 1.0.0 11 | generateSourceCodeOnly: true 12 | packageName: openapi 13 | files: 14 | ignore-list.txt: 15 | destinationFilename: .openapi-generator-ignore 16 | 17 | releaseNote: Release note 18 | httpUserAgent: User Agent 19 | 20 | apiPackage: handlers 21 | modelPackage: models 22 | 23 | invokerPackage: unused 24 | apiNameSuffix: "_" 25 | modelNamePrefix: "" 26 | modelNameSuffix: "" 27 | library: "" 28 | 29 | instantiationTypes: {} 30 | typeMappings: {} 31 | importMappings: {} 32 | languageSpecificPrimitives: [] 33 | reservedWordMappings: {} 34 | serverVariables: {} 35 | 36 | verbose: false 37 | skipOverwrite: false 38 | removeOperationIdPrefix: false 39 | skipOperationExample: false 40 | logToStderr: false 41 | validateSpec: true 42 | enablePostProcessFile: false 43 | strictSpecBehavior: true 44 | generateAliasAsModel: false 45 | templatingEngineName: handlebars 46 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/endpoint_args_passed.handlebars: -------------------------------------------------------------------------------- 1 | {{#if bodyParam}} 2 | {{#with bodyParam}} 3 | body=body, 4 | {{/with}} 5 | {{/if}} 6 | {{#if queryParams}} 7 | query_params=query_params, 8 | {{/if}} 9 | {{#if headerParams}} 10 | header_params=header_params, 11 | {{/if}} 12 | {{#if pathParams}} 13 | path_params=path_params, 14 | {{/if}} 15 | {{#if cookieParams}} 16 | cookie_params=cookie_params, 17 | {{/if}} 18 | {{#with bodyParam}} 19 | {{#each content}} 20 | {{#if @first}} 21 | content_type=content_type, 22 | {{/if}} 23 | {{/each}} 24 | {{/with}} 25 | {{#if produces}} 26 | accept_content_types=accept_content_types, 27 | {{/if}} 28 | {{#if servers}} 29 | host_index=host_index, 30 | {{/if}} 31 | stream=stream, 32 | timeout=timeout, 33 | skip_deserialization=skip_deserialization 34 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/endpoint_body_serialization.handlebars: -------------------------------------------------------------------------------- 1 | serialized_data = request_body_{{paramName}}.serialize(body, content_type) 2 | _headers.add('Content-Type', content_type) 3 | if 'fields' in serialized_data: 4 | _fields = serialized_data['fields'] 5 | elif 'body' in serialized_data: 6 | _body = serialized_data['body'] 7 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/endpoint_parameter.handlebars: -------------------------------------------------------------------------------- 1 | request_{{#if isQueryParam}}query{{/if}}{{#if isPathParam}}path{{/if}}{{#if isHeaderParam}}header{{/if}}{{#if isCookieParam}}cookie{{/if}}_{{paramName}} = api_client.{{#if isQueryParam}}Query{{/if}}{{#if isPathParam}}Path{{/if}}{{#if isHeaderParam}}Header{{/if}}{{#if isCookieParam}}Cookie{{/if}}Parameter( 2 | name="{{baseName}}", 3 | {{#if style}} 4 | style=api_client.ParameterStyle.{{style}}, 5 | {{/if}} 6 | {{#if schema}} 7 | {{#with schema}} 8 | schema={{baseName}}, 9 | {{/with}} 10 | {{/if}} 11 | {{#if required}} 12 | required=True, 13 | {{/if}} 14 | {{#if isExplode}} 15 | explode=True, 16 | {{/if}} 17 | ) 18 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/endpoint_stub.handlebars: -------------------------------------------------------------------------------- 1 | {{> endpoint isStub=true }} 2 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/ignore-list.txt: -------------------------------------------------------------------------------- 1 | /Dockerfile 2 | /README.md 3 | /api/openapi.yaml 4 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model.handlebars: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | 4 | {{#each models}} 5 | {{#with model}} 6 | {{> model_templates/imports_schema_types }} 7 | {{> model_templates/schema }} 8 | {{> model_templates/imports_schemas }} 9 | {{/with}} 10 | {{/each}} 11 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_doc.handlebars: -------------------------------------------------------------------------------- 1 | {{#each models}} 2 | {{#with model}} 3 | # {{packageName}}.{{modelPackage}}.{{classFilename}}.{{classname}} 4 | {{> schema_doc }} 5 | {{/with}} 6 | {{/each}} 7 | 8 | [[Back to Model list]](../../README.md#documentation-for-models) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to README]](../../README.md) 9 | 10 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_stub.handlebars: -------------------------------------------------------------------------------- 1 | {{> model isStub=true }} 2 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/classname.handlebars: -------------------------------------------------------------------------------- 1 | {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}{{/if}} -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/enums.handlebars: -------------------------------------------------------------------------------- 1 | {{#with allowableValues}} 2 | {{#each enumVars}} 3 | 4 | @schemas.classproperty 5 | def {{name}}(cls): 6 | {{#eq value "schemas.NoneClass.NONE"}} 7 | return cls(None) 8 | {{else}} 9 | {{#eq value "schemas.BoolClass.TRUE"}} 10 | return cls(True) 11 | {{else}} 12 | {{#eq value "schemas.BoolClass.FALSE"}} 13 | return cls(False) 14 | {{else}} 15 | return cls({{{value}}}) 16 | {{/eq}} 17 | {{/eq}} 18 | {{/eq}} 19 | {{/each}} 20 | {{/with}} -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/format_base.handlebars: -------------------------------------------------------------------------------- 1 | {{#eq getFormat "uuid"}} 2 | schemas.UUIDBase, 3 | {{/eq}} 4 | {{#eq getFormat "date"}} 5 | schemas.DateBase, 6 | {{/eq}} 7 | {{#eq getFormat "date-time"}} 8 | schemas.DateTimeBase, 9 | {{/eq}} 10 | {{#eq getFormat "number"}} 11 | schemas.DecimalBase, 12 | {{/eq}} 13 | {{#eq getFormat "binary"}} 14 | schemas.BinaryBase, 15 | {{/eq}} 16 | {{#eq getFormat "int32"}} 17 | schemas.Int32Base, 18 | {{/eq}} 19 | {{#eq getFormat "int64"}} 20 | schemas.Int64Base, 21 | {{/eq}} 22 | {{#eq getFormat "float"}} 23 | schemas.Float32Base, 24 | {{/eq}} 25 | {{#eq getFormat "double"}} 26 | schemas.Float64Base, 27 | {{/eq}} -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/imports_schema_types.handlebars: -------------------------------------------------------------------------------- 1 | from datetime import date, datetime # noqa: F401 2 | import decimal # noqa: F401 3 | import functools # noqa: F401 4 | import io # noqa: F401 5 | import re # noqa: F401 6 | import typing # noqa: F401 7 | import typing_extensions # noqa: F401 8 | import uuid # noqa: F401 9 | 10 | import frozendict # noqa: F401 11 | 12 | from {{packageName}} import schemas # noqa: F401 13 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/imports_schemas.handlebars: -------------------------------------------------------------------------------- 1 | {{#each imports}} 2 | {{#if @first}} 3 | 4 | {{/if}} 5 | {{{.}}} 6 | {{/each}} -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/list_partial.handlebars: -------------------------------------------------------------------------------- 1 | {{#with items}} 2 | {{#if complexType}} 3 | 4 | @staticmethod 5 | def {{baseName}}() -> typing.Type['{{complexType}}']: 6 | return {{complexType}} 7 | {{else}} 8 | {{> model_templates/schema }} 9 | {{/if}} 10 | {{/with}} 11 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/notes_msg.handlebars: -------------------------------------------------------------------------------- 1 | {{#unless isArray}}{{#unless complexType}}{{#with allowableValues}}must be one of [{{#each enumVars}}{{#eq value "schemas.NoneClass.NONE"}}None{{else}}{{#eq value "schemas.BoolClass.TRUE"}}True{{else}}{{#eq value "schemas.BoolClass.FALSE"}}False{{else}}{{{value}}}{{/eq}}{{/eq}}{{/eq}}, {{/each}}] {{/with}}{{#if defaultValue}}{{#unless hasRequired}}if omitted the server will use the default value of {{{defaultValue}}}{{/unless}}{{/if}}{{#eq getFormat "uuid"}}value must be a uuid{{/eq}}{{#eq getFormat "date"}}value must conform to RFC-3339 full-date YYYY-MM-DD{{/eq}}{{#eq getFormat "date-time"}}value must conform to RFC-3339 date-time{{/eq}}{{#eq getFormat "number"}}value must be numeric and storable in decimal.Decimal{{/eq}}{{#eq getFormat "int32"}}value must be a 32 bit integer{{/eq}}{{#eq getFormat "int64"}}value must be a 64 bit integer{{/eq}}{{#eq getFormat "double"}}value must be a 64 bit float{{/eq}}{{#eq getFormat "float"}}value must be a 32 bit float{{/eq}}{{/unless}}{{/unless}} -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/payload_renderer.handlebars: -------------------------------------------------------------------------------- 1 | {{#if isMap}} 2 | { 3 | {{#each value}} 4 | {{#with @key}} 5 | {{> model_templates/payload_renderer endChar=':'}} 6 | {{/with}} 7 | {{#with this}} 8 | {{> model_templates/payload_renderer endChar=','}} 9 | {{/with}} 10 | {{/each}} 11 | }{{endChar}} 12 | {{/if}} 13 | {{#if isArray}} 14 | [ 15 | {{#each value}} 16 | {{> model_templates/payload_renderer endChar=','}} 17 | {{/each}} 18 | ]{{endChar}} 19 | {{/if}} 20 | {{#or isNumber isUnboundedInteger}} 21 | {{value}}{{endChar}} 22 | {{/or}} 23 | {{#if isBoolean}} 24 | {{#if value}} 25 | True{{endChar}} 26 | {{else}} 27 | False{{endChar}} 28 | {{/if}} 29 | {{/if}} 30 | {{#if isNull}} 31 | None{{endChar}} 32 | {{/if}} 33 | {{#if isString}} 34 | "{{{value}}}"{{endChar}} 35 | {{/if}} -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/property_getitems_with_addprops_getitem.handlebars: -------------------------------------------------------------------------------- 1 | def {{methodName}}(self, name: typing.Union[{{#each getRequiredVarsMap}}{{#with this}}typing_extensions.Literal["{{{baseName}}}"], {{/with}}{{/each}}{{#each vars}}{{#unless required}}typing_extensions.Literal["{{{baseName}}}"], {{/unless}}{{/each}}{{#with additionalProperties}}{{#unless getIsBooleanSchemaFalse}}str, {{/unless}}{{/with}}]){{#not vars}}{{#not getRequiredVarsMap}}{{#with additionalProperties}}{{#unless getIsBooleanSchemaFalse}} -> {{#if complexType}}'{{complexType}}'{{else}}MetaOapg.{{baseName}}{{/if}}{{/unless}}{{/with}}{{/not}}{{/not}}: 2 | {{#eq methodName "__getitem__"}} 3 | # dict_instance[name] accessor 4 | {{/eq}} 5 | return super().{{methodName}}(name) 6 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/property_type_hints.handlebars: -------------------------------------------------------------------------------- 1 | {{#if getRequiredVarsMap}} 2 | 3 | {{#if additionalProperties}} 4 | {{> model_templates/property_type_hints_required }} 5 | {{else}} 6 | {{> model_templates/property_type_hints_required addPropsUnset=true }} 7 | {{/if}} 8 | {{/if}} 9 | {{#if additionalProperties}} 10 | {{> model_templates/property_getitems_with_addprops }} 11 | {{else}} 12 | {{> model_templates/property_getitems_without_addprops }} 13 | {{/if}} -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/property_type_hints_required.handlebars: -------------------------------------------------------------------------------- 1 | {{#each getRequiredVarsMap}} 2 | {{#with this}} 3 | {{#unless nameInSnakeCase}} 4 | {{#if complexType}} 5 | {{baseName}}: '{{complexType}}' 6 | {{else}} 7 | {{#if schemaIsFromAdditionalProperties}} 8 | {{#if addPropsUnset}} 9 | {{baseName}}: schemas.AnyTypeSchema 10 | {{else}} 11 | {{baseName}}: MetaOapg.additional_properties 12 | {{/if}} 13 | {{else}} 14 | {{baseName}}: MetaOapg.properties.{{baseName}} 15 | {{/if}} 16 | {{/if}} 17 | {{/unless}} 18 | {{/with}} 19 | {{/each}} -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/schema_accessed_types.handlebars: -------------------------------------------------------------------------------- 1 | {{#if isAnyType}}frozendict.frozendict, str, decimal.Decimal, BoolClass, NoneClass, tuple, bytes, FileIO{{/if}}{{#if isArray}}tuple, {{/if}}{{#if isMap}}frozendict.frozendict, {{/if}}{{#if isNull}}NoneClass, {{/if}}{{#if isString }}{{#neq format "binary"}}str, {{/neq}}{{#eq format "binary"}}bytes, FileIO, {{/eq}}{{/if}}{{#or isInteger isNumber}}decimal.Decimal, {{/or}}{{#if isBoolean}}BoolClass, {{/if}} -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/schema_dict.handlebars: -------------------------------------------------------------------------------- 1 | 2 | 3 | class {{> model_templates/classname }}( 4 | schemas.DictSchema 5 | ): 6 | {{#if this.classname}} 7 | """NOTE: This class is auto generated by OpenAPI Generator. 8 | Ref: https://openapi-generator.tech 9 | 10 | Do not edit the class manually. 11 | {{#if description}} 12 | 13 | {{{unescapedDescription}}} 14 | {{/if}} 15 | """ 16 | {{/if}} 17 | {{#if isStub}} 18 | {{#or additionalProperties getRequiredVarsMap getHasDiscriminatorWithNonEmptyMapping vars}} 19 | 20 | 21 | class MetaOapg: 22 | {{> model_templates/dict_partial }} 23 | {{/or}} 24 | {{else}} 25 | {{#or additionalProperties getRequiredVarsMap getHasDiscriminatorWithNonEmptyMapping vars hasValidation}} 26 | 27 | 28 | class MetaOapg: 29 | {{> model_templates/dict_partial }} 30 | {{> model_templates/validations }} 31 | {{/or}} 32 | {{/if}} 33 | {{> model_templates/property_type_hints }} 34 | 35 | {{> model_templates/new }} 36 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/schema_list.handlebars: -------------------------------------------------------------------------------- 1 | 2 | 3 | class {{> model_templates/classname }}( 4 | schemas.ListSchema 5 | ): 6 | {{#if this.classname}} 7 | """NOTE: This class is auto generated by OpenAPI Generator. 8 | Ref: https://openapi-generator.tech 9 | 10 | Do not edit the class manually. 11 | {{#if description}} 12 | 13 | {{{unescapedDescription}}} 14 | {{/if}} 15 | """ 16 | {{/if}} 17 | {{#if isStub}} 18 | {{#if items}} 19 | 20 | 21 | class MetaOapg: 22 | {{> model_templates/list_partial }} 23 | {{/if}} 24 | {{else}} 25 | {{#or getItems hasValidation}} 26 | 27 | 28 | class MetaOapg: 29 | {{#if hasValidation}} 30 | {{> model_templates/validations }} 31 | {{/if}} 32 | {{> model_templates/list_partial }} 33 | {{/or}} 34 | {{/if}} 35 | 36 | {{> model_templates/new }} 37 | 38 | def __getitem__(self, i: int) -> {{#with items}}{{#if complexType}}'{{complexType}}'{{else}}MetaOapg.items{{/if}}{{/with}}: 39 | return super().__getitem__(i) 40 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/schema_python_types.handlebars: -------------------------------------------------------------------------------- 1 | {{#if isAnyType}}dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader, {{/if}}{{#if isArray}}list, tuple, {{/if}}{{#if isMap}}dict, frozendict.frozendict, {{/if}}{{#if isNull}}None, {{/if}}{{#if isString }}{{#neq format "binary"}}str, {{/neq}}{{#eq format "date"}}date, {{/eq}}{{#eq format "date-time"}}datetime, {{/eq}}{{#eq format "uuid"}}uuid.UUID, {{/eq}}{{#eq format "binary"}}bytes, io.FileIO, io.BufferedReader, {{/eq}}{{/if}}{{#if isInteger}}decimal.Decimal, int, {{/if}}{{#if isNumber}}decimal.Decimal, int, float, {{/if}}{{#if isBoolean}}bool, {{/if}} -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/schema_simple.handlebars: -------------------------------------------------------------------------------- 1 | 2 | 3 | class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}{{/if}}( 4 | {{#if isEnum}} 5 | schemas.EnumBase, 6 | {{/if}} 7 | {{> model_templates/xbase_schema }} 8 | ): 9 | {{#if this.classname}} 10 | """NOTE: This class is auto generated by OpenAPI Generator. 11 | Ref: https://openapi-generator.tech 12 | 13 | Do not edit the class manually. 14 | {{#if description}} 15 | 16 | {{{unescapedDescription}}} 17 | {{/if}} 18 | """ 19 | {{/if}} 20 | {{#unless isStub}} 21 | {{#or hasValidation isEnum getFormat}} 22 | 23 | 24 | class MetaOapg: 25 | {{#if getFormat}} 26 | format = '{{getFormat}}' 27 | {{/if}} 28 | {{> model_templates/validations }} 29 | {{#if isEnum}} 30 | {{#with allowableValues}} 31 | enum_value_to_name = { 32 | {{#each enumVars}} 33 | {{{value}}}: "{{name}}", 34 | {{/each}} 35 | } 36 | {{/with}} 37 | {{/if}} 38 | {{/or}} 39 | {{/unless}} 40 | {{#if isEnum}} 41 | {{> model_templates/enums }} 42 | {{/if}} 43 | {{#if isStub}} 44 | {{#if hasValidation}} 45 | {{#unless isEnum}} 46 | pass 47 | {{/unless}} 48 | {{/if}} 49 | {{/if}} -------------------------------------------------------------------------------- /assets/openapi/client-template/python/model_templates/var_equals_cls.handlebars: -------------------------------------------------------------------------------- 1 | {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}}{{else}}{{baseName}}{{/if}}{{/if}} = {{#or getIsBooleanSchemaTrue getIsBooleanSchemaFalse}}{{#if getIsBooleanSchemaTrue}}schemas.AnyTypeSchema{{else}}schemas.NotAnyTypeSchema{{/if}}{{else}}{{#if complexType}}{{complexType}}{{else}}schemas.{{#if isNullable}}Nullable{{/if}}{{#if getIsNull}}None{{/if}}{{#if isAnyType}}AnyType{{/if}}{{#if isMap}}Dict{{/if}}{{#if isArray}}List{{/if}}{{#if isString}}{{#eq format "date"}}Date{{/eq}}{{#eq format "date-time"}}DateTime{{/eq}}{{#eq format "uuid"}}UUID{{/eq}}{{#eq format "number"}}Decimal{{/eq}}{{#eq format "binary"}}Binary{{/eq}}{{#neq format "date"}}{{#neq format "date-time"}}{{#neq format "uuid"}}{{#neq format "number"}}{{#neq format "binary"}}Str{{/neq}}{{/neq}}{{/neq}}{{/neq}}{{/neq}}{{/if}}{{#if isInteger}}{{#eq format "int32"}}Int32{{/eq}}{{#eq format "int64"}}Int64{{/eq}}{{#neq format "int32"}}{{#neq format "int64"}}Int{{/neq}}{{/neq}}{{/if}}{{#if isNumber}}{{#eq format "float"}}Float32{{/eq}}{{#eq format "double"}}Float64{{/eq}}{{#neq format "float"}}{{#neq format "double"}}Number{{/neq}}{{/neq}}{{/if}}{{#if isBoolean}}Bool{{/if}}Schema{{/if}}{{/or}} 2 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/partial_header.handlebars: -------------------------------------------------------------------------------- 1 | """ 2 | {{#if appName}} 3 | {{{appName}}} 4 | {{/if}} 5 | 6 | {{#if appDescription}} 7 | {{{appDescription}}} # noqa: E501 8 | {{/if}} 9 | 10 | {{#if version}} 11 | The version of the OpenAPI document: {{{version}}} 12 | {{/if}} 13 | {{#if infoEmail}} 14 | Contact: {{{infoEmail}}} 15 | {{/if}} 16 | Generated by: https://openapi-generator.tech 17 | """ 18 | -------------------------------------------------------------------------------- /assets/openapi/client-template/python/setup_cfg.handlebars: -------------------------------------------------------------------------------- 1 | {{#if useNose}} 2 | [nosetests] 3 | logging-clear-handlers=true 4 | verbosity=2 5 | randomize=true 6 | exe=true 7 | with-coverage=true 8 | cover-package={{{packageName}}} 9 | cover-erase=true 10 | 11 | {{/if}} 12 | [flake8] 13 | max-line-length=99 14 | -------------------------------------------------------------------------------- /assets/openapi/server-template/go/cors.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | package {{packageName}} 3 | // vim: set ft=go: 4 | 5 | import ( 6 | "net/http" 7 | 8 | "github.com/go-chi/cors" 9 | ) 10 | 11 | func CORS() func(http.Handler) http.Handler { 12 | // TODO(chebykinn): get the list of domains instead of wildcards 13 | // https://github.com/mify-io/mify/issues/75 14 | return cors.Handler( 15 | cors.Options{ 16 | AllowCredentials: true, 17 | AllowedMethods: []string{ 18 | http.MethodHead, 19 | http.MethodGet, 20 | http.MethodPost, 21 | http.MethodPut, 22 | http.MethodPatch, 23 | http.MethodDelete, 24 | }, 25 | AllowedOrigins: []string{ 26 | "*", 27 | }, 28 | AllowedHeaders: []string{ 29 | "*", 30 | }, 31 | }) 32 | } 33 | -------------------------------------------------------------------------------- /assets/openapi/server-template/go/ignore-list.txt: -------------------------------------------------------------------------------- 1 | /Dockerfile 2 | /README.md 3 | /go.mod 4 | /main.go 5 | -------------------------------------------------------------------------------- /assets/openapi/server-template/go/impl.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | // vim: set ft=go: 3 | package {{packageName}} 4 | 5 | //Implementation response defines an error code with the associated body 6 | type ServiceResponse struct { 7 | Code int 8 | {{#addResponseHeaders}} 9 | Headers map[string][]string 10 | {{/addResponseHeaders}} 11 | Body interface{} 12 | } 13 | 14 | type Dependencies struct { 15 | // handlers deps go here 16 | } 17 | -------------------------------------------------------------------------------- /assets/openapi/server-template/go/init/routes.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | // vim: set ft=go: 3 | package {{packageName}}_init 4 | 5 | import ( 6 | {{#routers}} 7 | "github.com/go-chi/chi/v5" 8 | {{/routers}} 9 | "{{mifyGeneratedServicePackage}}/api" 10 | "{{mifyGeneratedServicePackage}}/core" 11 | 12 | {{#openAPI}}{{#paths}} 13 | {{#entrySet}} 14 | "{{goModule}}/internal/{{serviceName}}/handlers{{key}}" 15 | {{/entrySet}} 16 | {{/paths}}{{/openAPI}} 17 | ) 18 | 19 | func Routes(ctx *core.MifyServiceContext, routerConfig openapi.RouterConfig, reqExtraFactory core.RequestExtraFactory) {{#routers}}chi.Router{{/routers}} { 20 | {{#apiInfo}}{{#apis}} 21 | {{classname}}Service := {{classFilename}}.New{{classname}}Service() 22 | {{classname}}Controller := {{packageName}}.New{{classname}}Controller(ctx, {{classname}}Service) 23 | {{/apis}}{{/apiInfo}} 24 | router := {{packageName}}.NewRouter(ctx, routerConfig, reqExtraFactory, {{#apiInfo}}{{#apis}}{{classname}}Controller{{^-last}}, {{/-last}}{{/apis}}{{/apiInfo}}) 25 | return router 26 | } 27 | -------------------------------------------------------------------------------- /assets/openapi/server-template/go/metrics.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | // vim: set ft=go: 3 | package {{packageName}} 4 | 5 | import ( 6 | "net/http" 7 | "time" 8 | 9 | "github.com/go-chi/chi/v5/middleware" 10 | "{{mifyGeneratedCommonPackage}}/metrics" 11 | ) 12 | 13 | func Metrics() func(next http.Handler) http.Handler { 14 | return func(next http.Handler) http.Handler { 15 | fn := func(w http.ResponseWriter, r *http.Request) { 16 | ww := middleware.NewWrapResponseWriter(w, r.ProtoMajor) 17 | 18 | ctxBuilder := mustGetContextBuilder(r) 19 | start := time.Now().UTC() 20 | 21 | next.ServeHTTP(ww, r) 22 | 23 | ctxBuilder.GetMetrics().ReportRequestEnd( 24 | metrics.RequestInfo{ 25 | ServiceName: ctxBuilder.ServiceContext().ServiceName(), 26 | Hostname: ctxBuilder.ServiceContext().Hostname(), 27 | URLPath: ctxBuilder.GetURLPath(), 28 | }, 29 | ww.Status(), 30 | time.Since(start), 31 | int(r.ContentLength), 32 | ww.BytesWritten()) 33 | } 34 | return http.HandlerFunc(fn) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /assets/openapi/server-template/go/openapi.mustache: -------------------------------------------------------------------------------- 1 | {{{openapi-yaml}}} 2 | -------------------------------------------------------------------------------- /assets/openapi/server-template/go/partial_header.mustache: -------------------------------------------------------------------------------- 1 | // THIS FILE IS AUTOGENERATED, DO NOT EDIT 2 | // Generated by mify via OpenAPI Generator 3 | -------------------------------------------------------------------------------- /assets/openapi/server-template/go/public/req_ctx_access.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | // vim: set ft=go: 3 | package {{packageName}}_public 4 | 5 | import ( 6 | "net/http" 7 | 8 | "{{mifyGeneratedServicePackage}}/core" 9 | ) 10 | 11 | type ctxKeyMifyContext int 12 | 13 | const MifyContextField ctxKeyMifyContext = 0 14 | 15 | // GetRequestContext allows getting current request context in between 16 | // middleware calls. This is useful for accessing sevice dependencies inside 17 | // middleware, while keeping the context flow intact. 18 | func GetMifyRequestContext(r *http.Request) *core.MifyRequestContext { 19 | return r.Context().Value(MifyContextField).(*core.MifyRequestContext) 20 | } 21 | -------------------------------------------------------------------------------- /assets/openapi/server-template/go/recoverer.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | // vim: set ft=go: 3 | 4 | package {{packageName}} 5 | 6 | import ( 7 | "fmt" 8 | "os" 9 | "net/http" 10 | "runtime" 11 | 12 | "go.uber.org/zap" 13 | ) 14 | 15 | func Recoverer() func(next http.Handler) http.Handler { 16 | const STACK_SIZE = 4 * 1024 * 1024 // 4 KB 17 | return func(next http.Handler) http.Handler { 18 | fn := func(w http.ResponseWriter, r *http.Request) { 19 | defer func() { 20 | if rc := recover(); rc != nil { 21 | if rc == http.ErrAbortHandler { 22 | panic(rc) 23 | } 24 | reqCtx := getMifyRequestContextBuilder(r) 25 | err, ok := rc.(error) 26 | if !ok { 27 | err = fmt.Errorf("%v", r) 28 | } 29 | var stack []byte 30 | var length int 31 | 32 | stack = make([]byte, STACK_SIZE) 33 | length = runtime.Stack(stack, true) 34 | stack = stack[:length] 35 | reqCtx.Logger().Error( 36 | "got panic in handler", 37 | zap.String("stacktrace", string(stack)), zap.Error(err)) 38 | fmt.Fprintf(os.Stderr, "panic: %s", string(stack)) 39 | w.WriteHeader(http.StatusInternalServerError) 40 | } 41 | }() 42 | next.ServeHTTP(w, r) 43 | } 44 | return http.HandlerFunc(fn) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /assets/openapi/server-template/go/swaggerui.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | package {{packageName}} 3 | // vim: set ft=go: 4 | 5 | import ( 6 | _ "embed" 7 | "net/http" 8 | 9 | "github.com/flowchartsman/swaggerui" 10 | ) 11 | 12 | //go:embed openapi.yaml 13 | var openapiYamlRaw []byte 14 | 15 | func SwaggerUIHandlerFunc(rw http.ResponseWriter, r *http.Request) { 16 | http.StripPrefix("/swagger-ui", swaggerui.Handler(openapiYamlRaw)).ServeHTTP(rw, r) 17 | } 18 | -------------------------------------------------------------------------------- /assets/openapi/server-template/js/app.mustache: -------------------------------------------------------------------------------- 1 | const ExpressServer = require('./expressServer'); 2 | const logger = require('./logger'); 3 | // const swaggerRouter = require('./utils/swaggerRouter'); 4 | 5 | class App { 6 | constructor(config) { 7 | this.config = config; 8 | } 9 | 10 | async launch() { 11 | try { 12 | this.expressServer = new ExpressServer(this.config.URL_PORT, this.config.OPENAPI_YAML); 13 | // this.expressServer.app.use(swaggerRouter()); 14 | await this.expressServer.launch(); 15 | logger.info('Express server running'); 16 | } catch (error) { 17 | logger.error(error); 18 | await this.close(); 19 | } 20 | } 21 | 22 | async close() { 23 | if (this.expressServer !== undefined) { 24 | await this.expressServer.close(); 25 | logger.info(`Server shut down on port ${this.config.URL_PORT}`); 26 | } 27 | } 28 | } 29 | 30 | module.exports = App; 31 | -------------------------------------------------------------------------------- /assets/openapi/server-template/js/config.mustache: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | const config = { 4 | ROOT_DIR: __dirname, 5 | URL_PORT: {{serverPort}}{{^serverPort}}3000{{/serverPort}}, 6 | URL_PATH: '{{serverHost}}{{^serverHost}}http://localhost{{/serverHost}}', 7 | BASE_VERSION: '{{contextPath}}{{^contextPath}}v2{{/contextPath}}', 8 | CONTROLLER_DIRECTORY: path.join(__dirname, 'controllers'), 9 | PROJECT_DIR: __dirname, 10 | }; 11 | config.OPENAPI_YAML = path.join(config.ROOT_DIR, 'api', 'openapi.yaml'); 12 | config.FULL_PATH = `${config.URL_PATH}:${config.URL_PORT}/${config.BASE_VERSION}`; 13 | config.FILE_UPLOAD_PATH = path.join(config.PROJECT_DIR, 'uploaded_files'); 14 | 15 | module.exports = config; 16 | -------------------------------------------------------------------------------- /assets/openapi/server-template/js/config.yaml: -------------------------------------------------------------------------------- 1 | generatorName: nodejs-express-server 2 | templateDir: /repo/.mify/assets/openapi/server-template/js 3 | enableMinimalUpdate: true 4 | globalProperties: {} 5 | additionalProperties: 6 | serverPort: 8080 7 | 8 | releaseNote: Release note 9 | httpUserAgent: User Agent 10 | 11 | apiPackage: handlers 12 | modelPackage: models 13 | 14 | invokerPackage: unused 15 | # packageName: api 16 | apiNameSuffix: Api 17 | modelNamePrefix: "" 18 | modelNameSuffix: "" 19 | artifactVersion: ARTIFACT_VERSION 20 | library: "" 21 | 22 | instantiationTypes: {} 23 | typeMappings: {} 24 | importMappings: {} 25 | languageSpecificPrimitives: [] 26 | reservedWordMappings: {} 27 | serverVariables: {} 28 | 29 | verbose: false 30 | skipOverwrite: false 31 | removeOperationIdPrefix: false 32 | skipOperationExample: false 33 | logToStderr: false 34 | validateSpec: true 35 | enablePostProcessFile: false 36 | strictSpecBehavior: true 37 | generateAliasAsModel: false 38 | templatingEngineName: mustache 39 | # ignoreFileOverride: "" 40 | -------------------------------------------------------------------------------- /assets/openapi/server-template/js/controller.mustache: -------------------------------------------------------------------------------- 1 | /** 2 | * The {{{classname}}}Controller file is a very simple one, which does not need to be changed manually, 3 | * unless there's a case where business logic routes the request to an entity which is not 4 | * the service. 5 | * The heavy lifting of the Controller item is done in Request.js - that is where request 6 | * parameters are extracted and sent to the service, and where response is handled. 7 | */ 8 | 9 | const Controller = require('./Controller'); 10 | const service = require('../services/{{{classname}}}Service'); 11 | {{#operations}} 12 | {{#operation}} 13 | const {{operationId}} = async (request, response) => { 14 | await Controller.handleRequest(request, response, service.{{operationId}}); 15 | }; 16 | 17 | {{/operation}} 18 | {{/operations}} 19 | 20 | module.exports = { 21 | {{#operations}} 22 | {{#operation}} 23 | {{operationId}}, 24 | {{/operation}} 25 | {{/operations}} 26 | }; 27 | -------------------------------------------------------------------------------- /assets/openapi/server-template/js/controllers/index.mustache: -------------------------------------------------------------------------------- 1 | {{#apiInfo}} 2 | {{#apis}} 3 | {{#operations}} 4 | {{#operation}} 5 | {{#-first}} 6 | const {{classname}}Controller = require('./{{classname}}Controller'); 7 | {{/-first}} 8 | {{/operation}} 9 | {{/operations}} 10 | {{/apis}} 11 | {{/apiInfo}} 12 | 13 | module.exports = { 14 | {{#apiInfo}} 15 | {{#apis}} 16 | {{#operations}} 17 | {{#operation}} 18 | {{#-first}} 19 | {{classname}}Controller, 20 | {{/-first}} 21 | {{/operation}} 22 | {{/operations}} 23 | {{/apis}} 24 | {{/apiInfo}} 25 | }; 26 | -------------------------------------------------------------------------------- /assets/openapi/server-template/js/eslintrc.mustache: -------------------------------------------------------------------------------- 1 | // Use this file as a starting point for your project's .eslintrc. 2 | // Copy this file, and add rule overrides as needed. 3 | { 4 | "extends": "airbnb-base", 5 | "rules": { 6 | "no-console": "off" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /assets/openapi/server-template/js/ignore-list.txt: -------------------------------------------------------------------------------- 1 | /Dockerfile 2 | /README.md 3 | /.gitignore 4 | -------------------------------------------------------------------------------- /assets/openapi/server-template/js/index.mustache: -------------------------------------------------------------------------------- 1 | const config = require('../mify-generated/services/{{serviceName}}/config'); 2 | const logger = require('../mify-generated/services/{{serviceName}}/logger'); 3 | const ExpressServer = require('../mify-generated/services/{{serviceName}}/expressServer'); 4 | 5 | const launchServer = async () => { 6 | try { 7 | this.expressServer = new ExpressServer(config.URL_PORT, config.OPENAPI_YAML); 8 | this.expressServer.launch(); 9 | logger.info('Express server running'); 10 | } catch (error) { 11 | logger.error('Express Server failure', error.message); 12 | await this.close(); 13 | } 14 | }; 15 | 16 | launchServer().catch(e => logger.error(e)); 17 | -------------------------------------------------------------------------------- /assets/openapi/server-template/js/logger.mustache: -------------------------------------------------------------------------------- 1 | const { transports, createLogger, format } = require('winston'); 2 | 3 | const logger = createLogger({ 4 | level: 'info', 5 | format: format.combine( 6 | format.timestamp(), 7 | format.json(), 8 | ), 9 | defaultMeta: { service: 'user-service' }, 10 | transports: [ 11 | new transports.Console(), 12 | new transports.File({ filename: 'error.log', level: 'error', timestamp: true }), 13 | new transports.File({ filename: 'combined.log', timestamp: true }), 14 | ], 15 | }); 16 | 17 | if (process.env.NODE_ENV !== 'production') { 18 | logger.add(new transports.Console({ format: format.simple() })); 19 | } 20 | 21 | module.exports = logger; 22 | -------------------------------------------------------------------------------- /assets/openapi/server-template/js/openapi.mustache: -------------------------------------------------------------------------------- 1 | {{{openapi-yaml}}} -------------------------------------------------------------------------------- /assets/openapi/server-template/js/package.mustache: -------------------------------------------------------------------------------- 1 | { 2 | "name": "{{projectName}}", 3 | "version": "{{appVersion}}", 4 | "description": "{{{appDescription}}}", 5 | "main": "index.js", 6 | "scripts": { 7 | "prestart": "npm install", 8 | "start": "node index.js", 9 | "dev": "node index.js" 10 | }, 11 | "keywords": [ 12 | "openapi-generator", 13 | "openapi" 14 | ], 15 | "license": "Unlicense", 16 | "private": true, 17 | "dependencies": { 18 | "body-parser": "^1.19.0", 19 | "camelcase": "^5.3.1", 20 | "cookie-parser": "^1.4.4", 21 | "cors": "^2.8.5", 22 | "express": "^4.18.2", 23 | "express-openapi-validator": "^5.0.4", 24 | "js-yaml": "^3.3.0", 25 | "ono": "^5.0.1", 26 | "openapi-sampler": "^1.0.0-beta.15", 27 | "swagger-ui-express": "^4.0.2", 28 | "winston": "^3.2.1" 29 | }, 30 | "devDependencies": { 31 | "axios": "^0.19.0", 32 | "chai": "^4.2.0", 33 | "chai-as-promised": "^7.1.1", 34 | "eslint": "^5.16.0", 35 | "eslint-config-airbnb-base": "^14.0.0", 36 | "eslint-plugin-import": "^2.17.2", 37 | "mocha": "^7.1.1", 38 | "typescript": "^5.1.3" 39 | }, 40 | "eslintConfig": { 41 | "env": { 42 | "node": true 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /assets/openapi/server-template/js/service.mustache: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | const Service = require('./Service'); 3 | 4 | {{#operations}} 5 | {{#operation}} 6 | /** 7 | {{#summary}} 8 | * {{{.}}} 9 | {{/summary}} 10 | {{#notes}} 11 | * {{{.}}} 12 | {{/notes}} 13 | * 14 | {{#allParams}} 15 | * {{paramName}} {{{dataType}}} {{{description}}}{{^required}} (optional){{/required}} 16 | {{/allParams}} 17 | {{^returnType}} 18 | * no response value expected for this operation 19 | {{/returnType}} 20 | {{#returnType}} 21 | * returns {{{.}}} 22 | {{/returnType}} 23 | * */ 24 | const {{{operationId}}} = ({{#allParams}}{{#-first}}{ {{/-first}}{{paramName}}{{^-last}}, {{/-last}}{{#-last}} }{{/-last}}{{/allParams}}) => new Promise( 25 | async (resolve, reject) => { 26 | try { 27 | resolve(Service.successResponse({ 28 | {{#allParams}} 29 | {{paramName}}, 30 | {{/allParams}} 31 | })); 32 | } catch (e) { 33 | reject(Service.rejectResponse( 34 | e.message || 'Invalid input', 35 | e.status || 405, 36 | )); 37 | } 38 | }, 39 | ); 40 | {{/operation}} 41 | {{/operations}} 42 | 43 | module.exports = { 44 | {{#operations}} 45 | {{#operation}} 46 | {{operationId}}, 47 | {{/operation}} 48 | {{/operations}} 49 | }; 50 | -------------------------------------------------------------------------------- /assets/openapi/server-template/js/services/Service.mustache: -------------------------------------------------------------------------------- 1 | class Service { 2 | static rejectResponse(error, code = 500) { 3 | return { error, code }; 4 | } 5 | 6 | static successResponse(payload, code = 200) { 7 | return { payload, code }; 8 | } 9 | } 10 | 11 | module.exports = Service; 12 | -------------------------------------------------------------------------------- /assets/openapi/server-template/js/services/index.mustache: -------------------------------------------------------------------------------- 1 | {{#apiInfo}} 2 | {{#apis}} 3 | {{#operations}} 4 | {{#operation}} 5 | {{#-first}} 6 | const {{classname}}Service = require('./{{classname}}Service'); 7 | {{/-first}} 8 | {{/operation}} 9 | {{/operations}} 10 | {{/apis}} 11 | {{/apiInfo}} 12 | 13 | module.exports = { 14 | {{#apiInfo}} 15 | {{#apis}} 16 | {{#operations}} 17 | {{#operation}} 18 | {{#-first}} 19 | {{classname}}Service, 20 | {{/-first}} 21 | {{/operation}} 22 | {{/operations}} 23 | {{/apis}} 24 | {{/apiInfo}} 25 | }; 26 | -------------------------------------------------------------------------------- /assets/openapi/server-template/js/utils/writer.mustache: -------------------------------------------------------------------------------- 1 | var ResponsePayload = function(code, payload) { 2 | this.code = code; 3 | this.payload = payload; 4 | } 5 | 6 | exports.respondWithCode = function(code, payload) { 7 | return new ResponsePayload(code, payload); 8 | } 9 | 10 | var writeJson = exports.writeJson = function(response, arg1, arg2) { 11 | var code; 12 | var payload; 13 | 14 | if(arg1 && arg1 instanceof ResponsePayload) { 15 | writeJson(response, arg1.payload, arg1.code); 16 | return; 17 | } 18 | 19 | if(arg2 && Number.isInteger(arg2)) { 20 | code = arg2; 21 | } 22 | else { 23 | if(arg1 && Number.isInteger(arg1)) { 24 | code = arg1; 25 | } 26 | } 27 | if(code && arg1) { 28 | payload = arg1; 29 | } 30 | else if(arg1) { 31 | payload = arg1; 32 | } 33 | 34 | if(!code) { 35 | // if no response code given, we default to 200 36 | code = 200; 37 | } 38 | if(typeof payload === 'object') { 39 | payload = JSON.stringify(payload, null, 2); 40 | } 41 | response.writeHead(code, {'Content-Type': 'application/json'}); 42 | response.end(payload); 43 | } 44 | -------------------------------------------------------------------------------- /assets/openapi/server-template/python/__init__.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | -------------------------------------------------------------------------------- /assets/openapi/server-template/python/__init__main.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | import os 4 | import connexion 5 | {{#featureCORS}} 6 | import aiohttp_cors 7 | {{/featureCORS}} 8 | 9 | def main(): 10 | options = { 11 | "swagger_ui": True 12 | } 13 | specification_dir = os.path.join(os.path.dirname(__file__), 'openapi') 14 | app = connexion.AioHttpApp(__name__, specification_dir=specification_dir, options=options) 15 | app.add_api('openapi.yaml', 16 | arguments={'title': '{{appName}}'}, 17 | pythonic_params=True, 18 | pass_context_arg_name='request') 19 | 20 | {{#featureCORS}} 21 | # Enable CORS for all origins. 22 | cors = aiohttp_cors.setup(app.app, defaults={ 23 | "*": aiohttp_cors.ResourceOptions( 24 | allow_credentials=True, 25 | expose_headers="*", 26 | allow_headers="*", 27 | ) 28 | }) 29 | 30 | # Register all routers for CORS. 31 | for route in list(app.app.router.routes()): 32 | cors.add(route) 33 | 34 | {{/featureCORS}} 35 | app.run(port={{serverPort}}) 36 | -------------------------------------------------------------------------------- /assets/openapi/server-template/python/__init__model.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | 4 | # import models into model package 5 | {{#models}}{{#model}}from {{packageName}}.{{modelPackage}}.{{classFilename}} import {{classname}}{{/model}} 6 | {{/models}} 7 | -------------------------------------------------------------------------------- /assets/openapi/server-template/python/__main__.mustache: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | {{>partial_header}} 3 | # vim: set ft=python: 4 | 5 | from . import main 6 | 7 | if __name__ == '__main__': 8 | main() 9 | -------------------------------------------------------------------------------- /assets/openapi/server-template/python/conftest.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | import logging 4 | import pytest 5 | import os 6 | 7 | import connexion 8 | 9 | 10 | @pytest.fixture 11 | def client(loop, aiohttp_client): 12 | logging.getLogger('connexion.operation').setLevel('ERROR') 13 | options = { 14 | "swagger_ui": True 15 | } 16 | specification_dir = os.path.join(os.path.dirname(__file__), '..',{{#pythonSrcRoot}} 17 | "{{{.}}}",{{/pythonSrcRoot}} 18 | '{{packageName}}', 19 | 'openapi') 20 | app = connexion.AioHttpApp(__name__, specification_dir=specification_dir, 21 | options=options) 22 | app.add_api('openapi.yaml', pythonic_params=True, 23 | pass_context_arg_name='request') 24 | return loop.run_until_complete(aiohttp_client(app.app)) 25 | -------------------------------------------------------------------------------- /assets/openapi/server-template/python/ignore-list.txt: -------------------------------------------------------------------------------- 1 | /Dockerfile 2 | /README.md 3 | /.gitignore 4 | /requirements.txt 5 | /test-requirements.txt 6 | /tox.ini 7 | /tests/* 8 | /setup.py 9 | -------------------------------------------------------------------------------- /assets/openapi/server-template/python/openapi.mustache: -------------------------------------------------------------------------------- 1 | {{{openapi-yaml}}} -------------------------------------------------------------------------------- /assets/openapi/server-template/python/param_type.mustache: -------------------------------------------------------------------------------- 1 | {{#isString}}str{{/isString}}{{#isInteger}}int{{/isInteger}}{{#isLong}}int{{/isLong}}{{#isFloat}}float{{/isFloat}}{{#isDouble}}float{{/isDouble}}{{#isByteArray}}str{{/isByteArray}}{{#isBinary}}str{{/isBinary}}{{#isBoolean}}bool{{/isBoolean}}{{#isDate}}str{{/isDate}}{{#isDateTime}}str{{/isDateTime}} -------------------------------------------------------------------------------- /assets/openapi/server-template/python/partial_header.mustache: -------------------------------------------------------------------------------- 1 | # THIS FILE IS AUTOGENERATED, DO NOT EDIT 2 | # Generated by mify via OpenAPI Generator 3 | -------------------------------------------------------------------------------- /assets/openapi/server-template/python/typing_utils.mustache: -------------------------------------------------------------------------------- 1 | {{>partial_header}} 2 | # vim: set ft=python: 3 | 4 | import sys 5 | 6 | if sys.version_info < (3, 7): 7 | import typing 8 | 9 | def is_generic(klass): 10 | """ Determine whether klass is a generic class """ 11 | return type(klass) == typing.GenericMeta 12 | 13 | def is_dict(klass): 14 | """ Determine whether klass is a Dict """ 15 | return klass.__extra__ == dict 16 | 17 | def is_list(klass): 18 | """ Determine whether klass is a List """ 19 | return klass.__extra__ == list 20 | 21 | else: 22 | 23 | def is_generic(klass): 24 | """ Determine whether klass is a generic class """ 25 | return hasattr(klass, '__origin__') 26 | 27 | def is_dict(klass): 28 | """ Determine whether klass is a Dict """ 29 | return klass.__origin__ == dict 30 | 31 | def is_list(klass): 32 | """ Determine whether klass is a List """ 33 | return klass.__origin__ == list 34 | -------------------------------------------------------------------------------- /cmd/mify/cmd/generate.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | "fmt" 7 | "os" 8 | 9 | "github.com/mify-io/mify/internal/mify" 10 | "github.com/spf13/cobra" 11 | ) 12 | 13 | var ( 14 | migrate bool 15 | force bool 16 | ) 17 | 18 | // genCmd represents the gen command 19 | var genCmd = &cobra.Command{ 20 | Use: "generate [service]...", 21 | Short: "Generate code in workspace", 22 | Long: `Generate code for given list of services after schema changes.`, 23 | PersistentPreRun: func(*cobra.Command, []string) { 24 | err := appContext.LoadWorkspace() 25 | if err != nil { 26 | fmt.Fprintf(os.Stderr, "failed to init workspace: %s\n", err) 27 | os.Exit(2) 28 | } 29 | }, 30 | Run: func(cmd *cobra.Command, args []string) { 31 | if err := mify.ServiceGenerateMany(appContext, workspacePath, args, migrate, force); err != nil { 32 | if errors.Is(err, context.Canceled) { 33 | return 34 | } 35 | fmt.Fprintf(os.Stderr, "%s", err) 36 | os.Exit(2) 37 | } 38 | }, 39 | } 40 | 41 | func init() { 42 | genCmd.Flags().BoolVarP( 43 | &migrate, 44 | "migrate", "m", true, "Should code migrations be applied?", 45 | ) 46 | genCmd.Flags().BoolVarP( 47 | &force, 48 | "force", "f", false, "Force complete regeneration", 49 | ) 50 | } 51 | -------------------------------------------------------------------------------- /cmd/mify/cmd/init.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/mify-io/mify/internal/mify" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | var ( 12 | vcsTemplate string 13 | ) 14 | 15 | // initCmd represents the init command 16 | var initCmd = &cobra.Command{ 17 | Use: "init", 18 | Short: "Initialize new workspace", 19 | Long: `Initialize new workspace`, 20 | Run: func(cmd *cobra.Command, args []string) { 21 | workspaceName := "." 22 | if len(args) > 0 { 23 | workspaceName = args[0] 24 | } 25 | 26 | if err := mify.CreateWorkspace(appContext, workspacePath, workspaceName, vcsTemplate); err != nil { 27 | fmt.Fprintf(os.Stderr, "failed to create workspace: %s\n", err) 28 | os.Exit(2) 29 | } 30 | }, 31 | } 32 | 33 | func init() { 34 | initCmd.LocalFlags().StringVar(&vcsTemplate, "vcs", "git", "[git|none]") 35 | } 36 | -------------------------------------------------------------------------------- /cmd/mify/cmd/run.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/mify-io/mify/internal/mify" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | // initCmd represents the init command 12 | var runCmd = &cobra.Command{ 13 | Use: "run", 14 | Short: "Run all go services", 15 | Long: `Run all go services in one dev-runner process`, 16 | PersistentPreRun: func(*cobra.Command, []string) { 17 | err := appContext.LoadWorkspace() 18 | if err != nil { 19 | fmt.Fprintf(os.Stderr, "failed to init workspace: %s\n", err) 20 | os.Exit(2) 21 | } 22 | }, 23 | Run: func(cmd *cobra.Command, args []string) { 24 | if err := mify.Run(appContext, workspacePath); err != nil { 25 | fmt.Fprintf(os.Stderr, "failed to run app: %s\n", err) 26 | os.Exit(2) 27 | } 28 | }, 29 | } 30 | 31 | func init() { 32 | } 33 | -------------------------------------------------------------------------------- /cmd/mify/cmd/tool.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/mify-io/mify/internal/mify" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | var migrateCmd = &cobra.Command{ 12 | Use: "migrate [-- -help -extra -args]", 13 | Short: "Run database migration on service locally", 14 | Long: `Run database migration on service locally`, 15 | Run: func(cmd *cobra.Command, args []string) { 16 | if len(args) < 2 { 17 | _ = cmd.Help() 18 | fmt.Fprintf(os.Stderr, "error: missing service-name and command\n") 19 | os.Exit(1) 20 | } 21 | serviceName := args[0] 22 | command := args[1] 23 | extraArgs := args[2:] 24 | if err := mify.ToolMigrate(appContext, workspacePath, serviceName, command, extraArgs); err != nil { 25 | fmt.Fprintf(os.Stderr, "failed to run migrate: %s\n", err) 26 | os.Exit(2) 27 | } 28 | }, 29 | } 30 | 31 | var toolCmd = &cobra.Command{ 32 | Use: "tool", 33 | Short: "Run external tool needed for development", 34 | Long: `Run some external tool which is needed for development`, 35 | } 36 | 37 | func init() { 38 | toolCmd.AddCommand(migrateCmd) 39 | } 40 | -------------------------------------------------------------------------------- /cmd/mify/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/mify-io/mify/cmd/mify/cmd" 4 | 5 | func main() { 6 | cmd.Execute() 7 | } 8 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | /node_modules 3 | 4 | # Production 5 | /build 6 | 7 | # Generated files 8 | .docusaurus 9 | .cache-loader 10 | 11 | # Misc 12 | .DS_Store 13 | .env.local 14 | .env.development.local 15 | .env.test.local 16 | .env.production.local 17 | 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* 21 | -------------------------------------------------------------------------------- /docs/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:lts-alpine as builder 2 | 3 | WORKDIR /app 4 | 5 | COPY ./mify-docs . 6 | 7 | WORKDIR /app/mify-docs 8 | 9 | RUN yarn install \ 10 | --prefer-offline \ 11 | --frozen-lockfile \ 12 | --non-interactive \ 13 | --production=false 14 | 15 | RUN yarn build 16 | 17 | RUN rm -rf node_modules && \ 18 | NODE_ENV=production yarn install \ 19 | --prefer-offline \ 20 | --pure-lockfile \ 21 | --non-interactive \ 22 | --production=true 23 | 24 | FROM node:lts-alpine 25 | 26 | WORKDIR /app 27 | 28 | COPY --from=builder /app . 29 | 30 | WORKDIR /app/mify-docs 31 | 32 | ENV HOST 0.0.0.0 33 | ENV PORT 80 34 | EXPOSE 80 35 | 36 | CMD [ "yarn", "start" ] 37 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Website 2 | 3 | This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator. 4 | 5 | ### Installation 6 | 7 | ``` 8 | $ yarn 9 | ``` 10 | 11 | ### Local Development 12 | 13 | ``` 14 | $ yarn start 15 | ``` 16 | 17 | This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server. 18 | 19 | ### Build 20 | 21 | ``` 22 | $ yarn build 23 | ``` 24 | 25 | This command generates static content into the `build` directory and can be served using any static contents hosting service. 26 | 27 | ### Deployment 28 | 29 | Using SSH: 30 | 31 | ``` 32 | $ USE_SSH=true yarn deploy 33 | ``` 34 | 35 | Not using SSH: 36 | 37 | ``` 38 | $ GIT_USER= yarn deploy 39 | ``` 40 | 41 | If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. 42 | -------------------------------------------------------------------------------- /docs/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [require.resolve('@docusaurus/core/lib/babel/preset')], 3 | }; 4 | -------------------------------------------------------------------------------- /docs/docs/components/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Components", 3 | "position": 4, 4 | "collapsed": false 5 | } 6 | -------------------------------------------------------------------------------- /docs/docs/getting-started/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Get Started", 3 | "position": 2, 4 | "collapsed": false 5 | } 6 | -------------------------------------------------------------------------------- /docs/docs/getting-started/cli.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 3 3 | --- 4 | 5 | # Mify CLI Reference 6 | 7 | Global flags: 8 | 9 | `-h, --help` help for mify. 10 | 11 | `-p, --path string` Path to workspace (if you're calling CLI outside directory). 12 | 13 | `-v, --verbose` Show verbose output. 14 | 15 | Commands: 16 | 17 | `mify init ` Initialize new workspace. 18 | 19 | `mify add service --language go|python` Generate service. 20 | 21 | `mify add frontend ` Generate frontend. 22 | 23 | `mify add client --to ` Generate a client for service. 24 | 25 | `mify remove client --to ` Generate a client for service. 26 | 27 | `mify generate ` Generate or regenerate code in workspace. 28 | -------------------------------------------------------------------------------- /docs/docs/guides/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Guides", 3 | "position": 3, 4 | "collapsed": false 5 | } 6 | -------------------------------------------------------------------------------- /docs/docs/guides/create-frontend/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Writing Counting Frontend", 3 | "position": 4, 4 | "collapsed": false 5 | } 6 | -------------------------------------------------------------------------------- /docs/docs/guides/create-frontend/building-and-testing-all-together.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 2 3 | --- 4 | 5 | # Building and Testing With Backend 6 | 7 | To build frontend first we need to go to `js-services/counter-display` directory and install dependencies: 8 | ``` 9 | $ cd js-services/counter-display 10 | $ yarn install 11 | ``` 12 | 13 | *Note: if you're using Ubuntu 20.04, this command won't work, because default 14 | node is too old, please install node >= 18.12.1.* 15 | 16 | Then we can run it: 17 | 18 | ``` 19 | $ yarn dev 20 | ``` 21 | 22 | :::info 23 | 24 | Don't forget to keep backend running using commands from [Building and Testing](/docs/guides/create-service/building-and-testing) backend section. 25 | 26 | ::: 27 | 28 | Frontend service should be available at: [http://localhost:3000](http://localhost:3000]) 29 | 30 | You should see counter updating with every page refresh. 31 | 32 | ![](/img/docs/frontend-result.png) 33 | 34 | That's it for out tutorial! Check out other sections to see all the components that Mify can provide. 35 | -------------------------------------------------------------------------------- /docs/docs/guides/create-frontend/skeleton.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 0 3 | --- 4 | 5 | import Tabs from '@theme/Tabs'; 6 | import TabItem from '@theme/TabItem'; 7 | 8 | # Generating Frontend Layout 9 | 10 | Time to implement frontend, same as with backend service we begin with adding it 11 | to our workspace: 12 | 13 | 14 | 15 | 16 | ``` 17 | mify add frontend --template react-ts counter-display 18 | ``` 19 | 20 | 21 | 22 | 23 | ``` 24 | mify add frontend --template nuxtjs counter-display 25 | ``` 26 | 27 | 28 | 29 | 30 | To access backend we also need to add client to our frontend: 31 | 32 | ``` 33 | mify add client counter-display --to counting-backend 34 | ``` 35 | -------------------------------------------------------------------------------- /docs/docs/guides/create-service/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Writing Counting Service", 3 | "position": 1, 4 | "collapsed": false 5 | } 6 | -------------------------------------------------------------------------------- /docs/docs/guides/overview.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 0 3 | --- 4 | 5 | # Overview 6 | 7 | In these guides we'll describe how to create a simple service using Mify CLI. 8 | 9 | We will create a counting service, which will return always increasing number 10 | and a simple frontend which will display it. 11 | 12 | To start let's create a workspace for this project: 13 | 14 | ``` 15 | mify init counting-project 16 | cd counting-project 17 | ``` 18 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docs", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "docusaurus": "docusaurus", 7 | "start": "docusaurus serve --port 80 --host 0.0.0.0", 8 | "dev": "docusaurus start --host 0.0.0.0", 9 | "build": "docusaurus build", 10 | "swizzle": "docusaurus swizzle", 11 | "deploy": "docusaurus deploy", 12 | "clear": "docusaurus clear", 13 | "serve": "docusaurus serve", 14 | "write-translations": "docusaurus write-translations", 15 | "write-heading-ids": "docusaurus write-heading-ids" 16 | }, 17 | "dependencies": { 18 | "@docusaurus/core": "^3.1.0", 19 | "@docusaurus/plugin-google-gtag": "^3.1.0", 20 | "@docusaurus/preset-classic": "^3.1.0", 21 | "@mdx-js/react": "^1.6.21", 22 | "clsx": "^2.0.0", 23 | "prism-react-renderer": "^2.3.0", 24 | "react": "^18.0.0", 25 | "react-dom": "^18.0.0" 26 | }, 27 | "browserslist": { 28 | "production": [ 29 | ">0.5%", 30 | "not dead", 31 | "not op_mini all" 32 | ], 33 | "development": [ 34 | "last 1 chrome version", 35 | "last 1 firefox version", 36 | "last 1 safari version" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /docs/sidebars.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creating a sidebar enables you to: 3 | - create an ordered group of docs 4 | - render a sidebar for each doc of that group 5 | - provide next/previous navigation 6 | 7 | The sidebars can be generated from the filesystem, or explicitly defined here. 8 | 9 | Create as many sidebars as you want. 10 | */ 11 | 12 | // @ts-check 13 | 14 | /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ 15 | const sidebars = { 16 | // By default, Docusaurus generates a sidebar from the docs folder structure 17 | tutorialSidebar: [{type: 'autogenerated', dirName: '.'}], 18 | 19 | // But you can create a sidebar manually 20 | /* 21 | tutorialSidebar: [ 22 | { 23 | type: 'category', 24 | label: 'Tutorial', 25 | items: ['hello'], 26 | }, 27 | ], 28 | */ 29 | }; 30 | 31 | module.exports = sidebars; 32 | -------------------------------------------------------------------------------- /docs/src/pages1/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {Redirect} from '@docusaurus/router'; 3 | export default function Home() { 4 | return ; 5 | } 6 | -------------------------------------------------------------------------------- /docs/src/pages1/index.module.css: -------------------------------------------------------------------------------- 1 | /** 2 | * CSS files with the .module.css suffix will be treated as CSS modules 3 | * and scoped locally. 4 | */ 5 | 6 | .heroBanner { 7 | padding: 4rem 0; 8 | text-align: center; 9 | position: relative; 10 | overflow: hidden; 11 | } 12 | 13 | @media screen and (max-width: 966px) { 14 | .heroBanner { 15 | padding: 2rem; 16 | } 17 | } 18 | 19 | .buttons { 20 | display: flex; 21 | align-items: center; 22 | justify-content: center; 23 | } 24 | -------------------------------------------------------------------------------- /docs/static/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/docs/static/.nojekyll -------------------------------------------------------------------------------- /docs/static/img/docs/cloud-get-token.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/docs/static/img/docs/cloud-get-token.png -------------------------------------------------------------------------------- /docs/static/img/docs/frontend-result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/docs/static/img/docs/frontend-result.png -------------------------------------------------------------------------------- /docs/static/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/docs/static/img/favicon.ico -------------------------------------------------------------------------------- /docs/static/img/logo-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/docs/static/img/logo-white.png -------------------------------------------------------------------------------- /docs/static/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/docs/static/img/logo.png -------------------------------------------------------------------------------- /internal/mify/client.go: -------------------------------------------------------------------------------- 1 | package mify 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/mify-io/mify/pkg/workspace/mutators/client" 7 | ) 8 | 9 | func AddClient(ctx *CliContext, basePath string, name string, clientName string) error { 10 | err := client.AddClient(ctx.MustGetMutatorContext(), name, clientName) 11 | if err != nil { 12 | return fmt.Errorf("can't add client: %w", err) 13 | } 14 | 15 | if err = ServiceGenerate(ctx, basePath, name, false, false); err != nil { 16 | return fmt.Errorf("error during generation: %w", err) 17 | } 18 | 19 | return nil 20 | } 21 | 22 | func RemoveClient(ctx *CliContext, basePath string, name string, clientName string) error { 23 | err := client.RemoveClient(ctx.MustGetMutatorContext(), name, clientName) 24 | if err != nil { 25 | return err 26 | } 27 | 28 | return ServiceGenerate(ctx, basePath, name, false, false) 29 | } 30 | -------------------------------------------------------------------------------- /internal/mify/cloud/auth/auth.go: -------------------------------------------------------------------------------- 1 | package auth 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | 7 | "github.com/go-resty/resty/v2" 8 | "github.com/mify-io/mify/pkg/cloudconfig" 9 | ) 10 | 11 | func ResolveAccessToken(apiToken string) (string, error) { 12 | accessToken, err := getAccessToken(apiToken) 13 | if err != nil { 14 | return "", fmt.Errorf("token validation error: %w", err) 15 | } 16 | 17 | return accessToken, nil 18 | } 19 | 20 | func getAccessToken(token string) (string, error) { 21 | endpoint := fmt.Sprintf("%s/auth/token/service", cloudconfig.GetCloudApiURL()) 22 | var reqData struct { 23 | RefreshToken string `json:"refresh_token"` 24 | } 25 | var respData struct { 26 | AccessToken string `json:"access_token"` 27 | } 28 | reqData.RefreshToken = token 29 | client := resty.New() 30 | resp, err := client.R().SetBody(reqData).SetResult(&respData).Post(endpoint) 31 | if err != nil { 32 | return "", fmt.Errorf("request to get token failed: %w", err) 33 | } 34 | if resp.StatusCode() != http.StatusOK { 35 | return "", fmt.Errorf("request to get token error: %s", resp.Status()) 36 | } 37 | return respData.AccessToken, nil 38 | } 39 | -------------------------------------------------------------------------------- /internal/mify/database.go: -------------------------------------------------------------------------------- 1 | package mify 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/mify-io/mify/pkg/workspace/mutators/database" 7 | ) 8 | 9 | func AddPostgres(ctx *CliContext, basePath string, serviceName string) error { 10 | err := database.AddPostgres(ctx.MustGetMutatorContext(), serviceName) 11 | if err != nil { 12 | return fmt.Errorf("can't add postgres: %w", err) 13 | } 14 | 15 | if err = ServiceGenerate(ctx, basePath, serviceName, false, false); err != nil { 16 | return fmt.Errorf("error during generation: %w", err) 17 | } 18 | 19 | return nil 20 | } 21 | 22 | func RemovePostgres(ctx *CliContext, basePath string, serviceName string) error { 23 | err := database.RemovePostgres(ctx.MustGetMutatorContext(), serviceName) 24 | if err != nil { 25 | return err 26 | } 27 | 28 | return ServiceGenerate(ctx, basePath, serviceName, false, false) 29 | } 30 | -------------------------------------------------------------------------------- /internal/mify/run.go: -------------------------------------------------------------------------------- 1 | package mify 2 | 3 | import ( 4 | "os" 5 | "os/exec" 6 | "strings" 7 | 8 | "github.com/mify-io/mify/pkg/workspace" 9 | ) 10 | 11 | func Run(ctx *CliContext, basePath string) error { 12 | if err := ServiceGenerate(ctx, basePath, workspace.DevRunnerName, false, false); err != nil { 13 | return err 14 | } 15 | 16 | workspace, err := workspace.InitDescription(basePath) 17 | if err != nil { 18 | return err 19 | } 20 | 21 | // TODO: find go in system 22 | devRunnerMainPath := workspace.GetDevRunnerMainRelPath() 23 | goServicesPath := workspace.GetGoServicesRelPath() 24 | 25 | devRunnerCmd := exec.Command("go", "run", "."+strings.TrimLeft(devRunnerMainPath, goServicesPath)) 26 | devRunnerCmd.Dir = workspace.GetGoServicesAbsPath() 27 | devRunnerCmd.Stderr = os.Stderr 28 | devRunnerCmd.Stdout = os.Stdout 29 | 30 | err = devRunnerCmd.Start() 31 | if err != nil { 32 | return err 33 | } 34 | 35 | err = devRunnerCmd.Wait() 36 | if err != nil { 37 | return err 38 | } 39 | 40 | return nil 41 | } 42 | -------------------------------------------------------------------------------- /internal/mify/service.go: -------------------------------------------------------------------------------- 1 | package mify 2 | 3 | import ( 4 | "github.com/mify-io/mify/pkg/mifyconfig" 5 | "github.com/mify-io/mify/pkg/workspace" 6 | "github.com/mify-io/mify/pkg/workspace/mutators/service" 7 | ) 8 | 9 | func CreateService(ctx *CliContext, basePath string, language string, template string, name string) error { 10 | mutCtx := ctx.MustGetMutatorContext() 11 | conf, err := service.CreateService(mutCtx, mifyconfig.ServiceLanguage(language), template, name) 12 | if err != nil { 13 | return err 14 | } 15 | 16 | return ServiceGenerate(ctx, basePath, conf.ServiceName, false, false) 17 | } 18 | 19 | func CreateFrontend(ctx *CliContext, basePath string, template string, name string) error { 20 | mutCtx := ctx.MustGetMutatorContext() 21 | err := service.CreateFrontend(mutCtx, template, name) 22 | if err != nil { 23 | return err 24 | } 25 | 26 | return ServiceGenerate(ctx, basePath, name, false, false) 27 | } 28 | 29 | func CreateApiGateway(ctx *CliContext) error { 30 | mutCtx := ctx.MustGetMutatorContext() 31 | err := service.CreateApiGateway(mutCtx) 32 | if err != nil { 33 | return err 34 | } 35 | 36 | return ServiceGenerate(ctx, ctx.WorkspacePath, workspace.ApiGatewayName, false, false) 37 | } 38 | -------------------------------------------------------------------------------- /internal/mify/tests/integration/.gitignore: -------------------------------------------------------------------------------- 1 | results -------------------------------------------------------------------------------- /internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.0.approved.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.0.approved.tar -------------------------------------------------------------------------------- /internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.1.approved.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.1.approved.tar -------------------------------------------------------------------------------- /internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.10.approved.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.10.approved.tar -------------------------------------------------------------------------------- /internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.11.approved.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.11.approved.tar -------------------------------------------------------------------------------- /internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.12.approved.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.12.approved.tar -------------------------------------------------------------------------------- /internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.13.approved.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.13.approved.tar -------------------------------------------------------------------------------- /internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.14.approved.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.14.approved.tar -------------------------------------------------------------------------------- /internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.2.approved.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.2.approved.tar -------------------------------------------------------------------------------- /internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.3.approved.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.3.approved.tar -------------------------------------------------------------------------------- /internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.4.approved.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.4.approved.tar -------------------------------------------------------------------------------- /internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.5.approved.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.5.approved.tar -------------------------------------------------------------------------------- /internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.6.approved.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.6.approved.tar -------------------------------------------------------------------------------- /internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.7.approved.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.7.approved.tar -------------------------------------------------------------------------------- /internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.8.approved.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.8.approved.tar -------------------------------------------------------------------------------- /internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.9.approved.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/internal/mify/tests/integration/data/TestFullFlow1/TestFullFlow1.9.approved.tar -------------------------------------------------------------------------------- /internal/mify/userinput/userinput.go: -------------------------------------------------------------------------------- 1 | package userinput 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "strings" 8 | ) 9 | 10 | type UserInput struct { 11 | } 12 | 13 | func (ui UserInput) AskInput(format string, a ...interface{}) (string, error) { 14 | println(fmt.Sprintf(format, a...)) 15 | print("> ") 16 | 17 | reader := bufio.NewReader(os.Stdin) 18 | data, err := reader.ReadString('\n') 19 | if err != nil { 20 | return "", err 21 | } 22 | 23 | return strings.TrimSpace(data), nil 24 | } 25 | -------------------------------------------------------------------------------- /internal/mify/util/args.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | func ValidateStrArg(arg string, allowed []string) error { 9 | found := false 10 | for _, t := range allowed { 11 | if arg == t { 12 | found = true 13 | break 14 | } 15 | } 16 | 17 | if !found { 18 | return fmt.Errorf( 19 | "value '%s' is not allowed. List of possible args: [%s]", 20 | arg, strings.Join(allowed, ",")) 21 | } 22 | 23 | return nil 24 | } 25 | -------------------------------------------------------------------------------- /internal/mify/util/atomic_bool.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import "sync/atomic" 4 | 5 | type AtomicBool struct{ flag int32 } 6 | 7 | func (b *AtomicBool) Store(value bool) { 8 | var i int32 = 0 9 | if value { 10 | i = 1 11 | } 12 | atomic.StoreInt32(&(b.flag), int32(i)) 13 | } 14 | 15 | func (b *AtomicBool) Load() bool { 16 | return atomic.LoadInt32(&(b.flag)) != 0 17 | } 18 | -------------------------------------------------------------------------------- /internal/mify/util/safe_names.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import "strings" 4 | 5 | func ToSafeGoVariableName(name string) string { 6 | return strings.Replace(name, "-", "_", -1) 7 | } 8 | -------------------------------------------------------------------------------- /internal/mify/util/set.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | func StringSetAppend(set []string, vals ...string) []string { 4 | mp := make(map[string]struct{}, len(set)) 5 | for _, val := range set { 6 | mp[val] = struct{}{} 7 | } 8 | for _, v := range vals { 9 | if _, ok := mp[v]; !ok { 10 | mp[v] = struct{}{} 11 | set = append(set, v) 12 | } 13 | } 14 | return set 15 | } 16 | -------------------------------------------------------------------------------- /internal/mify/util/yaml.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "os" 5 | 6 | "gopkg.in/yaml.v2" 7 | ) 8 | 9 | type YAMLData struct { 10 | path string 11 | } 12 | 13 | func NewYAMLData(path string) YAMLData { 14 | return YAMLData{ 15 | path: path, 16 | } 17 | } 18 | 19 | func (d *YAMLData) ReadFile(out interface{}) error { 20 | f, err := os.Open(d.path) 21 | if err != nil { 22 | return err 23 | } 24 | 25 | err = yaml.NewDecoder(f).Decode(out) 26 | if err != nil { 27 | return err 28 | } 29 | return nil 30 | } 31 | 32 | func (d *YAMLData) SaveFile(in interface{}) error { 33 | f, err := os.OpenFile(d.path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) 34 | if err != nil { 35 | return err 36 | } 37 | 38 | err = yaml.NewEncoder(f).Encode(in) 39 | if err != nil { 40 | return err 41 | } 42 | return nil 43 | } 44 | -------------------------------------------------------------------------------- /pkg/cloudconfig/api.go: -------------------------------------------------------------------------------- 1 | package cloudconfig 2 | 3 | import "os" 4 | 5 | const DEFAULT_CLOUD_URL = "https://cloud.mify.io" 6 | const DEFAULT_CLOUD_API_URL = "https://cloud.mify.io/api" 7 | const DEFAULT_STATS_API_URL = "https://cloud.mify.io/api-stats" 8 | 9 | func GetCloudUrl() string { 10 | return DEFAULT_CLOUD_URL 11 | } 12 | 13 | func GetCloudApiURL() string { 14 | env := os.Getenv("MIFY_CLOUD_API_URL") 15 | if env != "" { 16 | return env 17 | } 18 | return DEFAULT_CLOUD_API_URL 19 | } 20 | 21 | func GetStatsApiUrl() string { 22 | env := os.Getenv("MIFY_STATS_API_URL") 23 | if env != "" { 24 | return env 25 | } 26 | return DEFAULT_STATS_API_URL 27 | } 28 | -------------------------------------------------------------------------------- /pkg/generator/core/pipeline_builder.go: -------------------------------------------------------------------------------- 1 | package core 2 | 3 | type PipelineBuilder struct { 4 | steps []Step 5 | } 6 | 7 | func NewPipelineBuilder() *PipelineBuilder { 8 | return &PipelineBuilder{ 9 | steps: make([]Step, 0), 10 | } 11 | } 12 | 13 | func (pb *PipelineBuilder) Register(step Step) *PipelineBuilder { 14 | pb.steps = append(pb.steps, step) 15 | return pb 16 | } 17 | 18 | func (pb *PipelineBuilder) Build() Pipeline { 19 | return Pipeline{ 20 | steps: pb.steps, 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /pkg/generator/core/step.go: -------------------------------------------------------------------------------- 1 | package core 2 | 3 | import gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 4 | 5 | type StepResult int 6 | 7 | const ( 8 | Done StepResult = 0 9 | RepeatAll StepResult = 1 10 | ) 11 | 12 | type Step interface { 13 | Name() string 14 | Execute(*gencontext.GenContext) (StepResult, error) 15 | } 16 | -------------------------------------------------------------------------------- /pkg/generator/gen-context/execute_pool.go: -------------------------------------------------------------------------------- 1 | package gencontext 2 | 3 | import "sync" 4 | 5 | type ExecutePoolFactory struct { 6 | } 7 | 8 | type ExecutePool struct { 9 | wg sync.WaitGroup 10 | results []chan error 11 | } 12 | 13 | func (ep *ExecutePool) Execute(work func() error) chan error { 14 | res := make(chan error) 15 | go func() { 16 | err := work() 17 | res <- err 18 | }() 19 | 20 | return res 21 | } 22 | 23 | func (ep *ExecutePool) EnqueExecution(work func() error) { 24 | ep.wg.Add(1) 25 | 26 | res := make(chan error) 27 | ep.results = append(ep.results, res) 28 | go func() { 29 | err := work() 30 | ep.wg.Done() 31 | res <- err 32 | }() 33 | } 34 | 35 | func (ep *ExecutePool) WaitAll() []error { 36 | ep.wg.Wait() 37 | errList := make([]error, 0, len(ep.results)) 38 | for _, resChan := range ep.results { 39 | res := <-resChan 40 | if res != nil { 41 | errList = append(errList, res) 42 | } 43 | } 44 | 45 | ep.results = make([]chan error, 0) 46 | 47 | if len(errList) == 0 { 48 | return nil 49 | } 50 | 51 | return errList 52 | } 53 | 54 | func (ep *ExecutePoolFactory) NewPool() ExecutePool { 55 | return ExecutePool{} 56 | } 57 | -------------------------------------------------------------------------------- /pkg/generator/pipelines.go: -------------------------------------------------------------------------------- 1 | package generator 2 | 3 | import ( 4 | "github.com/mify-io/mify/pkg/generator/core" 5 | apigateway "github.com/mify-io/mify/pkg/generator/steps/api-gateway" 6 | devrunner "github.com/mify-io/mify/pkg/generator/steps/dev-runner" 7 | "github.com/mify-io/mify/pkg/generator/steps/migrate" 8 | "github.com/mify-io/mify/pkg/generator/steps/layout" 9 | mifygenerated "github.com/mify-io/mify/pkg/generator/steps/mify-generated" 10 | "github.com/mify-io/mify/pkg/generator/steps/openapi" 11 | "github.com/mify-io/mify/pkg/generator/steps/postgres" 12 | "github.com/mify-io/mify/pkg/generator/steps/prepare" 13 | "github.com/mify-io/mify/pkg/generator/steps/schema" 14 | ) 15 | 16 | func BuildServicePipeline() core.Pipeline { 17 | return core.NewPipelineBuilder(). 18 | Register(schema.NewSchemaStep()). 19 | Register(prepare.NewPrepareStep()). 20 | Register(apigateway.NewApiGatewaySchemaStep()). 21 | Register(migrate.NewMigrateStep()). 22 | Register(openapi.NewOpenapiStep()). 23 | Register(postgres.NewPostgresStep()). 24 | Register(layout.NewLayoutStep()). 25 | Register(mifygenerated.NewMifyGeneratedStep()). 26 | Register(devrunner.NewDevRunnerStep()). 27 | Build() 28 | } 29 | -------------------------------------------------------------------------------- /pkg/generator/steps/api-gateway/context/context.go: -------------------------------------------------------------------------------- 1 | package context 2 | 3 | type ApiGatewayContext struct { 4 | } 5 | -------------------------------------------------------------------------------- /pkg/generator/steps/api-gateway/step.go: -------------------------------------------------------------------------------- 1 | package apigateway 2 | 3 | import ( 4 | "github.com/mify-io/mify/pkg/generator/core" 5 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 6 | ) 7 | 8 | const ( 9 | ApiGatewayName = "api-gateway" // TODO: it is not right place to declare it 10 | ) 11 | 12 | type ApiGatewaySchemaStep struct { 13 | } 14 | 15 | func NewApiGatewaySchemaStep() ApiGatewaySchemaStep { 16 | return ApiGatewaySchemaStep{} 17 | } 18 | 19 | func (s ApiGatewaySchemaStep) Name() string { 20 | return "api-gateway-schema" 21 | } 22 | 23 | func (s ApiGatewaySchemaStep) Execute(ctx *gencontext.GenContext) (core.StepResult, error) { 24 | if ctx.GetServiceName() != ApiGatewayName { 25 | return core.Done, nil 26 | } 27 | 28 | res, err := execute(ctx) 29 | if err != nil { 30 | return core.Done, err 31 | } 32 | 33 | return res, nil 34 | } 35 | -------------------------------------------------------------------------------- /pkg/generator/steps/dev-runner/context/context.go: -------------------------------------------------------------------------------- 1 | package context 2 | 3 | type DevRunnerContext struct { 4 | } 5 | -------------------------------------------------------------------------------- /pkg/generator/steps/dev-runner/step.go: -------------------------------------------------------------------------------- 1 | package devrunner 2 | 3 | import ( 4 | _ "embed" 5 | 6 | "github.com/mify-io/mify/pkg/generator/core" 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/mifyconfig" 9 | "github.com/mify-io/mify/pkg/workspace" 10 | ) 11 | 12 | type DevRunnerStep struct { 13 | } 14 | 15 | func NewDevRunnerStep() DevRunnerStep { 16 | return DevRunnerStep{} 17 | } 18 | 19 | func (s DevRunnerStep) Name() string { 20 | return "dev-runner" 21 | } 22 | 23 | func (s DevRunnerStep) Execute(ctx *gencontext.GenContext) (core.StepResult, error) { 24 | if ctx.GetServiceName() != workspace.DevRunnerName { 25 | return core.Done, nil 26 | } 27 | // TODO: add language property for dev-runner, for now hardcode Go 28 | lang := mifyconfig.ServiceLanguageGo 29 | if !ctx.GetWorkspace().Config.GeneratorParams.Template[lang].DevRunner.Enabled { 30 | ctx.Logger.Info("skipping disabled step") 31 | return core.Done, nil 32 | } 33 | 34 | if err := execute(ctx); err != nil { 35 | return core.Done, err 36 | } 37 | 38 | return core.Done, nil 39 | } 40 | -------------------------------------------------------------------------------- /pkg/generator/steps/dev-runner/tpl/main.go: -------------------------------------------------------------------------------- 1 | package tpl 2 | 3 | type TargetService struct { 4 | Name string 5 | SafeName string 6 | AppIncludePath string 7 | } 8 | 9 | func NewTargetService(name string, safeName string, appIncludePath string) TargetService { 10 | return TargetService{ 11 | Name: name, 12 | SafeName: safeName, 13 | AppIncludePath: appIncludePath, 14 | } 15 | } 16 | 17 | type Model struct { 18 | Header string 19 | Services []TargetService 20 | } 21 | 22 | func NewModel(header string, services []TargetService) Model { 23 | return Model{ 24 | Header: header, 25 | Services: services, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /pkg/generator/steps/dev-runner/tpl/main.go.tpl: -------------------------------------------------------------------------------- 1 | {{- .Header}} 2 | 3 | package main 4 | 5 | {{if .Services }} 6 | 7 | import ( 8 | "context" 9 | {{- range $key, $value := .Services }} 10 | {{ $value.SafeName }} "{{ $value.AppIncludePath -}}" 11 | {{- end }} 12 | ) 13 | 14 | func main() { 15 | ctx, cancel := context.WithCancel(context.Background()) 16 | {{ range $key, $value := .Services }} 17 | app_{{ $value.SafeName }} := {{ $value.SafeName }}.NewMifyServiceApp(ctx) 18 | go func() { 19 | app_{{ $value.SafeName }}.Run() 20 | cancel() 21 | }() 22 | {{ end }} 23 | <-ctx.Done() 24 | } 25 | 26 | {{else}} 27 | func main() { 28 | } 29 | {{end}} 30 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/helpers/base_model.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | type GeneratedBaseModel struct { 4 | TplHeader string 5 | } 6 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/helpers/js/names.go: -------------------------------------------------------------------------------- 1 | package js 2 | 3 | import ( 4 | "strings" 5 | "unicode" 6 | ) 7 | 8 | func SanitizeServiceName(serviceName string) string { 9 | if unicode.IsDigit(rune(serviceName[0])) { 10 | serviceName = "service_" + serviceName 11 | } 12 | serviceName = strings.ReplaceAll(serviceName, "-", "_") 13 | 14 | return serviceName 15 | } 16 | 17 | func MakeServerEnvName(serviceName string) string { 18 | sanitizedName := SanitizeServiceName(serviceName) 19 | return strings.ToUpper(sanitizedName) + "_SERVER_ENDPOINT" 20 | } 21 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/step.go: -------------------------------------------------------------------------------- 1 | package layout 2 | 3 | import ( 4 | _ "embed" 5 | 6 | "github.com/mify-io/mify/pkg/generator/core" 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | ) 9 | 10 | type LayoutStep struct { 11 | } 12 | 13 | func NewLayoutStep() LayoutStep { 14 | return LayoutStep{} 15 | } 16 | 17 | func (s LayoutStep) Name() string { 18 | return "layout" 19 | } 20 | 21 | func (s LayoutStep) Execute(ctx *gencontext.GenContext) (core.StepResult, error) { 22 | if ctx.GetMifySchema() != nil && !ctx.MustGetMifySchema().Components.Layout.Enabled { 23 | ctx.Logger.Info("skipping disabled step") 24 | return core.Done, nil 25 | } 26 | if err := execute(ctx); err != nil { 27 | return core.Done, err 28 | } 29 | 30 | return core.Done, nil 31 | } 32 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/cmd/_service_/Dockerfile.tpl: -------------------------------------------------------------------------------- 1 | FROM golang:1.19 AS build 2 | WORKDIR /go/src 3 | COPY . . 4 | 5 | ENV CGO_ENABLED=0 6 | ENV GOARCH=amd64 7 | RUN go get -d -v ./... 8 | 9 | RUN go build -a -installsuffix cgo -o {{.ServiceName}} ./cmd/{{.ServiceName}} 10 | 11 | FROM alpine:3.15 AS runtime 12 | ENV {{.Service.GetApiEndpointEnvName}}=:80 13 | ENV {{.Service.GetMaintenanceApiEndpointEnvName}}=:8000 14 | COPY --from=build /go/src/{{.ServiceName}} ./ 15 | COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ 16 | EXPOSE 80/tcp 17 | EXPOSE 8000/tcp 18 | ENTRYPOINT ["./{{.ServiceName}}"] 19 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/cmd/_service_/main.go.tpl: -------------------------------------------------------------------------------- 1 | {{- .TplHeader }} 2 | // vim: set ft=go: 3 | 4 | package main 5 | 6 | import ( 7 | "context" 8 | "{{ .Workspace.MifyGeneratedServicePackage }}/app" 9 | ) 10 | 11 | func main() { 12 | app := app.NewMifyServiceApp(context.Background()) 13 | app.Run() 14 | } 15 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/cmd/_service_/render.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | curPath := path.Join( 16 | ctx.GetWorkspace().GetGoServicesAbsPath(), 17 | "cmd", 18 | ctx.GetServiceName(), 19 | ) 20 | 21 | return render.RenderMany( 22 | templates, 23 | render.NewFile(ctx, path.Join(curPath, "main.go")), 24 | render.NewFile(ctx, path.Join(curPath, "Dockerfile")), 25 | ) 26 | } 27 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/cmd/render.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | service "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/go-services/cmd/_service_" 6 | ) 7 | 8 | func Render(ctx *gencontext.GenContext) error { 9 | return service.Render(ctx) 10 | } 11 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/go.mod.go: -------------------------------------------------------------------------------- 1 | package goservices 2 | 3 | type goModModel struct { 4 | ModuleName string 5 | } 6 | 7 | func newGoModModel(moduleName string) goModModel { 8 | return goModModel{ 9 | ModuleName: moduleName, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/go.sum.go: -------------------------------------------------------------------------------- 1 | package goservices 2 | 3 | type goSumModel struct { 4 | } 5 | 6 | func newGoSumModel() goSumModel { 7 | return goSumModel{} 8 | } 9 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/_service_/app/migrate.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "strings" 5 | ) 6 | 7 | // #65 8 | func migrateContextToServiceExtra(_ string, _ interface{}, currentText string) (string, error) { 9 | // TODO: use https://pkg.go.dev/go/parser 10 | return strings.ReplaceAll( 11 | currentText, 12 | "func NewRouterConfig()", 13 | "func NewRouterConfig(ctx *core.MifyServiceContext)"), nil 14 | } 15 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/_service_/app/request_extra.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 4 | 5 | type requestExtraModel struct { 6 | CoreInclude string // Include path to core package 7 | } 8 | 9 | func newRequestExtraModel(ctx *gencontext.GenContext) requestExtraModel { 10 | return requestExtraModel{ 11 | CoreInclude: ctx.GetWorkspace().GetCoreIncludePath(ctx.MustGetMifySchema().ServiceName), 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/_service_/app/request_extra.go.tpl: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "{{.CoreInclude}}" 5 | ) 6 | 7 | type RequestExtra struct { 8 | // Append your dependencies here 9 | } 10 | 11 | func NewRequestExtra(ctx *core.MifyServiceContext) (*RequestExtra, error) { 12 | // Here you can do your custom service initialization, prepare dependencies 13 | extra := &RequestExtra{ 14 | // Here you can initialize your dependencies 15 | } 16 | return extra, nil 17 | } 18 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/_service_/app/router/render.go: -------------------------------------------------------------------------------- 1 | package router 2 | 3 | import ( 4 | _ "embed" 5 | 6 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 7 | "github.com/mify-io/mify/pkg/util/render" 8 | ) 9 | 10 | //go:embed router.go.tpl 11 | var routerTemplate string 12 | 13 | func Render(ctx *gencontext.GenContext) error { 14 | routerModel := newRouterModel(ctx) 15 | routerPath := ctx.GetWorkspace().GetAppSubAbsPath(ctx.GetServiceName(), "router/router.go") 16 | if err := render.RenderOrSkipTemplate(routerTemplate, routerModel, routerPath); err != nil { 17 | return render.WrapError("request extra", err) 18 | } 19 | 20 | return nil 21 | } 22 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/_service_/app/router/router.go: -------------------------------------------------------------------------------- 1 | package router 2 | 3 | import gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 4 | 5 | type routerModel struct { 6 | CoreInclude string // Include path to core package 7 | } 8 | 9 | func newRouterModel(ctx *gencontext.GenContext) routerModel { 10 | return routerModel{ 11 | CoreInclude: ctx.GetWorkspace().GetCoreIncludePath(ctx.MustGetMifySchema().ServiceName), 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/_service_/app/router/router.go.tpl: -------------------------------------------------------------------------------- 1 | package router 2 | 3 | import ( 4 | "net/http" 5 | 6 | "{{.CoreInclude}}" 7 | ) 8 | 9 | 10 | type routerConfig struct { 11 | Middlewares []func(http.Handler) http.Handler 12 | } 13 | 14 | func NewRouterConfig(ctx *core.MifyServiceContext) *routerConfig { 15 | return &routerConfig { 16 | Middlewares: []func(http.Handler) http.Handler { 17 | // Add your middlewares here 18 | }, 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/_service_/app/service_extra.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 4 | 5 | type serviceExtraModel struct { 6 | CoreInclude string // Include path to core package 7 | } 8 | 9 | func newServiceExtraModel(ctx *gencontext.GenContext) serviceExtraModel { 10 | return serviceExtraModel{ 11 | CoreInclude: ctx.GetWorkspace().GetCoreIncludePath(ctx.MustGetMifySchema().ServiceName), 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/_service_/app/service_extra.go.tpl: -------------------------------------------------------------------------------- 1 | // vim: set ft=go: 2 | 3 | package app 4 | 5 | import ( 6 | "{{.CoreInclude}}" 7 | ) 8 | 9 | type ServiceExtra struct { 10 | // Append your dependencies here 11 | } 12 | 13 | func NewServiceExtra(ctx *core.MifyServiceContext) (*ServiceExtra, error) { 14 | // Here you can do your custom service initialization, prepare dependencies 15 | extra := &ServiceExtra{ 16 | // Here you can initialize your dependencies 17 | } 18 | return extra, nil 19 | } 20 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/_service_/render.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/go-services/internal/_service_/app" 6 | "github.com/mify-io/mify/pkg/util/render" 7 | ) 8 | 9 | func Render(ctx *gencontext.GenContext) error { 10 | if err := app.Render(ctx); err != nil { 11 | return render.WrapError("app", err) 12 | } 13 | 14 | return nil 15 | } 16 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/mify-generated/render.go: -------------------------------------------------------------------------------- 1 | package mifygenerated 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | services "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/go-services/internal/mify-generated/services" 6 | ) 7 | 8 | func Render(ctx *gencontext.GenContext) error { 9 | if err := services.Render(ctx); err != nil { 10 | return err 11 | } 12 | return nil 13 | } 14 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/mify-generated/services/_service_/app/render.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed mify_app.go.tpl 12 | var mifyAppTemplate string 13 | 14 | //go:embed *.tpl 15 | var templates embed.FS 16 | 17 | func Render(ctx *gencontext.GenContext) error { 18 | mifyAppModel := render.NewModel(ctx, newMifyAppModel(ctx)) 19 | curPath := path.Join( 20 | ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetServicePath().Abs(), 21 | "app", 22 | ) 23 | return render.RenderMany(templates, 24 | render.NewFile(ctx, path.Join(curPath, "mify_app.go")).SetModel(mifyAppModel), 25 | ) 26 | } 27 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/mify-generated/services/_service_/apputil/apputil.go: -------------------------------------------------------------------------------- 1 | package apputil 2 | 3 | import ( 4 | "fmt" 5 | 6 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 7 | ) 8 | 9 | type appUtilModel struct { 10 | TplHeader string 11 | ServiceName string 12 | AppImportPath string 13 | CoreImportPath string 14 | } 15 | 16 | func newAppUtilModel(ctx *gencontext.GenContext) appUtilModel { 17 | return appUtilModel{ 18 | TplHeader: ctx.GetWorkspace().TplHeader, 19 | ServiceName: ctx.GetServiceName(), 20 | CoreImportPath: ctx.GetWorkspace().GetCoreIncludePath(ctx.MustGetMifySchema().ServiceName), 21 | AppImportPath: fmt.Sprintf( 22 | "%s/internal/%s/app", 23 | ctx.GetWorkspace().GetGoModule(), 24 | ctx.MustGetMifySchema().ServiceName), 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/mify-generated/services/_service_/apputil/apputil.go.tpl: -------------------------------------------------------------------------------- 1 | {{- .TplHeader}} 2 | // vim: set ft=go: 3 | 4 | package apputil 5 | 6 | import ( 7 | "{{.Model.AppImportPath}}" 8 | "{{.Model.CoreImportPath}}" 9 | ) 10 | 11 | func GetServiceExtra(ctx *core.MifyServiceContext) *app.ServiceExtra { 12 | return ctx.ServiceExtra().(*app.ServiceExtra) 13 | } 14 | 15 | func GetRequestExtra(ctx *core.MifyRequestContext) *app.RequestExtra { 16 | return ctx.RequestExtra().(*app.RequestExtra) 17 | } 18 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/mify-generated/services/_service_/apputil/render.go: -------------------------------------------------------------------------------- 1 | package apputil 2 | 3 | import ( 4 | "embed" 5 | _ "embed" 6 | "path" 7 | 8 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 9 | "github.com/mify-io/mify/pkg/util/render" 10 | ) 11 | 12 | //go:embed apputil.go.tpl 13 | var appUtilTemplate string 14 | 15 | //go:embed *.tpl 16 | var templates embed.FS 17 | 18 | func Render(ctx *gencontext.GenContext) error { 19 | appUtilModel := render.NewModel(ctx, newAppUtilModel(ctx)) 20 | curPath := path.Join( 21 | ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetServicePath().Abs(), 22 | "apputil", 23 | ) 24 | return render.RenderMany(templates, 25 | render.NewFile(ctx, path.Join(curPath, "apputil.go")).SetModel(appUtilModel), 26 | ) 27 | } 28 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/mify-generated/services/_service_/render.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/go-services/internal/mify-generated/services/_service_/app" 6 | "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/go-services/internal/mify-generated/services/_service_/apputil" 7 | ) 8 | 9 | func Render(ctx *gencontext.GenContext) error { 10 | if err := app.Render(ctx); err != nil { 11 | return err 12 | } 13 | 14 | if err := apputil.Render(ctx); err != nil { 15 | return err 16 | } 17 | 18 | return nil 19 | } 20 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/mify-generated/services/render.go: -------------------------------------------------------------------------------- 1 | package services 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | service "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/go-services/internal/mify-generated/services/_service_" 6 | "github.com/mify-io/mify/pkg/util/render" 7 | ) 8 | 9 | func Render(ctx *gencontext.GenContext) error { 10 | if err := service.Render(ctx); err != nil { 11 | return render.WrapError("service", err) 12 | } 13 | 14 | return nil 15 | } 16 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/go-services/internal/render.go: -------------------------------------------------------------------------------- 1 | package internal 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | service "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/go-services/internal/_service_" 6 | mifygenerated "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/go-services/internal/mify-generated" 7 | ) 8 | 9 | func Render(ctx *gencontext.GenContext) error { 10 | if err := service.Render(ctx); err != nil { 11 | return err 12 | } 13 | if err := mifygenerated.Render(ctx); err != nil { 14 | return err 15 | } 16 | return nil 17 | } 18 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/components/render.go: -------------------------------------------------------------------------------- 1 | package components 2 | 3 | import ( 4 | _ "embed" 5 | 6 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 7 | "github.com/mify-io/mify/pkg/util/render" 8 | ) 9 | 10 | //go:embed sample.vue.tpl 11 | var sampleVueTemplate string 12 | 13 | func Render(ctx *gencontext.GenContext) error { 14 | sampleVueModel := newSampleVueModel(ctx) 15 | sampleVuePath := ctx.GetWorkspace().GetJsSampleVueAbsPath(ctx.GetServiceName()) 16 | if err := render.RenderOrSkipTemplate(sampleVueTemplate, sampleVueModel, sampleVuePath); err != nil { 17 | return render.WrapError("sample.vue", err) 18 | } 19 | 20 | return nil 21 | } 22 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/components/sample.vue.go: -------------------------------------------------------------------------------- 1 | package components 2 | 3 | import gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 4 | 5 | type sampleVueModel struct { 6 | } 7 | 8 | func newSampleVueModel(ctx *gencontext.GenContext) sampleVueModel { 9 | return sampleVueModel{} 10 | } 11 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/components/sample.vue.tpl: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/dockerfile.go: -------------------------------------------------------------------------------- 1 | package nuxtjs 2 | 3 | import gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 4 | 5 | type dockerfileModel struct { 6 | ServiceName string 7 | } 8 | 9 | func newDockerfileModel(ctx *gencontext.GenContext) dockerfileModel { 10 | return dockerfileModel{ 11 | ServiceName: ctx.GetServiceName(), 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/dockerfile.tpl: -------------------------------------------------------------------------------- 1 | FROM node:lts-alpine as builder 2 | 3 | WORKDIR /app 4 | 5 | COPY . . 6 | 7 | WORKDIR /app/{{.ServiceName}} 8 | 9 | RUN yarn install \ 10 | --prefer-offline \ 11 | --frozen-lockfile \ 12 | --non-interactive \ 13 | --production=false 14 | 15 | RUN yarn build 16 | 17 | RUN rm -rf node_modules && \ 18 | NODE_ENV=production yarn install \ 19 | --prefer-offline \ 20 | --pure-lockfile \ 21 | --non-interactive \ 22 | --production=true 23 | 24 | RUN npm prune --production 25 | 26 | FROM node:lts-alpine 27 | 28 | WORKDIR /app 29 | 30 | COPY --from=builder /app . 31 | 32 | WORKDIR /app/{{.ServiceName}} 33 | 34 | ENV HOST 0.0.0.0 35 | ENV PORT 80 36 | EXPOSE 80 37 | 38 | CMD [ "yarn", "start" ] 39 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/generated/core/context.js.tpl: -------------------------------------------------------------------------------- 1 | // vim: set ft=javascript: 2 | import Clients from './clients' 3 | 4 | class MifyContext { 5 | constructor() { 6 | this._config = Clients.getConfigEnvMap() 7 | this._clients = new Clients(this._config) 8 | } 9 | 10 | get config() { 11 | return this._config 12 | } 13 | 14 | get clients() { 15 | return this._clients 16 | } 17 | } 18 | 19 | export default MifyContext; 20 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/generated/core/render.go: -------------------------------------------------------------------------------- 1 | package generatedcore 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | dir := path.Join(ctx.GetWorkspace().GetJsServiceAbsPath(ctx.GetServiceName()), "generated", "core") 16 | 17 | return render.RenderMany( 18 | templates, 19 | render.NewFile(ctx, path.Join(dir, "context.js")), 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/nuxt.config.go: -------------------------------------------------------------------------------- 1 | package nuxtjs 2 | 3 | import gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 4 | 5 | type nuxtConfigModel struct { 6 | ServiceName string 7 | } 8 | 9 | func newNuxtConfigModel(ctx *gencontext.GenContext) nuxtConfigModel { 10 | return nuxtConfigModel{ 11 | ServiceName: ctx.GetServiceName(), 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/package.go: -------------------------------------------------------------------------------- 1 | package nuxtjs 2 | 3 | import gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 4 | 5 | type packageJsonModel struct { 6 | ServiceName string 7 | } 8 | 9 | func newPackageJsonModel(ctx *gencontext.GenContext) packageJsonModel { 10 | return packageJsonModel{ 11 | ctx.GetServiceName(), 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/package.json.tpl: -------------------------------------------------------------------------------- 1 | { 2 | "name": "{{.ServiceName}}", 3 | "version": "1.0.0", 4 | "scripts": { 5 | "dev": "NODE_OPTIONS=--openssl-legacy-provider nuxt", 6 | "build": "NODE_OPTIONS=--openssl-legacy-provider nuxt build", 7 | "generate": "NODE_OPTIONS=--openssl-legacy-provider nuxt generate", 8 | "start": "NODE_OPTIONS=--openssl-legacy-provider nuxt start" 9 | }, 10 | "dependencies": { 11 | "nuxt": "^2.15.8", 12 | "superagent": "^7.1.1" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/pages/index.go: -------------------------------------------------------------------------------- 1 | package pages 2 | 3 | import gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 4 | 5 | type indexModel struct { 6 | } 7 | 8 | func newIndexModel(_ *gencontext.GenContext) indexModel { 9 | return indexModel{} 10 | } 11 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/pages/index.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 22 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/pages/render.go: -------------------------------------------------------------------------------- 1 | package pages 2 | 3 | import ( 4 | _ "embed" 5 | 6 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 7 | "github.com/mify-io/mify/pkg/util/render" 8 | ) 9 | 10 | //go:embed index.vue 11 | var indexTemplate string 12 | 13 | func Render(ctx *gencontext.GenContext) error { 14 | indexModel := newIndexModel(ctx) 15 | indexPath := ctx.GetWorkspace().GetJsIndexAbsPath(ctx.GetServiceName()) 16 | if err := render.RenderOrSkipTemplate(indexTemplate, indexModel, indexPath); err != nil { 17 | return render.WrapError("index.vue", err) 18 | } 19 | 20 | return nil 21 | } 22 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/plugins/mifycontext.js.tpl: -------------------------------------------------------------------------------- 1 | // vim: set ft=javascript: 2 | import MifyContext from '../generated/core/context' 3 | 4 | export default function(ctx, inject) { 5 | inject('mifyContext', new MifyContext(ctx.store.state.mifycontext.config)) 6 | } 7 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/plugins/render.go: -------------------------------------------------------------------------------- 1 | package plugins 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | curPath := path.Join(ctx.GetWorkspace().BasePath, ctx.GetWorkspace().GetJsServiceRelPath(ctx.GetServiceName()), "plugins") 16 | return render.RenderMany( 17 | templates, 18 | render.NewFile(ctx, path.Join(curPath, "mifycontext.js")).SetFlags(render.NewFlags().SkipExisting()), 19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/store/index.js.tpl: -------------------------------------------------------------------------------- 1 | // vim: set ft=javascript: 2 | import { newContext } from "./mifycontext" 3 | export const actions = { 4 | async nuxtServerInit({ commit }) { 5 | commit('mifycontext/update', newContext()) 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/store/mifycontext.js.tpl: -------------------------------------------------------------------------------- 1 | // vim: set ft=javascript: 2 | import MifyContext from '../generated/core/context' 3 | 4 | export function newContext() { 5 | return { 6 | "config": MifyContext.config, 7 | } 8 | } 9 | 10 | export const state = function() { 11 | return newContext() 12 | } 13 | 14 | export const getters = { 15 | getContext(state) { 16 | return state.context 17 | } 18 | } 19 | 20 | export const mutations = { 21 | update(state, newContext) { 22 | state = newContext 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/store/render.go: -------------------------------------------------------------------------------- 1 | package store 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | curPath := path.Join(ctx.GetWorkspace().BasePath, ctx.GetWorkspace().GetJsServiceRelPath(ctx.GetServiceName()), "store") 16 | return render.RenderMany( 17 | templates, 18 | render.NewFile(ctx, path.Join(curPath, "index.js")).SetFlags(render.NewFlags().SkipExisting()), 19 | render.NewFile(ctx, path.Join(curPath, "mifycontext.js")).SetFlags(render.NewFlags().SkipExisting()), 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs/yarn.lock.go: -------------------------------------------------------------------------------- 1 | package nuxtjs 2 | 3 | import gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 4 | 5 | type YarnLockModel struct{} 6 | 7 | func newYarnLockModel(ctx *gencontext.GenContext) YarnLockModel { 8 | return YarnLockModel{} 9 | } 10 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/Dockerfile-nginx.tpl: -------------------------------------------------------------------------------- 1 | FROM node:lts-alpine as builder 2 | 3 | WORKDIR /app 4 | 5 | {{- range .Clients}} 6 | ARG {{.EndpointEnvName}} 7 | ENV {{.EndpointEnvName}}=${ 8 | {{- .EndpointEnvName -}} 9 | } 10 | {{- end}} 11 | 12 | COPY package.json tsconfig.json ./ 13 | COPY public/ public/ 14 | COPY src/ src/ 15 | 16 | RUN yarn && yarn build 17 | 18 | FROM nginx:1.25.1-alpine 19 | 20 | COPY <<-"EOT" /etc/nginx/conf.d/default.conf 21 | server_tokens off; 22 | server { 23 | listen 80; 24 | server_name localhost; 25 | location / { 26 | root /usr/share/nginx/html; 27 | index index.html index.htm; 28 | try_files $uri /index.html; 29 | } 30 | } 31 | EOT 32 | 33 | COPY --from=builder /app/build /usr/share/nginx/html 34 | 35 | RUN touch /var/run/nginx.pid && \ 36 | chown -R nginx:nginx /var/run/nginx.pid /usr/share/nginx/html /var/cache/nginx /var/log/nginx /etc/nginx/conf.d 37 | USER nginx 38 | EXPOSE 80 39 | CMD ["nginx", "-g", "daemon off;"] 40 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/Dockerfile.tpl: -------------------------------------------------------------------------------- 1 | FROM node:lts-alpine as builder 2 | 3 | WORKDIR /app 4 | 5 | {{- range .Clients}} 6 | ARG {{.EndpointEnvName}} 7 | ENV {{.EndpointEnvName}}=${ 8 | {{- .EndpointEnvName -}} 9 | } 10 | {{- end}} 11 | 12 | COPY . . 13 | 14 | WORKDIR /app/{{.ServiceName}} 15 | 16 | RUN yarn install \ 17 | --prefer-offline \ 18 | --frozen-lockfile \ 19 | --non-interactive \ 20 | --production=false 21 | 22 | RUN yarn build 23 | 24 | RUN rm -rf node_modules && \ 25 | NODE_ENV=production yarn install \ 26 | --prefer-offline \ 27 | --pure-lockfile \ 28 | --non-interactive \ 29 | --production=true 30 | 31 | RUN npm prune --production 32 | 33 | FROM node:lts-alpine 34 | 35 | WORKDIR /app 36 | 37 | COPY --from=builder /app . 38 | 39 | WORKDIR /app/{{.ServiceName}} 40 | 41 | ENV HOST 0.0.0.0 42 | ENV PORT 80 43 | EXPOSE 80 44 | 45 | CMD [ "yarn", "start" ] 46 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/public/manifest.json.tpl: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "{{.ServiceName}}", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/public/render.go: -------------------------------------------------------------------------------- 1 | package public 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | dir := path.Join(ctx.GetWorkspace().GetJsServiceAbsPath(ctx.GetServiceName()), "public") 16 | return render.RenderMany( 17 | templates, 18 | render.NewFile(ctx, path.Join(dir, "robots.txt")).SetFlags(render.NewFlags().SkipExisting()), 19 | render.NewFile(ctx, path.Join(dir, "index.html")).SetFlags(render.NewFlags().SkipExisting()), 20 | render.NewFile(ctx, path.Join(dir, "manifest.json")).SetFlags(render.NewFlags().SkipExisting()), 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/public/robots.txt.tpl: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/src/App.css.tpl: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/src/App.test.tsx.tpl: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render, screen } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | render(); 7 | const linkElement = screen.getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/src/App.tsx.tpl: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './App.css'; 3 | 4 | function App() { 5 | return ( 6 |
7 |
8 |

9 | Edit src/App.tsx and save to reload. 10 |

11 | 17 | Learn React 18 | 19 |
20 |
21 | ); 22 | } 23 | 24 | export default App; 25 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/src/app/hooks.ts.tpl: -------------------------------------------------------------------------------- 1 | // vim: set ft=typescript: 2 | import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'; 3 | import type { RootState, AppDispatch } from './store'; 4 | 5 | // Use throughout your app instead of plain `useDispatch` and `useSelector` 6 | export const useAppDispatch = () => useDispatch(); 7 | export const useAppSelector: TypedUseSelectorHook = useSelector; 8 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/src/app/render.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | dir := path.Join(ctx.GetWorkspace().GetJsServiceAbsPath(ctx.GetServiceName()), "src", "app") 16 | 17 | return render.RenderMany( 18 | templates, 19 | render.NewFile(ctx, path.Join(dir, "hooks.ts")).SetFlags(render.NewFlags().SkipExisting()), 20 | render.NewFile(ctx, path.Join(dir, "store.ts")).SetFlags(render.NewFlags().SkipExisting()), 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/src/app/store.ts.tpl: -------------------------------------------------------------------------------- 1 | // vim: set ft=typescript: 2 | import { configureStore, ThunkAction, Action } from '@reduxjs/toolkit'; 3 | import mifyContextReducer from '../generated/core/state'; 4 | 5 | export const store = configureStore({ 6 | reducer: { 7 | mifyState: mifyContextReducer, 8 | }, 9 | }); 10 | 11 | export type AppDispatch = typeof store.dispatch; 12 | export type RootState = ReturnType; 13 | export type AppThunk = ThunkAction< 14 | ReturnType, 15 | RootState, 16 | unknown, 17 | Action 18 | >; 19 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/src/generated/core/context.js.tpl: -------------------------------------------------------------------------------- 1 | // vim: set ft=javascript: 2 | import Clients from './clients' 3 | 4 | class MifyContext { 5 | constructor(config) { 6 | this._config = config 7 | if (!this._config) { 8 | this._config = MifyContext.getConfig() 9 | } 10 | this._clients = new Clients(this._config) 11 | } 12 | 13 | get config() { 14 | return this._config 15 | } 16 | 17 | get clients() { 18 | return this._clients 19 | } 20 | 21 | static getConfig() { 22 | return Clients.getConfigEnvMap() 23 | } 24 | } 25 | 26 | export default MifyContext; 27 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/src/generated/core/render.go: -------------------------------------------------------------------------------- 1 | package generatedcore 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | dir := path.Join(ctx.GetWorkspace().GetJsServiceAbsPath(ctx.GetServiceName()), "src", "generated", "core") 16 | 17 | return render.RenderMany( 18 | templates, 19 | render.NewFile(ctx, path.Join(dir, "context.js")), 20 | render.NewFile(ctx, path.Join(dir, "state.ts")), 21 | ) 22 | } 23 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/src/generated/core/state.ts.tpl: -------------------------------------------------------------------------------- 1 | // vim: set ft=typescript: 2 | import { createSlice } from '@reduxjs/toolkit'; 3 | import MifyContext from './context'; 4 | 5 | export interface MifyContextState { 6 | value: MifyContext; 7 | } 8 | 9 | const initialState: MifyContextState = { 10 | value: new MifyContext(), 11 | }; 12 | 13 | export const mifyContextSlice = createSlice({ 14 | name: 'mify_context', 15 | initialState, 16 | reducers: {}, 17 | extraReducers: () => {}, 18 | }); 19 | 20 | export default mifyContextSlice.reducer; 21 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/src/index.css.tpl: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/src/index.tsx.tpl: -------------------------------------------------------------------------------- 1 | import ReactDOM from 'react-dom/client'; 2 | import './index.css'; 3 | import App from './App'; 4 | import reportWebVitals from './reportWebVitals'; 5 | import { Provider } from 'react-redux'; 6 | import { store } from './app/store'; 7 | 8 | const root = ReactDOM.createRoot( 9 | document.getElementById('root') as HTMLElement 10 | ); 11 | root.render( 12 | 13 | 14 | 15 | ); 16 | 17 | // If you want to start measuring performance in your app, pass a function 18 | // to log results (for example: reportWebVitals(console.log)) 19 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 20 | reportWebVitals(); 21 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/src/react-app-env.d.ts.tpl: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/src/reportWebVitals.ts.tpl: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/src/setupTests.ts.tpl: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts/tsconfig.json.tpl: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/_service_/render.go: -------------------------------------------------------------------------------- 1 | package jsservices 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | nuxtjs "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/js-services/_service_/nuxtjs" 6 | reactts "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/js-services/_service_/react-ts" 7 | "github.com/mify-io/mify/pkg/util/render" 8 | ) 9 | 10 | func Render(ctx *gencontext.GenContext) error { 11 | if ctx.GetMifySchema().Template == "nuxtjs" { 12 | if err := nuxtjs.Render(ctx); err != nil { 13 | return render.WrapError("nuxtjs", err) 14 | } 15 | return nil 16 | } 17 | if ctx.GetMifySchema().Template == "react-ts" { 18 | if err := reactts.Render(ctx, false); err != nil { 19 | return render.WrapError("react-ts", err) 20 | } 21 | return nil 22 | } 23 | if ctx.GetMifySchema().Template == "react-ts-nginx" { 24 | if err := reactts.Render(ctx, true); err != nil { 25 | return render.WrapError("react-ts-nginx", err) 26 | } 27 | return nil 28 | } 29 | 30 | return nil 31 | } 32 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/package.go: -------------------------------------------------------------------------------- 1 | package jsservices 2 | 3 | import ( 4 | "sort" 5 | 6 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 7 | "github.com/mify-io/mify/pkg/mifyconfig" 8 | ) 9 | 10 | type packageJsonModel struct { 11 | ServiceList []string 12 | } 13 | 14 | func newPackageJsonModel(ctx *gencontext.GenContext) packageJsonModel { 15 | return packageJsonModel{ 16 | ServiceList: getServiceList(ctx), 17 | } 18 | } 19 | 20 | func getServiceList(ctx *gencontext.GenContext) []string { 21 | schemas := ctx.GetSchemaCtx().GetAllSchemas() 22 | res := make([]string, 0) 23 | for serviceName, schemas := range schemas { 24 | if schemas.GetMify().Language == mifyconfig.ServiceLanguageJs { 25 | res = append(res, serviceName) 26 | } 27 | } 28 | sort.Strings(res) 29 | return res 30 | } 31 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/package.json.tpl: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "workspaces": [ 4 | {{- $first := true}} 5 | {{- range $v := .ServiceList}} 6 | {{- if $first}} 7 | {{- $first = false}} 8 | {{- else}}, 9 | {{- end}} 10 | "{{$v}}" 11 | {{- end}} 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/js-services/render.go: -------------------------------------------------------------------------------- 1 | package jsservices 2 | 3 | import ( 4 | _ "embed" 5 | 6 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 7 | service "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/js-services/_service_" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed package.json.tpl 12 | var packageJsonTemplate string 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | packageJsonModel := newPackageJsonModel(ctx) 16 | packageJsonPath := ctx.GetWorkspace().GetJsPackageJsonAbsPath() 17 | if err := render.RenderTemplate(packageJsonTemplate, packageJsonModel, packageJsonPath); err != nil { 18 | return render.WrapError("package.json", err) 19 | } 20 | 21 | if err := service.Render(ctx); err != nil { 22 | return render.WrapError("service", err) 23 | } 24 | return nil 25 | } 26 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/py-services/_service_/Dockerfile.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | "github.com/mify-io/mify/pkg/generator/lib/endpoints" 6 | ) 7 | 8 | type dockerfileModel struct { 9 | ServiceName string 10 | ApiEndpointEnv string 11 | MaintenanceApiEndpointEnv string 12 | } 13 | 14 | func newDockerfileModel(ctx *gencontext.GenContext) dockerfileModel { 15 | return dockerfileModel{ 16 | ServiceName: ctx.MustGetMifySchema().ServiceName, 17 | ApiEndpointEnv: endpoints.MakeApiEndpointEnvName(ctx.GetServiceName()), 18 | MaintenanceApiEndpointEnv: endpoints.MakeMaintenanceEndpointEnvName(ctx.GetServiceName()), 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/py-services/_service_/Dockerfile.tpl: -------------------------------------------------------------------------------- 1 | FROM python:3.9-alpine 2 | 3 | RUN mkdir /app 4 | WORKDIR /app 5 | COPY . . 6 | 7 | RUN pip install -r requirements.txt 8 | 9 | ENV {{.ApiEndpointEnv}}=:80 10 | ENV {{.MaintenanceApiEndpointEnv}}=:8000 11 | EXPOSE 80/tcp 12 | EXPOSE 8000/tcp 13 | ENTRYPOINT ["python", "-m", "{{.ServiceName}}"] 14 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/py-services/_service_/__init__.py.tpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/pkg/generator/steps/layout/tpl-new/py-services/_service_/__init__.py.tpl -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/py-services/_service_/__main__.py.tpl: -------------------------------------------------------------------------------- 1 | # vim: set ft=python: 2 | from {{.Workspace.MifyGeneratedServicePackage}}.app.mify_app import MifyServiceApp 3 | 4 | 5 | def main(): 6 | app = MifyServiceApp() 7 | app.run() 8 | 9 | if __name__ == '__main__': 10 | main() 11 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/py-services/_service_/app/__init__.py.tpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/pkg/generator/steps/layout/tpl-new/py-services/_service_/app/__init__.py.tpl -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/py-services/_service_/app/request_extra.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 4 | 5 | type requestExtraModel struct { 6 | } 7 | 8 | func newRequestExtraModel(ctx *gencontext.GenContext) requestExtraModel { 9 | return requestExtraModel{} 10 | } 11 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/py-services/_service_/app/request_extra.py.tpl: -------------------------------------------------------------------------------- 1 | # vim: set ft=python: 2 | class RequestExtra: 3 | def __init__(self): 4 | # Append your dependencies here 5 | pass 6 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/py-services/_service_/app/service_extra.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 4 | 5 | type serviceExtraModel struct{} 6 | 7 | func newServiceExtraModel(ctx *gencontext.GenContext) serviceExtraModel { 8 | return serviceExtraModel{} 9 | } 10 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/py-services/_service_/app/service_extra.py.tpl: -------------------------------------------------------------------------------- 1 | # vim: set ft=python: 2 | class ServiceExtra: 3 | def __init__(self, service_context): 4 | # Here you can do your custom service initialization, prepare dependencies 5 | pass 6 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/py-services/_service_/main.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | "github.com/mify-io/mify/pkg/generator/lib/endpoints" 6 | ) 7 | 8 | type mainModel struct { 9 | ServiceName string 10 | ServicePackageName string 11 | } 12 | 13 | func newMainModel(ctx *gencontext.GenContext) mainModel { 14 | serviceName := ctx.MustGetMifySchema().ServiceName 15 | return mainModel{ 16 | ServiceName: serviceName, 17 | ServicePackageName: endpoints.SanitizeServiceName(serviceName), 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/py-services/render.go: -------------------------------------------------------------------------------- 1 | package pyservices 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | service "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/py-services/_service_" 6 | ) 7 | 8 | func Render(ctx *gencontext.GenContext) error { 9 | if err := service.Render(ctx); err != nil { 10 | return err 11 | } 12 | return nil 13 | } 14 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/render.go: -------------------------------------------------------------------------------- 1 | package tplnew 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | goservices "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/go-services" 6 | jsservices "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/js-services" 7 | pyservices "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/py-services" 8 | "github.com/mify-io/mify/pkg/generator/steps/layout/tpl-new/workspace" 9 | ) 10 | 11 | func RenderWorkspace(ctx *gencontext.GenContext) error { 12 | if err := workspace.Render(ctx); err != nil { 13 | return err 14 | } 15 | 16 | return nil 17 | } 18 | 19 | func RenderGo(ctx *gencontext.GenContext) error { 20 | if err := goservices.Render(ctx); err != nil { 21 | return err 22 | } 23 | 24 | return nil 25 | } 26 | 27 | func RenderJs(ctx *gencontext.GenContext) error { 28 | if err := jsservices.Render(ctx); err != nil { 29 | return err 30 | } 31 | 32 | return nil 33 | } 34 | 35 | func RenderPy(ctx *gencontext.GenContext) error { 36 | if err := pyservices.Render(ctx); err != nil { 37 | return err 38 | } 39 | 40 | return nil 41 | } 42 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/workspace/dotmify/gitignore.tpl: -------------------------------------------------------------------------------- 1 | assets 2 | logs 3 | schemas 4 | stats 5 | -------------------------------------------------------------------------------- /pkg/generator/steps/layout/tpl-new/workspace/render.go: -------------------------------------------------------------------------------- 1 | package workspace 2 | 3 | import ( 4 | _ "embed" 5 | "path/filepath" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed dotmify/gitignore.tpl 12 | var gitignoreTemplate string 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | cacheGitignoreAbsPath := filepath.Join(ctx.GetWorkspace().GetCacheDirectory(), ".gitignore") 16 | if err := render.RenderTemplate(gitignoreTemplate, struct{}{}, cacheGitignoreAbsPath); err != nil { 17 | return err 18 | } 19 | return nil 20 | } 21 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/helpers/base_model.go: -------------------------------------------------------------------------------- 1 | package helpers 2 | 3 | type GeneratedBaseModel struct { 4 | TplHeader string 5 | } 6 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/helpers/js/names.go: -------------------------------------------------------------------------------- 1 | package js 2 | 3 | import ( 4 | "strings" 5 | "unicode" 6 | ) 7 | 8 | func SanitizeServiceName(serviceName string) string { 9 | if unicode.IsDigit(rune(serviceName[0])) { 10 | serviceName = "service_" + serviceName 11 | } 12 | serviceName = strings.ReplaceAll(serviceName, "-", "_") 13 | 14 | return serviceName 15 | } 16 | 17 | func MakeServerEnvName(serviceName string) string { 18 | sanitizedName := SanitizeServiceName(serviceName) 19 | return strings.ToUpper(sanitizedName) + "_SERVER_ENDPOINT" 20 | } 21 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/impl.go: -------------------------------------------------------------------------------- 1 | package layout 2 | 3 | import ( 4 | _ "embed" 5 | "fmt" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl" 9 | "github.com/mify-io/mify/pkg/mifyconfig" 10 | ) 11 | 12 | func execute(ctx *gencontext.GenContext) error { 13 | if err := render(ctx); err != nil { 14 | return err 15 | } 16 | 17 | return nil 18 | } 19 | 20 | func render(ctx *gencontext.GenContext) error { 21 | mifySchema := ctx.GetMifySchema() 22 | if mifySchema == nil { 23 | return nil 24 | } 25 | 26 | switch mifySchema.Language { 27 | case mifyconfig.ServiceLanguageGo: 28 | if err := tpl.RenderGo(ctx); err != nil { 29 | return fmt.Errorf("can't render go files: %w", err) 30 | } 31 | case mifyconfig.ServiceLanguageJs: 32 | if err := tpl.RenderJs(ctx); err != nil { 33 | return fmt.Errorf("can't render js files: %w", err) 34 | } 35 | case mifyconfig.ServiceLanguagePython: 36 | if err := tpl.RenderPy(ctx); err != nil { 37 | return fmt.Errorf("can't render python files: %w", err) 38 | } 39 | } 40 | 41 | return nil 42 | } 43 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/step.go: -------------------------------------------------------------------------------- 1 | package layout 2 | 3 | import ( 4 | _ "embed" 5 | 6 | "github.com/mify-io/mify/pkg/generator/core" 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | ) 9 | 10 | type MifyGeneratedStep struct { 11 | } 12 | 13 | func NewMifyGeneratedStep() MifyGeneratedStep { 14 | return MifyGeneratedStep{} 15 | } 16 | 17 | func (s MifyGeneratedStep) Name() string { 18 | return "mify-generated" 19 | } 20 | 21 | func (s MifyGeneratedStep) Execute(ctx *gencontext.GenContext) (core.StepResult, error) { 22 | if err := execute(ctx); err != nil { 23 | return core.Done, err 24 | } 25 | 26 | return core.Done, nil 27 | } 28 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/common/configs/render.go: -------------------------------------------------------------------------------- 1 | package configs 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | curPath := path.Join( 16 | ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetCommonPath().Abs(), 17 | "configs", 18 | ) 19 | return render.RenderMany( 20 | templates, 21 | render.NewFile(ctx, path.Join(curPath, "common.go")), 22 | render.NewFile(ctx, path.Join(curPath, "dynamic_config.go")), 23 | render.NewFile(ctx, path.Join(curPath, "static_config.go")), 24 | ) 25 | } 26 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/common/consul/consul_config.go.tpl: -------------------------------------------------------------------------------- 1 | {{- .TplHeader}} 2 | // vim: set ft=go: 3 | 4 | package consul 5 | 6 | import "{{.Workspace.MifyGeneratedCommonPackage}}/configs" 7 | 8 | type ConsulConfig struct { 9 | Endpoint string `yaml:"endpoint" envconfig:"CONSUL_ENDPOINT" default:"127.0.0.1:8500"` 10 | } 11 | 12 | func GetConsulConfig(cfg *configs.MifyStaticConfig) *ConsulConfig { 13 | return cfg.MustGetPtr((*ConsulConfig)(nil)).(*ConsulConfig) 14 | } 15 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/common/consul/render.go: -------------------------------------------------------------------------------- 1 | package consul 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | curPath := path.Join( 16 | ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetCommonPath().Abs(), 17 | "consul", 18 | ) 19 | return render.RenderMany( 20 | templates, 21 | render.NewFile(ctx, path.Join(curPath, "consul_config.go")), 22 | ) 23 | } 24 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/common/logs/render.go: -------------------------------------------------------------------------------- 1 | package logs 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | curPath := path.Join( 16 | ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetCommonPath().Abs(), 17 | "logs", 18 | ) 19 | return render.RenderMany( 20 | templates, 21 | render.NewFile(ctx, path.Join(curPath, "logger.go")), 22 | ) 23 | } 24 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/common/metrics/metrics.go.tpl: -------------------------------------------------------------------------------- 1 | {{- .TplHeader}} 2 | // vim: set ft=go: 3 | 4 | package metrics 5 | 6 | import ( 7 | "github.com/prometheus/client_golang/prometheus" 8 | ) 9 | 10 | type MifyMetricsWrapper struct { 11 | register prometheus.Registerer 12 | } 13 | 14 | func (mfw *MifyMetricsWrapper) Register(collector prometheus.Collector) error { 15 | return mfw.register.Register(collector) 16 | } 17 | 18 | func NewMifyMetricsWrapper() *MifyMetricsWrapper { 19 | return &MifyMetricsWrapper{ 20 | register: prometheus.DefaultRegisterer, 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/common/metrics/render.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | curPath := path.Join( 16 | ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetCommonPath().Abs(), 17 | "metrics", 18 | ) 19 | return render.RenderMany( 20 | templates, 21 | render.NewFile(ctx, path.Join(curPath, "client_metrics.go")), 22 | render.NewFile(ctx, path.Join(curPath, "metrics.go")), 23 | render.NewFile(ctx, path.Join(curPath, "request_metrics.go")), 24 | ) 25 | } 26 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/common/render.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/common/configs" 6 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/common/consul" 7 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/common/logs" 8 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/common/metrics" 9 | ) 10 | 11 | func Render(ctx *gencontext.GenContext) error { 12 | if err := configs.Render(ctx); err != nil { 13 | return err 14 | } 15 | if err := consul.Render(ctx); err != nil { 16 | return err 17 | } 18 | if err := logs.Render(ctx); err != nil { 19 | return err 20 | } 21 | if err := metrics.Render(ctx); err != nil { 22 | return err 23 | } 24 | return nil 25 | } 26 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/render.go: -------------------------------------------------------------------------------- 1 | package mifygenerated 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/common" 6 | services "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/services" 7 | ) 8 | 9 | func Render(ctx *gencontext.GenContext) error { 10 | if err := services.Render(ctx); err != nil { 11 | return err 12 | } 13 | if err := common.Render(ctx); err != nil { 14 | return err 15 | } 16 | return nil 17 | } 18 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/services/_service_/app/render.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | serverModel := render.NewModel(ctx, newServerModel(ctx)) 16 | curPath := path.Join( 17 | ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetServicePath().Abs(), 18 | "app", 19 | ) 20 | return render.RenderMany(templates, 21 | render.NewFile(ctx, path.Join(curPath, "server.go")).SetModel(serverModel), 22 | ) 23 | } 24 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/services/_service_/app/server.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | ) 6 | 7 | type serverModel struct { 8 | TplHeader string 9 | CoreImportPath string 10 | ConfigsImportPath string 11 | } 12 | 13 | func newServerModel(ctx *gencontext.GenContext) serverModel { 14 | return serverModel{ 15 | TplHeader: ctx.GetWorkspace().TplHeader, 16 | CoreImportPath: ctx.GetWorkspace().GetCoreIncludePath(ctx.MustGetMifySchema().ServiceName), 17 | ConfigsImportPath: ctx.GetWorkspace().GetGoConfigsImportPath(), 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/services/_service_/core/helpers.go: -------------------------------------------------------------------------------- 1 | package core 2 | 3 | import ( 4 | "fmt" 5 | 6 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 7 | ) 8 | 9 | type helpersModel struct { 10 | TplHeader string 11 | ConfigsImportPath string 12 | } 13 | 14 | func newHelpersModel(ctx *gencontext.GenContext) helpersModel { 15 | commonPath := ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetCommonPackage() 16 | return helpersModel{ 17 | TplHeader: ctx.GetWorkspace().TplHeader, 18 | ConfigsImportPath: fmt.Sprintf("%s/configs", commonPath), 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/services/_service_/core/request_context.go: -------------------------------------------------------------------------------- 1 | package core 2 | 3 | import ( 4 | "fmt" 5 | 6 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 7 | ) 8 | 9 | type requestContextModel struct { 10 | TplHeader string 11 | MetricsImportPath string 12 | ConfigsImportPath string 13 | } 14 | 15 | func newRequestContextModel(ctx *gencontext.GenContext) requestContextModel { 16 | // TODO: move paths to description 17 | commonPath := ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetCommonPackage() 18 | return requestContextModel{ 19 | TplHeader: ctx.GetWorkspace().TplHeader, 20 | MetricsImportPath: fmt.Sprintf("%s/metrics", commonPath), 21 | ConfigsImportPath: fmt.Sprintf("%s/configs", commonPath), 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/services/_service_/render.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/services/_service_/app" 6 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/services/_service_/core" 7 | ) 8 | 9 | func Render(ctx *gencontext.GenContext) error { 10 | if err := core.Render(ctx); err != nil { 11 | return err 12 | } 13 | 14 | if err := app.Render(ctx); err != nil { 15 | return err 16 | } 17 | 18 | return nil 19 | } 20 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/services/render.go: -------------------------------------------------------------------------------- 1 | package services 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | service "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated/services/_service_" 6 | "github.com/mify-io/mify/pkg/util/render" 7 | ) 8 | 9 | func Render(ctx *gencontext.GenContext) error { 10 | if err := service.Render(ctx); err != nil { 11 | return render.WrapError("service", err) 12 | } 13 | 14 | return nil 15 | } 16 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/internal/render.go: -------------------------------------------------------------------------------- 1 | package internal 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | mifygenerated "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/go-services/internal/mify-generated" 6 | ) 7 | 8 | func Render(ctx *gencontext.GenContext) error { 9 | if err := mifygenerated.Render(ctx); err != nil { 10 | return err 11 | } 12 | return nil 13 | } 14 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/go-services/render.go: -------------------------------------------------------------------------------- 1 | package goservices 2 | 3 | import ( 4 | _ "embed" 5 | 6 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 7 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/go-services/internal" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | func Render(ctx *gencontext.GenContext) error { 12 | if err := internal.Render(ctx); err != nil { 13 | return render.WrapError("app", err) 14 | } 15 | return nil 16 | } 17 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/common/__init__.py.tpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/common/__init__.py.tpl -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/common/configs/render.go: -------------------------------------------------------------------------------- 1 | package configs 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | basePath := path.Join( 16 | ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetCommonPath().Abs(), 17 | "configs", 18 | ) 19 | return render.RenderMany( 20 | templates, 21 | render.NewFile(ctx, path.Join(basePath, "static.py")), 22 | render.NewFile(ctx, path.Join(basePath, "dynamic.py")), 23 | ) 24 | } 25 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/common/logs/render.go: -------------------------------------------------------------------------------- 1 | package logs 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | basePath := path.Join( 16 | ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetCommonPath().Abs(), 17 | "logs", 18 | ) 19 | return render.RenderMany( 20 | templates, 21 | render.NewFile(ctx, path.Join(basePath, "logger.py")), 22 | ) 23 | } 24 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/common/metrics/metrics.py.tpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/common/metrics/metrics.py.tpl -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/common/metrics/render.go: -------------------------------------------------------------------------------- 1 | package metrics 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | basePath := path.Join( 16 | ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetCommonPath().Abs(), 17 | "metrics", 18 | ) 19 | return render.RenderMany( 20 | templates, 21 | render.NewFile(ctx, path.Join(basePath, "server.py")), 22 | render.NewFile(ctx, path.Join(basePath, "request_metrics.py")), 23 | render.NewFile(ctx, path.Join(basePath, "client_metrics.py")), 24 | ) 25 | } 26 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/common/render.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/common/configs" 9 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/common/logs" 10 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/common/metrics" 11 | "github.com/mify-io/mify/pkg/util/render" 12 | ) 13 | 14 | //go:embed *.tpl 15 | var templates embed.FS 16 | 17 | func Render(ctx *gencontext.GenContext) error { 18 | basePath := path.Join( 19 | ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetCommonPath().Abs(), 20 | ) 21 | if err := render.RenderMany( 22 | templates, 23 | render.NewFile(ctx, path.Join(basePath, "__init__.py")), 24 | ); err != nil { 25 | return render.WrapError("__init__.py", err) 26 | } 27 | 28 | if err := configs.Render(ctx); err != nil { 29 | return err 30 | } 31 | if err := logs.Render(ctx); err != nil { 32 | return err 33 | } 34 | if err := metrics.Render(ctx); err != nil { 35 | return err 36 | } 37 | return nil 38 | } 39 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/render.go: -------------------------------------------------------------------------------- 1 | package mifygenerated 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/common" 6 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services" 7 | "github.com/mify-io/mify/pkg/util/render" 8 | ) 9 | 10 | func Render(ctx *gencontext.GenContext) error { 11 | if err := common.Render(ctx); err != nil { 12 | return render.WrapError("common", err) 13 | } 14 | if err := services.Render(ctx); err != nil { 15 | return render.WrapError("services", err) 16 | } 17 | 18 | return nil 19 | } 20 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services/_service_/app/__init__.py.tpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services/_service_/app/__init__.py.tpl -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services/_service_/app/mify_app.py.tpl: -------------------------------------------------------------------------------- 1 | {{.TplHeader}} 2 | # vim: set ft=python: 3 | 4 | from {{.Workspace.MifyGeneratedServicePackage}}.core.service_context import MifyServiceContext 5 | from {{.ServiceName}}.app.service_extra import ServiceExtra 6 | 7 | from .server import Server 8 | 9 | class MifyServiceApp: 10 | def __init__(self): 11 | self._service_context = MifyServiceContext('{{.ServiceName}}').with_extra(ServiceExtra) 12 | self._server = Server(self._service_context) 13 | 14 | def run(self): 15 | self._server.run() 16 | self._service_context.close() 17 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services/_service_/app/render.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | basePath := path.Join( 16 | ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetServicePath().Abs(), 17 | "app", 18 | ) 19 | 20 | return render.RenderMany( 21 | templates, 22 | render.NewFile(ctx, path.Join(basePath, "__init__.py")), 23 | render.NewFile(ctx, path.Join(basePath, "mify_app.py")), 24 | render.NewFile(ctx, path.Join(basePath, "server.py")), 25 | ) 26 | } 27 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services/_service_/core/__init__.py.tpl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mify-io/mify/a57d89478602566c7e24f7ff9ed8658296ea9510/pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services/_service_/core/__init__.py.tpl -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services/_service_/core/clients.py.tpl: -------------------------------------------------------------------------------- 1 | {{.TplHeader}} 2 | # vim: set ft=python: 3 | from {{.Workspace.MifyGeneratedCommonPackage}}.metrics.client_metrics import ClientMetrics 4 | 5 | {{- range .Model.Clients}} 6 | from {{.ImportPath}} import ApiClient as {{.ApiClientName}}, Configuration as {{.ConfigurationName}} 7 | {{- end}} 8 | 9 | class MifyServiceClients: 10 | def __init__(self, service_context): 11 | metrics = ClientMetrics() 12 | {{- range .Model.Clients}} 13 | self._{{.PropertyName}} = {{.ApiClientName}}(metrics, {{.ConfigurationName}}(service_context.static_config)) 14 | {{- end}} 15 | pass 16 | 17 | def close(self): 18 | {{- range .Model.Clients}} 19 | self._{{.PropertyName}}.close() 20 | {{- end}} 21 | pass 22 | 23 | {{- range .Model.Clients}} 24 | @property 25 | def {{.PropertyName}}(self): 26 | return self._{{.PropertyName}} 27 | {{- end}} 28 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services/_service_/core/render.go: -------------------------------------------------------------------------------- 1 | package core 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | clientsModel := newClientsModel(ctx) 16 | basePath := path.Join( 17 | ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetServicePath().Abs(), 18 | "core", 19 | ) 20 | 21 | return render.RenderMany( 22 | templates, 23 | render.NewFile(ctx, path.Join(basePath, "__init__.py")), 24 | render.NewFile(ctx, path.Join(basePath, "request_context.py")), 25 | render.NewFile(ctx, path.Join(basePath, "service_context.py")), 26 | render.NewFile(ctx, path.Join(basePath, "clients.py")). 27 | SetModel(render.NewModel(ctx, clientsModel)), 28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services/_service_/openapi/render.go: -------------------------------------------------------------------------------- 1 | package openapi 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | basePath := path.Join( 16 | ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetServicePath().Abs(), 17 | "openapi", 18 | ) 19 | return render.RenderMany( 20 | templates, 21 | render.NewFile(ctx, path.Join(basePath, "app.py")), 22 | ) 23 | } 24 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services/_service_/render.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services/_service_/app" 6 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services/_service_/core" 7 | "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services/_service_/openapi" 8 | ) 9 | 10 | func Render(ctx *gencontext.GenContext) error { 11 | if err := core.Render(ctx); err != nil { 12 | return err 13 | } 14 | 15 | if err := app.Render(ctx); err != nil { 16 | return err 17 | } 18 | 19 | if err := openapi.Render(ctx); err != nil { 20 | return err 21 | } 22 | 23 | return nil 24 | } 25 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services/render.go: -------------------------------------------------------------------------------- 1 | package services 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | service "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/py-services/mify_generated/services/_service_" 6 | "github.com/mify-io/mify/pkg/util/render" 7 | ) 8 | 9 | func Render(ctx *gencontext.GenContext) error { 10 | if err := service.Render(ctx); err != nil { 11 | return render.WrapError("service", err) 12 | } 13 | 14 | return nil 15 | } 16 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/py-services/render.go: -------------------------------------------------------------------------------- 1 | package pyservices 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | mifygenerated "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/py-services/mify_generated" 6 | "github.com/mify-io/mify/pkg/util/render" 7 | ) 8 | 9 | func Render(ctx *gencontext.GenContext) error { 10 | if err := mifygenerated.Render(ctx); err != nil { 11 | return render.WrapError("mifygenerated", err) 12 | } 13 | 14 | return nil 15 | } 16 | -------------------------------------------------------------------------------- /pkg/generator/steps/mify-generated/tpl/render.go: -------------------------------------------------------------------------------- 1 | package tpl 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | goservices "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/go-services" 6 | // jsservices "github.com/mify-io/mify/pkg/generator/steps/layout/tpl/js-services" 7 | pyservices "github.com/mify-io/mify/pkg/generator/steps/mify-generated/tpl/py-services" 8 | ) 9 | 10 | func RenderGo(ctx *gencontext.GenContext) error { 11 | if err := goservices.Render(ctx); err != nil { 12 | return err 13 | } 14 | 15 | return nil 16 | } 17 | 18 | func RenderJs(ctx *gencontext.GenContext) error { 19 | // if err := jsservices.Render(ctx); err != nil { 20 | // return err 21 | // } 22 | 23 | return nil 24 | } 25 | 26 | func RenderPy(ctx *gencontext.GenContext) error { 27 | if err := pyservices.Render(ctx); err != nil { 28 | return err 29 | } 30 | 31 | return nil 32 | } 33 | -------------------------------------------------------------------------------- /pkg/generator/steps/migrate/step.go: -------------------------------------------------------------------------------- 1 | package migrate 2 | 3 | import ( 4 | _ "embed" 5 | 6 | "github.com/mify-io/mify/pkg/generator/core" 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | ) 9 | 10 | type MigrateStep struct { 11 | } 12 | 13 | func NewMigrateStep() MigrateStep { 14 | return MigrateStep{} 15 | } 16 | 17 | func (s MigrateStep) Name() string { 18 | return "migrate" 19 | } 20 | 21 | func (s MigrateStep) Execute(ctx *gencontext.GenContext) (core.StepResult, error) { 22 | if !ctx.GetMigrate() { 23 | ctx.Logger.Info("called without --migrate, skipping") 24 | return core.Done, nil 25 | } 26 | if ctx.GetMifySchema() == nil { 27 | return core.Done, nil 28 | } 29 | if err := execute(ctx); err != nil { 30 | return core.Done, err 31 | } 32 | 33 | return core.Done, nil 34 | } 35 | -------------------------------------------------------------------------------- /pkg/generator/steps/openapi/clients_cache.go: -------------------------------------------------------------------------------- 1 | package openapi 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path/filepath" 7 | 8 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 9 | "gopkg.in/yaml.v2" 10 | ) 11 | 12 | const ( 13 | CLIENTS_FILENAME = ".clients.yaml" 14 | ) 15 | 16 | func updateClientsList(ctx *gencontext.GenContext) error { 17 | tmpDir := ctx.GetWorkspace().GetServiceCacheDirectory(ctx.GetServiceName()) 18 | 19 | ctx.Logger.Infof("updating clients list in: %s", tmpDir) 20 | 21 | err := os.MkdirAll(tmpDir, 0755) 22 | if err != nil { 23 | return fmt.Errorf("failed to write clients list file: %w", err) 24 | } 25 | 26 | f, err := os.OpenFile(filepath.Join(tmpDir, CLIENTS_FILENAME), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) 27 | if err != nil { 28 | return fmt.Errorf("failed to write clients list file: %w", err) 29 | } 30 | 31 | list := make([]string, 0, len(ctx.MustGetMifySchema().OpenAPI.Clients)) 32 | for client := range ctx.MustGetMifySchema().OpenAPI.Clients { 33 | list = append(list, client) 34 | } 35 | 36 | err = yaml.NewEncoder(f).Encode(list) 37 | if err != nil { 38 | return fmt.Errorf("failed to write clients list file: %w", err) 39 | } 40 | 41 | return nil 42 | } 43 | -------------------------------------------------------------------------------- /pkg/generator/steps/openapi/context/context.go: -------------------------------------------------------------------------------- 1 | package context 2 | 3 | type OpenapiContext struct { 4 | } 5 | -------------------------------------------------------------------------------- /pkg/generator/steps/openapi/processors/processor.go: -------------------------------------------------------------------------------- 1 | package processors 2 | 3 | import ( 4 | "fmt" 5 | 6 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 7 | "github.com/mify-io/mify/pkg/mifyconfig" 8 | ) 9 | 10 | const ( 11 | SERVER_PACKAGE_NAME = "openapi" 12 | ) 13 | 14 | type GeneratorConfig struct { 15 | TargetPath string 16 | PackageName string 17 | } 18 | 19 | type PostProcessor interface { 20 | GetServerGeneratorConfig(ctx *gencontext.GenContext) (GeneratorConfig, error) 21 | GetClientGeneratorConfig(ctx *gencontext.GenContext, clientName string) (GeneratorConfig, error) 22 | ProcessServer(ctx *gencontext.GenContext) error 23 | ProcessClient(ctx *gencontext.GenContext, clientName string) error 24 | PopulateServerHandlers(ctx *gencontext.GenContext, paths []string) error 25 | Format(ctx *gencontext.GenContext) error 26 | } 27 | 28 | func NewPostProcessor(lang mifyconfig.ServiceLanguage) (PostProcessor, error) { 29 | switch lang { 30 | case mifyconfig.ServiceLanguagePython: 31 | return newPythonProcessor(), nil 32 | case mifyconfig.ServiceLanguageGo: 33 | return newGoProcessor(), nil 34 | case mifyconfig.ServiceLanguageJs: 35 | return newJsProcessor(), nil 36 | default: 37 | return nil, fmt.Errorf("unsupported language: %s", lang) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /pkg/generator/steps/openapi/processors/string_utils_test.go: -------------------------------------------------------------------------------- 1 | package processors 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/stretchr/testify/assert" 7 | ) 8 | 9 | func TestToApiFilename(t *testing.T) { 10 | assert.Equal(t, "api_path_to_api", toAPIFilename("/path/to/api")) 11 | assert.Equal(t, "api_path_to_api", toAPIFilename("/path/to/api/")) 12 | assert.Equal(t, "api_path_to_api_minus", toAPIFilename("/path/to/api-minus/")) 13 | assert.Equal(t, "api_path_to_api_param_test_other", toAPIFilename("/path/to/api/{param}.{test}/{other}")) 14 | 15 | // reserved filename 16 | assert.Equal(t, "api_api_v1_test_", toAPIFilename("/api/v1/test")) 17 | } 18 | -------------------------------------------------------------------------------- /pkg/generator/steps/openapi/step.go: -------------------------------------------------------------------------------- 1 | package openapi 2 | 3 | import ( 4 | "github.com/mify-io/mify/pkg/generator/core" 5 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 6 | ) 7 | 8 | type OpenapiStep struct { 9 | } 10 | 11 | func NewOpenapiStep() OpenapiStep { 12 | return OpenapiStep{} 13 | } 14 | 15 | func (s OpenapiStep) Name() string { 16 | return "openapi" 17 | } 18 | 19 | func (s OpenapiStep) Execute(ctx *gencontext.GenContext) (core.StepResult, error) { 20 | if ctx.GetMifySchema() == nil { 21 | return core.Done, nil // Some services (like dev-runner) could not have any scheme 22 | } 23 | 24 | if err := generateServiceOpenAPI(ctx); err != nil { 25 | return core.Done, err 26 | } 27 | 28 | return core.Done, nil 29 | } 30 | -------------------------------------------------------------------------------- /pkg/generator/steps/openapi/tpl/go_clients.go: -------------------------------------------------------------------------------- 1 | package tpl 2 | 3 | type GoClientModel struct { 4 | ClientName string 5 | PackageName string 6 | PrivateFieldName string 7 | PublicMethodName string 8 | IncludePath string 9 | } 10 | 11 | func NewGoClientModel( 12 | clientName string, 13 | packageName string, 14 | privateFieldName string, 15 | publicMethodName string, 16 | includePath string) GoClientModel { 17 | 18 | return GoClientModel{ 19 | ClientName: clientName, 20 | PackageName: packageName, 21 | PrivateFieldName: privateFieldName, 22 | PublicMethodName: publicMethodName, 23 | IncludePath: includePath, 24 | } 25 | } 26 | 27 | type GoClientsModel struct { 28 | Header string 29 | GoModule string 30 | ServiceName string 31 | 32 | MetricsIncludePath string 33 | Clients []GoClientModel 34 | } 35 | 36 | func NewGoClientsModel( 37 | header string, 38 | goModule string, 39 | serviceName string, 40 | metricsIncludePath string, 41 | clients []GoClientModel) GoClientsModel { 42 | 43 | return GoClientsModel{ 44 | Header: header, 45 | GoModule: goModule, 46 | ServiceName: serviceName, 47 | 48 | MetricsIncludePath: metricsIncludePath, 49 | Clients: clients, 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /pkg/generator/steps/openapi/tpl/go_clients.go.tpl: -------------------------------------------------------------------------------- 1 | {{- .Header}} 2 | 3 | package core 4 | 5 | import ( 6 | {{- range .Clients}} 7 | "{{.IncludePath}}" 8 | {{- end}} 9 | 10 | {{if .MetricsIncludePath }}"{{.MetricsIncludePath}}"{{end}} 11 | ) 12 | 13 | type MifyServiceClients struct { 14 | {{- range .Clients}} 15 | {{.PrivateFieldName}} *{{.PackageName}}.APIClient 16 | {{- end}} 17 | } 18 | 19 | func NewMifyServiceClients(ctx *MifyServiceContext) (*MifyServiceClients, error) { 20 | {{- range .Clients}} 21 | {{.PrivateFieldName}} := {{.PackageName}}.NewAPIClient(metrics.NewClientMetrics(), {{.PackageName}}.NewConfiguration(ctx.StaticConfig())) 22 | {{- end}} 23 | 24 | clients := &MifyServiceClients { 25 | {{- range .Clients}} 26 | {{.PrivateFieldName}}: {{.PrivateFieldName}}, 27 | {{- end}} 28 | } 29 | 30 | return clients, nil 31 | } 32 | 33 | {{- range .Clients}} 34 | func (c *MifyServiceClients) {{.PublicMethodName}}() *{{.PackageName}}.APIClient { 35 | return c.{{.PrivateFieldName}} 36 | } 37 | {{- end}} 38 | -------------------------------------------------------------------------------- /pkg/generator/steps/openapi/tpl/js_clients.go: -------------------------------------------------------------------------------- 1 | package tpl 2 | 3 | type JsClientModel struct { 4 | ClientName string 5 | PublicMethodName string 6 | ClassName string 7 | } 8 | 9 | func NewJsClientModel( 10 | clientName string, 11 | className string, 12 | publicMethodName string) JsClientModel { 13 | 14 | return JsClientModel{ 15 | ClientName: clientName, 16 | PublicMethodName: publicMethodName, 17 | ClassName: className, 18 | } 19 | } 20 | 21 | type JsClientsModel struct { 22 | Header string 23 | ServiceName string 24 | Clients []JsClientModel 25 | } 26 | 27 | func NewJsClientsModel( 28 | header string, 29 | serviceName string, 30 | clients []JsClientModel) JsClientsModel { 31 | 32 | return JsClientsModel{ 33 | Header: header, 34 | ServiceName: serviceName, 35 | Clients: clients, 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /pkg/generator/steps/openapi/tpl/js_clients.js.tpl: -------------------------------------------------------------------------------- 1 | {{- .Header}} 2 | 3 | {{- range .Clients}} 4 | import {{.ClassName}} from '../api/clients/{{.ClientName}}' 5 | {{- end}} 6 | 7 | class Clients { 8 | constructor(config) { 9 | {{- range .Clients}} 10 | this._{{.PublicMethodName}} = new {{.ClassName}}.Api( 11 | new {{.ClassName}}.ApiClient(config), 12 | ); 13 | {{- end}} 14 | } 15 | 16 | {{- range .Clients}} 17 | {{.PublicMethodName}}() { 18 | return this._{{.PublicMethodName}}; 19 | } 20 | {{- end}} 21 | 22 | static getConfigEnvMap() { 23 | {{- range .Clients}} 24 | var {{.PublicMethodName}}Env = {{.ClassName}}.ApiClient.getConfigEnvName() 25 | {{- end}} 26 | return { 27 | {{- range .Clients}} 28 | [{{.PublicMethodName}}Env]: process.env[{{.PublicMethodName}}Env], 29 | {{- end}} 30 | } 31 | 32 | } 33 | } 34 | 35 | export default Clients 36 | -------------------------------------------------------------------------------- /pkg/generator/steps/postgres/impl.go: -------------------------------------------------------------------------------- 1 | package postgres 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | "github.com/mify-io/mify/pkg/generator/steps/postgres/tpl" 6 | "github.com/mify-io/mify/pkg/mifyconfig" 7 | ) 8 | 9 | func execute(ctx *gencontext.GenContext) error { 10 | if ctx.GetMifySchema() == nil { 11 | return nil 12 | } 13 | 14 | if !ctx.GetMifySchema().Postgres.Enabled { 15 | return nil 16 | } 17 | 18 | if ctx.GetMifySchema().Language == mifyconfig.ServiceLanguageGo { 19 | ctx.Logger.Infof("Will generated postgres for service") 20 | if err := tpl.RenderGo(ctx); err != nil { 21 | return err 22 | } 23 | } 24 | 25 | return nil 26 | } 27 | -------------------------------------------------------------------------------- /pkg/generator/steps/postgres/step.go: -------------------------------------------------------------------------------- 1 | package postgres 2 | 3 | import ( 4 | _ "embed" 5 | 6 | "github.com/mify-io/mify/pkg/generator/core" 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | ) 9 | 10 | type PostgresStep struct { 11 | } 12 | 13 | func NewPostgresStep() PostgresStep { 14 | return PostgresStep{} 15 | } 16 | 17 | func (s PostgresStep) Name() string { 18 | return "postgres" 19 | } 20 | 21 | func (s PostgresStep) Execute(ctx *gencontext.GenContext) (core.StepResult, error) { 22 | if err := execute(ctx); err != nil { 23 | return core.Done, err 24 | } 25 | 26 | return core.Done, nil 27 | } 28 | -------------------------------------------------------------------------------- /pkg/generator/steps/postgres/tpl/go/config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | ) 6 | 7 | type PostgresConfigModel struct { 8 | ConfigsImportPath string 9 | DatabaseName string 10 | } 11 | 12 | func NewPostgresConfigModel(ctx *gencontext.GenContext) PostgresConfigModel { 13 | return PostgresConfigModel{ 14 | ctx.GetWorkspace().GetGoConfigsImportPath(), 15 | ctx.GetMifySchema().Postgres.DatabaseName, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /pkg/generator/steps/postgres/tpl/go/config/config.go.tpl: -------------------------------------------------------------------------------- 1 | // THIS FILE IS AUTOGENERATED, DO NOT EDIT 2 | // Generated by mify 3 | 4 | package postgres 5 | 6 | import "{{.Workspace.MifyGeneratedCommonPackage }}/configs" 7 | 8 | type PostgresConfig struct { 9 | DatabaseUrl string `yaml:"database_url" envconfig:"DATABASE_URL" default:"postgres://user:passwd@localhost:5432/{{.Model.DatabaseName}}"` 10 | } 11 | 12 | func GetPostgresConfig(cfg *configs.MifyStaticConfig) *PostgresConfig { 13 | return cfg.MustGetPtr((*PostgresConfig)(nil)).(*PostgresConfig) 14 | } 15 | -------------------------------------------------------------------------------- /pkg/generator/steps/postgres/tpl/go/config/render.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "embed" 5 | "path" 6 | 7 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 8 | "github.com/mify-io/mify/pkg/util/render" 9 | ) 10 | 11 | //go:embed *.tpl 12 | var templates embed.FS 13 | 14 | func Render(ctx *gencontext.GenContext) error { 15 | postgresConfigModel := NewPostgresConfigModel(ctx) 16 | basePath := path.Join( 17 | ctx.GetWorkspace().GetMifyGenerated(ctx.MustGetMifySchema()).GetServicePath().Abs(), 18 | "postgres", 19 | ) 20 | 21 | return render.RenderMany( 22 | templates, 23 | render.NewFile(ctx, path.Join(basePath, "config.go")).SetModel(render.NewModel(ctx, postgresConfigModel)), 24 | ) 25 | } 26 | -------------------------------------------------------------------------------- /pkg/generator/steps/postgres/tpl/go/queries.sql.example.tpl: -------------------------------------------------------------------------------- 1 | -- Check out sqlc docs to get started: 2 | -- https://docs.sqlc.dev/en/latest/tutorials/getting-started-postgresql.html 3 | -- Here are simple CRUD examples: 4 | 5 | -- name: GetAuthor :one 6 | -- SELECT * FROM authors 7 | -- WHERE id = $1 LIMIT 1; 8 | 9 | -- name: ListAuthors :many 10 | -- SELECT * FROM authors 11 | -- ORDER BY name; 12 | 13 | -- name: CreateAuthor :one 14 | -- INSERT INTO authors ( 15 | -- name, bio 16 | -- ) VALUES ( 17 | -- $1, $2 18 | -- ) 19 | -- RETURNING *; 20 | 21 | -- name: DeleteAuthor :exec 22 | -- DELETE FROM authors 23 | -- WHERE id = $1; 24 | 25 | -- Schema: 26 | -- CREATE TABLE authors ( 27 | -- id BIGSERIAL PRIMARY KEY, 28 | -- name text NOT NULL, 29 | -- bio text 30 | -- ); 31 | -------------------------------------------------------------------------------- /pkg/generator/steps/postgres/tpl/go/sqlc.go: -------------------------------------------------------------------------------- 1 | package gotpl 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | ) 6 | 7 | type sqlcModel struct { 8 | MigrationsDir string 9 | QueriesDir string 10 | OutDir string 11 | } 12 | 13 | func NewSqlcModel(ctx *gencontext.GenContext) (sqlcModel, error) { 14 | dbName := ctx.MustGetMifySchema().Postgres.DatabaseName 15 | // NOTE: sqlc doesn't support absolute paths, these are relative to sqlc.yaml 16 | // location, so go-services/internal//generated/postgres 17 | return sqlcModel{ 18 | MigrationsDir: "../../../../../migrations/"+dbName, 19 | QueriesDir: "../../../../../sql-queries/"+dbName, 20 | OutDir: ".", 21 | }, nil 22 | } 23 | -------------------------------------------------------------------------------- /pkg/generator/steps/postgres/tpl/go/sqlc.yaml.tpl: -------------------------------------------------------------------------------- 1 | # vim: set ft=yaml: 2 | version: "2" 3 | sql: 4 | - schema: "{{ .Model.MigrationsDir }}" 5 | queries: "{{ .Model.QueriesDir }}" 6 | engine: "postgresql" 7 | gen: 8 | go: 9 | package: "postgres" 10 | out: "{{ .Model.OutDir }}" 11 | sql_package: "pgx/v4" 12 | -------------------------------------------------------------------------------- /pkg/generator/steps/postgres/tpl/render.go: -------------------------------------------------------------------------------- 1 | package tpl 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | gotpl "github.com/mify-io/mify/pkg/generator/steps/postgres/tpl/go" 6 | ) 7 | 8 | func RenderGo(ctx *gencontext.GenContext) error { 9 | if err := gotpl.Render(ctx); err != nil { 10 | return err 11 | } 12 | 13 | return nil 14 | } 15 | -------------------------------------------------------------------------------- /pkg/generator/steps/prepare/impl.go: -------------------------------------------------------------------------------- 1 | package prepare 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | ) 6 | 7 | func execute(ctx *gencontext.GenContext) error { 8 | if err := preparePython(ctx); err != nil { 9 | return err 10 | } 11 | return nil 12 | } 13 | -------------------------------------------------------------------------------- /pkg/generator/steps/prepare/requirements.txt.tpl: -------------------------------------------------------------------------------- 1 | connexion[aiohttp,swagger-ui] >= 2.6.0; python_version>="3.6" 2 | # 2.3 is the last version that supports python 3.5 3 | connexion[aiohttp,swagger-ui] <= 2.3.0; python_version=="3.5" or python_version=="3.4" 4 | # connexion requires werkzeug but connexion < 2.4.0 does not install werkzeug 5 | # we must peg werkzeug versions below to fix connexion 6 | # https://github.com/zalando/connexion/pull/1044 7 | werkzeug == 0.16.1; python_version=="3.5" or python_version=="3.4" 8 | swagger-ui-bundle == 0.0.6 9 | aiohttp_jinja2 == 1.5.0 10 | aiohttp_cors >= 0.7.0 11 | structlog >= 22.1.0 12 | prometheus-client >= 0.14.1 13 | certifi >= 14.05.14 14 | frozendict >= 2.0.3 15 | python_dateutil >= 2.5.3 16 | setuptools >= 21.0.0 17 | urllib3 >= 1.15.1 18 | typing-extensions >= 4.4.0 19 | python-consul2 >= 0.1.5 20 | -------------------------------------------------------------------------------- /pkg/generator/steps/prepare/step.go: -------------------------------------------------------------------------------- 1 | package prepare 2 | 3 | import ( 4 | "github.com/mify-io/mify/pkg/generator/core" 5 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 6 | ) 7 | 8 | type PrepareStep struct { 9 | } 10 | 11 | func NewPrepareStep() PrepareStep { 12 | return PrepareStep{} 13 | } 14 | 15 | func (s PrepareStep) Name() string { 16 | return "prepare" 17 | } 18 | 19 | func (s PrepareStep) Execute(ctx *gencontext.GenContext) (core.StepResult, error) { 20 | if err := execute(ctx); err != nil { 21 | return core.Done, err 22 | } 23 | 24 | return core.Done, nil 25 | } 26 | -------------------------------------------------------------------------------- /pkg/generator/steps/schema/context/openapi.go: -------------------------------------------------------------------------------- 1 | package context 2 | 3 | import "github.com/getkin/kin-openapi/openapi3" 4 | 5 | type OpenapiServiceSchemas map[string]*openapi3.T // schema name -> openapi schema 6 | 7 | func (s OpenapiServiceSchemas) GetMainSchema() *openapi3.T { 8 | res, ok := s[MainSchemaName] 9 | if !ok { 10 | return nil 11 | } 12 | 13 | return res 14 | } 15 | 16 | func (s OpenapiServiceSchemas) GetGeneratedSchema() *openapi3.T { 17 | res, ok := s[GeneratedSchemaName] 18 | if !ok { 19 | return nil 20 | } 21 | 22 | return res 23 | } 24 | -------------------------------------------------------------------------------- /pkg/generator/steps/schema/context/schemas.go: -------------------------------------------------------------------------------- 1 | package context 2 | 3 | import ( 4 | "github.com/mify-io/mify/pkg/mifyconfig" 5 | ) 6 | 7 | const ( 8 | MainSchemaName = "api.yaml" 9 | GeneratedSchemaName = "api_generated.yaml" 10 | ) 11 | 12 | type AllSchemas map[string]*ServiceSchemas // service name -> schemas 13 | 14 | type ServiceSchemas struct { 15 | openApi OpenapiServiceSchemas 16 | mify *mifyconfig.ServiceConfig 17 | } 18 | 19 | func NewServiceSchemas(openApi OpenapiServiceSchemas, mify *mifyconfig.ServiceConfig) *ServiceSchemas { 20 | if mify == nil { 21 | panic("mify schema is required") 22 | } 23 | 24 | return &ServiceSchemas{ 25 | openApi: openApi, 26 | mify: mify, 27 | } 28 | } 29 | 30 | // Can be nill for some services 31 | func (s ServiceSchemas) GetOpenapi() OpenapiServiceSchemas { 32 | return s.openApi 33 | } 34 | 35 | func (s ServiceSchemas) GetMify() *mifyconfig.ServiceConfig { 36 | return s.mify 37 | } 38 | -------------------------------------------------------------------------------- /pkg/generator/steps/schema/step.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | import ( 4 | "github.com/mify-io/mify/pkg/generator/core" 5 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 6 | ) 7 | 8 | type SchemaStep struct { 9 | } 10 | 11 | func NewSchemaStep() SchemaStep { 12 | return SchemaStep{} 13 | } 14 | 15 | func (s SchemaStep) Name() string { 16 | return "schema-collector" 17 | } 18 | 19 | func (s SchemaStep) Execute(ctx *gencontext.GenContext) (core.StepResult, error) { 20 | schemaCtx, err := execute(ctx) 21 | if err != nil { 22 | return core.Done, err 23 | } 24 | ctx.SetSchemaCtx(schemaCtx) 25 | 26 | if err = validateCtx(ctx); err != nil { 27 | return core.Done, err 28 | } 29 | 30 | return core.Done, nil 31 | } 32 | -------------------------------------------------------------------------------- /pkg/util/render/service_model.go: -------------------------------------------------------------------------------- 1 | package render 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | "github.com/mify-io/mify/pkg/generator/lib/endpoints" 6 | ) 7 | 8 | type ServiceModel struct { 9 | Name string 10 | ApiEndpointEnv string 11 | ApiEndpoint string 12 | MaintenanceEndpointEnv string 13 | MaintenanceEndpoint string 14 | } 15 | 16 | func NewServiceModel(ctx *gencontext.GenContext) *ServiceModel { 17 | resolved, err := ctx.EndpointsResolver.ResolveEndpoints(ctx.GetServiceName()) 18 | if err != nil { 19 | ctx.Logger.Panic("failed to resolve service endpoints during template generation") 20 | } 21 | return &ServiceModel{ 22 | Name: ctx.GetServiceName(), 23 | ApiEndpointEnv: endpoints.MakeApiEndpointEnvName(ctx.GetServiceName()), 24 | ApiEndpoint: resolved.Api, 25 | MaintenanceEndpointEnv: endpoints.MakeMaintenanceEndpointEnvName(ctx.GetServiceName()), 26 | MaintenanceEndpoint: resolved.Maintenance, 27 | } 28 | } 29 | 30 | func (c ServiceModel) GetApiEndpointEnvName() string { 31 | return endpoints.MakeApiEndpointEnvName(c.Name) 32 | } 33 | 34 | func (c ServiceModel) GetMaintenanceApiEndpointEnvName() string { 35 | return endpoints.MakeMaintenanceEndpointEnvName(c.Name) 36 | } 37 | -------------------------------------------------------------------------------- /pkg/util/render/workspace_model.go: -------------------------------------------------------------------------------- 1 | package render 2 | 3 | import ( 4 | gencontext "github.com/mify-io/mify/pkg/generator/gen-context" 5 | ) 6 | 7 | type GoServiceModel struct { 8 | Name string 9 | } 10 | 11 | type WorkspaceModel struct { 12 | Name string 13 | MifyGeneratedCommonPackage string 14 | MifyGeneratedServicePackage string 15 | } 16 | 17 | func NewWorkspaceModel(context *gencontext.GenContext) *WorkspaceModel { 18 | mifyGen := context.GetWorkspace().GetMifyGenerated(context.MustGetMifySchema()) 19 | return &WorkspaceModel{ 20 | Name: context.GetWorkspace().Name, 21 | MifyGeneratedCommonPackage: mifyGen.GetCommonPackage(), 22 | MifyGeneratedServicePackage: mifyGen.GetServicePackage(), 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /pkg/util/threading/lock.go: -------------------------------------------------------------------------------- 1 | package threading 2 | 3 | import "sync" 4 | 5 | func DoUnderLock(mtx *sync.Mutex, work func() error) error { 6 | mtx.Lock() 7 | defer mtx.Unlock() 8 | return work() 9 | } 10 | -------------------------------------------------------------------------------- /pkg/workspace/helpers.go: -------------------------------------------------------------------------------- 1 | package workspace 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path" 7 | ) 8 | 9 | func (description Description) GetServiceList() ([]string, error) { 10 | schemasDir := path.Join(description.BasePath, description.GetSchemasRootRelPath()) 11 | files, err := os.ReadDir(schemasDir) 12 | if err != nil { 13 | return nil, fmt.Errorf("can't collect service list: %w", err) 14 | } 15 | 16 | res := make([]string, 0, len(files)) 17 | for _, f := range files { 18 | res = append(res, f.Name()) 19 | } 20 | 21 | return res, nil 22 | } 23 | -------------------------------------------------------------------------------- /pkg/workspace/mutators/cloud/init.go: -------------------------------------------------------------------------------- 1 | package cloud 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/mify-io/mify/pkg/workspace/mutators" 7 | ) 8 | 9 | func Init(mutContext *mutators.MutatorContext) error { 10 | if err := UpdateCloudPublicity(mutContext); err != nil { 11 | return fmt.Errorf("failed to update cloud publicity: %w", err) 12 | } 13 | 14 | return nil 15 | } 16 | -------------------------------------------------------------------------------- /pkg/workspace/mutators/database/database.go: -------------------------------------------------------------------------------- 1 | package database 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/mify-io/mify/pkg/mifyconfig" 7 | "github.com/mify-io/mify/pkg/workspace/mutators" 8 | ) 9 | 10 | func AddPostgres(mutContext *mutators.MutatorContext, service string) error { 11 | fmt.Printf("Adding postgres to %s\n", service) 12 | 13 | serviceConf, err := mifyconfig.ReadServiceConfig(mutContext.GetDescription().BasePath, service) 14 | if err != nil { 15 | return err 16 | } 17 | 18 | serviceConf.Postgres.Enabled = true 19 | return mifyconfig.SaveServiceConfig(mutContext.GetDescription().BasePath, service, serviceConf) 20 | } 21 | 22 | func RemovePostgres(mutContext *mutators.MutatorContext, service string) error { 23 | fmt.Printf("Removing postgres to %s\n", service) 24 | 25 | serviceConf, err := mifyconfig.ReadServiceConfig(mutContext.GetDescription().BasePath, service) 26 | if err != nil { 27 | return err 28 | } 29 | 30 | serviceConf.Postgres = mifyconfig.PostgresConfig{} 31 | return mifyconfig.SaveServiceConfig(mutContext.GetDescription().BasePath, service, serviceConf) 32 | } 33 | -------------------------------------------------------------------------------- /pkg/workspace/mutators/service/tpl/api.yaml.go: -------------------------------------------------------------------------------- 1 | package tpl 2 | 3 | type ApiSchemaModel struct { 4 | ServiceName string 5 | } 6 | 7 | func NewApiSchemaModel(serviceName string) ApiSchemaModel { 8 | return ApiSchemaModel{ 9 | ServiceName: serviceName, 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /pkg/workspace/mutators/service/tpl/api.yaml.tpl: -------------------------------------------------------------------------------- 1 | openapi: "3.0.0" 2 | info: 3 | version: 1.0.0 4 | title: {{.ServiceName}} 5 | description: Service description 6 | contact: 7 | name: Maintainer name 8 | email: maintainer@example.com # Replace with your email 9 | # Add your local and cloud service url here for testing with Swagger UI. 10 | # You can also add prefix for all paths like this: 11 | # - url: /api 12 | servers: 13 | - url: / 14 | paths: {} 15 | # Example of a handler, uncomment and remove the above 'paths: {}' line. 16 | # Check Petstore OpenAPI example for more possible options: 17 | # https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.0/petstore-expanded.yaml 18 | # 19 | # paths: 20 | # /path/to/api: 21 | # get: 22 | # summary: sample handler 23 | # responses: 24 | # '200': 25 | # description: OK 26 | # content: 27 | # application/json: 28 | # schema: 29 | # $ref: '#/components/schemas/PathToApiResponse' 30 | # components: 31 | # schemas: 32 | # PathToApiResponse: 33 | # type: object 34 | # properties: 35 | # value: 36 | # type: string 37 | # required: 38 | # - value 39 | -------------------------------------------------------------------------------- /pkg/workspace/mutators/workspace/tpl/gitignore.tpl: -------------------------------------------------------------------------------- 1 | assets 2 | logs 3 | schemas 4 | stats 5 | -------------------------------------------------------------------------------- /pkg/workspace/tpl-helpers/go.go: -------------------------------------------------------------------------------- 1 | package tplhelpers 2 | 3 | import ( 4 | "fmt" 5 | "path" 6 | 7 | "github.com/mify-io/mify/pkg/mifyconfig" 8 | ) 9 | 10 | type goHelpers struct {} 11 | 12 | func (h goHelpers) MakeDefaultMifyGeneratedPath() string { 13 | return path.Join(mifyconfig.GoServicesRoot, "internal", mifyconfig.MifyGeneratedDirName) 14 | } 15 | 16 | func getRepository(conf mifyconfig.WorkspaceConfig) string { 17 | return fmt.Sprintf("%s/%s/%s", 18 | conf.GitHost, 19 | conf.GitNamespace, 20 | conf.GitRepository) 21 | } 22 | 23 | func (h goHelpers) MakeDefaultMifyGeneratedPackage(conf mifyconfig.WorkspaceConfig, generatedPath string) string { 24 | return fmt.Sprintf("%s/%s", getRepository(conf), generatedPath) 25 | } 26 | 27 | func (h goHelpers) GetCommonPackage(pkgRoot string) string { 28 | return fmt.Sprintf("%s/common", pkgRoot) 29 | } 30 | 31 | func (h goHelpers) GetServicePackage(pkgRoot string, serviceName string) string { 32 | return fmt.Sprintf("%s/services/%s", pkgRoot, serviceName) 33 | } 34 | -------------------------------------------------------------------------------- /pkg/workspace/tpl-helpers/js.go: -------------------------------------------------------------------------------- 1 | package tplhelpers 2 | 3 | import ( 4 | "fmt" 5 | "path" 6 | 7 | "github.com/mify-io/mify/pkg/mifyconfig" 8 | ) 9 | 10 | type jsHelpers struct { } 11 | 12 | func (h jsHelpers) MakeDefaultMifyGeneratedPath() string { 13 | return path.Join(mifyconfig.JsServicesRoot, mifyconfig.MifyGeneratedDirName) 14 | } 15 | 16 | func (h jsHelpers) MakeDefaultMifyGeneratedPackage(conf mifyconfig.WorkspaceConfig, generatedPath string) string { 17 | return mifyconfig.MifyGeneratedDirName 18 | } 19 | 20 | func (h jsHelpers) GetCommonPackage(pkgRoot string) string { 21 | return fmt.Sprintf("%s.common", pkgRoot) 22 | } 23 | 24 | func (h jsHelpers) GetServicePackage(pkgRoot string, serviceName string) string { 25 | return fmt.Sprintf("%s.services.%s", pkgRoot, serviceName) 26 | } 27 | -------------------------------------------------------------------------------- /pkg/workspace/tpl-helpers/python.go: -------------------------------------------------------------------------------- 1 | package tplhelpers 2 | 3 | import ( 4 | "fmt" 5 | "path" 6 | "strings" 7 | 8 | "github.com/mify-io/mify/pkg/mifyconfig" 9 | ) 10 | 11 | type pythonHelpers struct {} 12 | 13 | func (h pythonHelpers) MakeDefaultMifyGeneratedPath() string { 14 | dirName := strings.ReplaceAll(mifyconfig.MifyGeneratedDirName, "-", "_") 15 | return path.Join(mifyconfig.PythonServicesRoot, dirName) 16 | } 17 | 18 | func (h pythonHelpers) MakeDefaultMifyGeneratedPackage(conf mifyconfig.WorkspaceConfig, generatedPath string) string { 19 | pkgName := strings.ReplaceAll(mifyconfig.MifyGeneratedDirName, "/", ".") 20 | pkgName = strings.ReplaceAll(pkgName, "-", "_") 21 | return pkgName 22 | } 23 | 24 | func (h pythonHelpers) GetCommonPackage(pkgRoot string) string { 25 | return fmt.Sprintf("%s.common", pkgRoot) 26 | } 27 | 28 | func (h pythonHelpers) GetServicePackage(pkgRoot string, serviceName string) string { 29 | return fmt.Sprintf("%s.services.%s", pkgRoot, serviceName) 30 | } 31 | -------------------------------------------------------------------------------- /scripts/debug.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" 4 | REPO_ROOT="$(dirname "$SCRIPT_DIR")" 5 | PATH=$(go env GOPATH)/bin:$PATH 6 | 7 | rm -f "$REPO_ROOT/mify" 8 | (cd "$REPO_ROOT" || exit 1 && go build ./cmd/mify) 9 | dlv exec "$REPO_ROOT"/mify "$@" 10 | -------------------------------------------------------------------------------- /scripts/init.sh: -------------------------------------------------------------------------------- 1 | NAME=mify_tmp 2 | TARGET_PATH=$HOME/.cache/"$NAME" 3 | rm -rf "$TARGET_PATH" 4 | 5 | go run ./cmd/mify/ init "$NAME" -p $HOME/.cache || exit 2 6 | go run ./cmd/mify/ add service service1 service2 -p "$TARGET_PATH" || exit 2 7 | go run ./cmd/mify/ add client service1 --to service2 -p "$TARGET_PATH" || exit 2 8 | go run ./cmd/mify/ remove client service1 --to service2 -p "$TARGET_PATH" || exit 2 9 | go run ./cmd/mify/ add client service1 --to service2 -p "$TARGET_PATH" || exit 2 10 | go run ./cmd/mify/ add frontend --template nuxtjs front -p "$TARGET_PATH" || exit 2 11 | go run ./cmd/mify/ add client front --to service1 -p "$TARGET_PATH" || exit 2 12 | go run ./cmd/mify/ add api-gateway -p "$TARGET_PATH" || exit 2 13 | 14 | cd "$TARGET_PATH/go-services" || exit 2 15 | go mod tidy || exit 2 16 | go build ./cmd/service1 ./cmd/service2 || exit 2 17 | 18 | cd "$TARGET_PATH/js-services/front" || exit 2 19 | yarn install && yarn build || exit 2 20 | 21 | git add * && git commit -m "init" || exit 2 22 | -------------------------------------------------------------------------------- /scripts/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | TARGET_PATH=$HOME/.cache/mify_tmp 3 | 4 | SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" 5 | REPO_ROOT="$(dirname "$SCRIPT_DIR")" 6 | 7 | rm -f "$REPO_ROOT/mify" 8 | (cd "$REPO_ROOT" || exit 1 && go build -race ./cmd/mify) 9 | "$REPO_ROOT"/mify "$@" 10 | --------------------------------------------------------------------------------