Skip to content

ftkit new

Add a new component to an existing Fountain service.

Usage

bash
ftkit new

The command is also available under the alias n. It takes no arguments — running it starts an interactive prompt that walks you through choosing one or more components to generate (powered by promptui).

What it does

new first reads the current module's environment data (it runs go list -m in the project root), then presents a multi-select menu titled "Choose the component(s) to add to the service". Based on your selection it generates the corresponding files and wires them into the existing service — updating server/server.go, biz/biz.go, and biz/dal/dao/managers.go as needed (a backup of each edited file is taken first).

Run new from the root of a service that was created with ftkit init.

Components it can generate

The interactive menu offers these component types (see cmd/new.go / cmd/new_func.go):

ComponentWhat it generates
controllerA new controller domain under biz/core/<name>/, registered via a blank import in biz/biz.go.
handlerA handler package under server/<name>/, with the handler field and constructor wired into the server struct's Initialize().
daoA DAO/cache under biz/dal/dao/<storage>_dao/, registered in managers.go and installed in server.go. Optionally generates the matching model.
pkgA reusable package skeleton under pkg/<name>/.
clientA client library package (<service>_client/) for calling the service.
serverA protocol server added to the server struct, wired into Initialize(), Serving() and Destroy().

Server protocols

When you choose server, you pick one of the supported protocols:

  • grpc
  • http
  • tcp
  • udp

DAO storage backends

When you choose dao, you pick a storage backend. The supported backends (from createNewComponentDAO) are:

StorageGenerated artifact
redisA *Cache in redis_dao/, installed via InstallRedisDAOManager.
mysqlA *DAO in mysql_dao/, installed via InstallSQLDAOManager.
postgres / postgresqlA *DAO in postgres_dao/, installed via InstallSQLDAOManager.
mongo / mongodbA *DAO in mongo_dao/, installed via InstallMongoDAOManager.
cql / scylla / cassandraA *STO in cassandra_dao/, installed via InstallCQLDAOManager.
elasticA *STO in elastic_dao/, installed via InstallElasticDAOManager.

For a DAO you are also asked whether to generate the DAO from a model — if you choose yes, a model file is created (or an existing one is reused) under biz/dal/models/ and its db:"..." tags are used to populate the generated SQL DAO.

TIP

new is fully interactive — there are no command-line flags. All choices (component type, storage, names) are entered through the prompts.

Known limitations

note.txt in the ftkit repository tracks several planned-but-not-yet-implemented refinements for new — for example a new mvc flow that would generate models → handler → controller → dao in one pass, an option to create all missing DAOs for /models, and import-path fixes for multi-word handler names. These are not available yet and are intentionally not documented here as working features.