From 1b99d484da73f8641ea6cbc82d4b37d449833676 Mon Sep 17 00:00:00 2001 From: Jonathan Vuillemin Date: Sat, 30 Mar 2024 21:55:56 +0100 Subject: [PATCH] doc(main): Updated documentation --- README.md | 65 ++++++++++++++---------------- internal/bootstrap.go | 12 +++--- internal/register.go | 10 +++++ internal/{routing.go => router.go} | 4 +- internal/services.go | 10 ----- 5 files changed, 49 insertions(+), 52 deletions(-) create mode 100644 internal/register.go rename internal/{routing.go => router.go} (70%) delete mode 100644 internal/services.go diff --git a/README.md b/README.md index 89bea82..90d2705 100644 --- a/README.md +++ b/README.md @@ -6,29 +6,53 @@ > HTTP application template based on the [Yokai](https://github.com/ankorstore/yokai) Go framework. -* [Overview](#overview) * [Documentation](#documentation) +* [Overview](#overview) + * [Layout](#layout) + * [Makefile](#makefile) * [Getting started](#getting-started) * [Installation](#installation) * [With GitHub](#with-github) * [With gonew](#with-gonew) * [Usage](#usage) -* [Contents](#contents) - * [Layout](#layout) - * [Makefile](#makefile) +## Documentation + +For more information about the [Yokai](https://github.com/ankorstore/yokai) framework, you can check its [documentation](https://ankorstore.github.io/yokai). + ## Overview This template provides: -- a ready to extend [Yokai](https://github.com/ankorstore/yokai) application, with the [fxhttpserver](https://github.com/ankorstore/yokai/tree/main/fxhttpserver) module installed +- a ready to extend [Yokai](https://github.com/ankorstore/yokai) application, with the [HTTP server](https://ankorstore.github.io/yokai/modules/fxhttpserver/) module installed - a ready to use [dev environment](docker-compose.yaml), based on [Air](https://github.com/cosmtrek/air) (for live reloading) - some examples of [handler](internal/handler/example.go) and [test](internal/handler/example_test.go) to get started -## Documentation +### Layout + +This template is following the [recommended project layout](https://go.dev/doc/modules/layout): + +- `cmd/`: entry points +- `configs/`: configuration files +- `internal/`: + - `handler/`: handler and test examples + - `bootstrap.go`: bootstrap + - `register.go`: dependencies registration + - `router.go`: routing registration -See [Yokai documentation](https://ankorstore.github.io/yokai). +### Makefile + +This template provides a [Makefile](Makefile): + +``` +make up # start the docker compose stack +make down # stop the docker compose stack +make logs # stream the docker compose stack logs +make fresh # refresh the docker compose stack +make test # run tests +make lint # run linter +``` ## Getting started @@ -61,30 +85,3 @@ make fresh Once ready, the application will be available on: - [http://localhost:8080](http://localhost:8080) for the application HTTP server - [http://localhost:8081](http://localhost:8081) for the application core dashboard - -## Contents - -### Layout - -This template is following the [standard Go project layout](https://github.com/golang-standards/project-layout): - -- `cmd/`: entry points -- `configs/`: configuration files -- `internal/`: - - `handler/`: handler and test examples - - `bootstrap.go`: bootstrap (modules, lifecycles, etc) - - `routing.go`: routing - - `services.go`: dependency injection - -### Makefile - -This template provides a [Makefile](Makefile): - -``` -make up # start the docker compose stack -make down # stop the docker compose stack -make logs # stream the docker compose stack logs -make fresh # refresh the docker compose stack -make test # run tests -make lint # run linter -``` diff --git a/internal/bootstrap.go b/internal/bootstrap.go index 0d4f2c8..ba9596d 100644 --- a/internal/bootstrap.go +++ b/internal/bootstrap.go @@ -17,14 +17,14 @@ func init() { // RootDir is the application root directory. var RootDir string -// Bootstrapper can be used to load modules, options, services and bootstraps your application. +// Bootstrapper can be used to load modules, options, dependencies, routing and bootstraps your application. var Bootstrapper = fxcore.NewBootstrapper().WithOptions( - // modules + // modules registration fxhttpserver.FxHttpServerModule, - // routing - ProvideRouting(), - // services - ProvideServices(), + // dependencies registration + Register(), + // routing registration + Router(), ) // Run starts the application, with a provided [context.Context]. diff --git a/internal/register.go b/internal/register.go new file mode 100644 index 0000000..a52b29e --- /dev/null +++ b/internal/register.go @@ -0,0 +1,10 @@ +package internal + +import ( + "go.uber.org/fx" +) + +// Register is used to register the application dependencies. +func Register() fx.Option { + return fx.Options() +} diff --git a/internal/routing.go b/internal/router.go similarity index 70% rename from internal/routing.go rename to internal/router.go index 4ad442b..09c96b4 100644 --- a/internal/routing.go +++ b/internal/router.go @@ -6,8 +6,8 @@ import ( "go.uber.org/fx" ) -// ProvideRouting is used to register the application HTTP handlers. -func ProvideRouting() fx.Option { +// Router is used to register the application HTTP middlewares and handlers. +func Router() fx.Option { return fx.Options( fxhttpserver.AsHandler("GET", "", handler.NewExampleHandler), ) diff --git a/internal/services.go b/internal/services.go deleted file mode 100644 index 8163302..0000000 --- a/internal/services.go +++ /dev/null @@ -1,10 +0,0 @@ -package internal - -import ( - "go.uber.org/fx" -) - -// ProvideServices is used to register the application services. -func ProvideServices() fx.Option { - return fx.Options() -}