diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 40b98c2..d7117bc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -78,7 +78,7 @@ webapi:deploy:dev: - dev-web-api dependencies: - 'webapi:build:dev' - # - 'db:migrate:dev' + - 'db:migrate:dev' variables: TARGET_ENV: 'dev' SERVICE: 'web-api' @@ -92,7 +92,6 @@ webapi:deploy:dev: - #ddlogscollector:deploy:stage: # <<: *deploy_stage_tmpl # variables: diff --git a/README.md b/README.md index 1ecfda2..6247b39 100644 --- a/README.md +++ b/README.md @@ -6,22 +6,39 @@ twins@geeksaccelerator.com ## Description -The SaaS Starter Kit is a set of libraries for building scalable software-as-a-service (SaaS) applications while preventing both misuse and fraud. The goal of this project is project is to provide a proven starting point for new projects that reduces the repetitive tasks in getting a new project launched to production that can easily be scaled and ready to onboard enterprise clients. It uses minimal dependencies, implements idiomatic code and follows Golang best practices. Collectively, the toolkit lays out everything logically to minimize guess work and enable engineers to quickly load a mental model for the project. This inturn will make current developers happy and expedite on-boarding of new engineers. +The SaaS Starter Kit is a set of libraries for building scalable software-as-a-service (SaaS) applications while +preventing both misuse and fraud. The goal of this project is project is to provide a proven starting point for new +projects that reduces the repetitive tasks in getting a new project launched to production that can easily be scaled +and ready to onboard enterprise clients. It uses minimal dependencies, implements idiomatic code and follows Golang +best practices. Collectively, the toolkit lays out everything logically to minimize guess work and enable engineers to +quickly load a mental model for the project. This inturn will make current developers happy and expedite on-boarding of +new engineers. -This project should not be considered a web framework. It is a starter toolkit that provides a set of working examples to handle some of the common challenges for developing SaaS using Golang. Coding is a discovery process and with that, it leaves you in control of your project’s architecture and development. +This project should not be considered a web framework. It is a starter toolkit that provides a set of working examples +to handle some of the common challenges for developing SaaS using Golang. Coding is a discovery process and with that, +it leaves you in control of your project’s architecture and development. -There are five areas of expertise that an engineer or her engineering team must do for a project to grow and scale. Based on our experience, a few core decisions were made for each of these areas that help you focus initially on writing the business logic. -1. Micro level - Since SaaS requires transactions, project implements Postgres. Implementation facilitates the data semantics that define the data being captured and their relationships. +There are five areas of expertise that an engineer or her engineering team must do for a project to grow and scale. +Based on our experience, a few core decisions were made for each of these areas that help you focus initially on writing +the business logic. +1. Micro level - Since SaaS requires transactions, project implements Postgres. Implementation facilitates the data +semantics that define the data being captured and their relationships. 2. Macro level - The project architecture and design, provides basic project structure and foundation for development. -3. Business logic - Defines an example Golang package that helps illustrate where value generating activities should reside and how the code will be delivered to clients. +3. Business logic - Defines an example Golang package that helps illustrate where value generating activities should +reside and how the code will be delivered to clients. 4. Deployment and Operations - Integrates with GitLab for CI/CD and AWS for serverless deployments with AWS Fargate. -5. Observability - Implements Datadog to facilitate exposing metrics, logs and request tracing that ensure stable and responsive service for clients. +5. Observability - Implements Datadog to facilitate exposing metrics, logs and request tracing that ensure stable and +responsive service for clients. -SaaS product offerings typically provide two main components: an API and a web application. Both facilitate delivering a valuable software based product to clients ideally from a single code base on a recurring basis delivered over the internet. +SaaS product offerings typically provide two main components: an API and a web application. Both facilitate delivering a +valuable software based product to clients ideally from a single code base on a recurring basis delivered over the +internet. The example project is a complete starter kit for building SasS with GoLang. It provides three example services: -* Web App - Responsive web application to provide service to clients. Includes user signup and user authentication for direct client interaction. -* Web API - REST API with JWT authentication that renders results as JSON. This allows clients to develop deep integrations with the project. +* Web App - Responsive web application to provide service to clients. Includes user signup and user authentication for +direct client interaction. +* Web API - REST API with JWT authentication that renders results as JSON. This allows clients to develop deep +integrations with the project. * Schema - Tool for initializing of Postgres database and handles schema migration. It contains the following features: @@ -45,7 +62,11 @@ It contains the following features: ### Example project -With SaaS, a client subscribes to an online service you provide them. The example project provides functionality for clients to subscribe and then once subscribed they can interact with your software service. For this example, *projects* will be the single business logic package that will be exposed to users for management based on their role. Additional business logic packages can be added to support your project. It’s important at the beginning to minimize the connection between business logic packages on the same horizontal level. +With SaaS, a client subscribes to an online service you provide them. The example project provides functionality for +clients to subscribe and then once subscribed they can interact with your software service. For this example, *projects* +will be the single business logic package that will be exposed to users for management based on their role. Additional +business logic packages can be added to support your project. It’s important at the beginning to minimize the connection +between business logic packages on the same horizontal level. This project provides the following functionality to users: New clients can sign up which creates an account and a user with role of admin. @@ -63,13 +84,15 @@ The project groups code in three distinct directories: * Internal - all business logic (compiler protections) * Platform - all foundation stuff (kit) -All business logic should be contained as a package inside the internal directory. This enables both the web app and web API to use the same API (Golang packages) with the only main difference between them is their response, HTML or JSON. +All business logic should be contained as a package inside the internal directory. This enables both the web app and web +API to use the same API (Golang packages) with the only main difference between them is their response, HTML or JSON. ## Local Installation -Docker is required to run this project on your local machine. This project uses multiple third-party services that will be hosted locally via Docker. +Docker is required to run this project on your local machine. This project uses multiple third-party services that will +be hosted locally via Docker. * Postgres - Transactional database to handle persistence of all data. * Redis - Key / value storage for sessions and other data. Used only as ephemeral storage. * Datadog - Provides metrics, logging, and tracing. @@ -84,7 +107,8 @@ An AWS account is required for deployment for the following AWS dependencies: ### Getting the project -Clone the repo into your desired location. This project uses Go modules and does not need to be in your GOPATH. You will need to be using Go >= 1.11. +Clone the repo into your desired location. This project uses Go modules and does not need to be in your GOPATH. You will +need to be using Go >= 1.11. You should now be able to clone the project. @@ -93,7 +117,8 @@ git clone git@gitlab.com:geeks-accelerator/oss/saas-starter-kit.git cd saas-starter-kit/ ``` -If you have Go Modules enabled, you should be able compile the project locally. If you have Go Modulels disabled, see the next section. +If you have Go Modules enabled, you should be able compile the project locally. If you have Go Modulels disabled, see +the next section. ### Go Modules @@ -113,7 +138,6 @@ echo "export GO111MODULE=on" >> ~/.bash_profile ``` - ### Installing Docker Docker is a critical component and required to run this project. @@ -123,9 +147,11 @@ https://docs.docker.com/install/ ## Running The Project -There is a `docker-compose` file that knows how to build and run all the services. Each service has its own a `dockerfile`. +There is a `docker-compose` file that knows how to build and run all the services. Each service has its own a +`dockerfile`. -When you run `docker-compose up` it will run all the services including the main.go file for each Go service. The services the project will run are: +When you run `docker-compose up` it will run all the services including the main.go file for each Go service. The +services the project will run are: - web-api - web-app - postgres @@ -134,7 +160,8 @@ When you run `docker-compose up` it will run all the services including the main ### Running the project -Use the `docker-compose.yaml` to run all of the services, including the 3rd party services. The first time to run this command, Docker will download the required images for the 3rd party services. +Use the `docker-compose.yaml` to run all of the services, including the 3rd party services. The first time to run this +command, Docker will download the required images for the 3rd party services. ``` $ docker-compose up @@ -161,7 +188,9 @@ Running `docker-compose down` will properly stop and terminate the Docker Compos ### Re-starting a specific Go service for development -When writing code in an iterative fashion, it is nice to be able to restart a specific service so it will run updated Go code. This decreases the overhead of stopping all services with `docker-compose down` and then re-starting all the services again with 'docker-compose up'. +When writing code in an iterative fashion, it is nice to be able to restart a specific service so it will run updated +Go code. This decreases the overhead of stopping all services with `docker-compose down` and then re-starting all the +services again with 'docker-compose up'. To restart a specific service, first use `docker ps` to see the list of services running. @@ -169,17 +198,20 @@ To restart a specific service, first use `docker ps` to see the list of services docker ps CONTAINER ID IMAGE COMMAND NAMES 35043164fd0d example-project/web-api:latest "/gosrv" saas-starter-kit_web-api_1 +d34c8fc27f3b example-project/web-app:latest "/gosrv" saas-starter-kit_web-app_1 fd844456243e postgres:11-alpine "docker-entrypoint.s…" saas-starter-kit_postgres_1 dda16bfbb8b5 redis:latest "redis-server --appe…" saas-starter-kit_redis_1 ``` -Then use `docker-compose down` for a specific service. In the command include the name of the container for the service to shut down. In the example command, we will shut down down the web-api service so we can start it again. +Then use `docker-compose down` for a specific service. In the command include the name of the container for the service +to shut down. In the example command, we will shut down down the web-api service so we can start it again. ```bash docker-compose down saas-starter-kit_web-api_1 ``` -If you are not in the director for the service you want to restart navigate to it. We will go to the directory for the web-api. +If you are not in the directory for the service you want to restart navigate to it. We will go to the directory for the +web-api. ```bash cd cmd/web-api/ @@ -195,11 +227,15 @@ go run main.go By default the project will compile and run without AWS configs or other third-party dependencies. -As you use start utilizing AWS services in this project and/or ready for deployment, you will need to start specifying AWS configs in a docker-compose file. You can also set credentials for other dependencies in the new docker-compose file too. +As you use start utilizing AWS services in this project and/or ready for deployment, you will need to start specifying +AWS configs in a docker-compose file. You can also set credentials for other dependencies in the new docker-compose file +too. -The sample docker-compose file is not loaded since it is named sample, which allows the project to run without these configs. +The sample docker-compose file is not loaded since it is named sample, which allows the project to run without these +configs. -To set AWS configs and credentials for other third-party dependencies, you need to create a copy of the sample docker-compose file without "sample" prepending the file name. +To set AWS configs and credentials for other third-party dependencies, you need to create a copy of the sample +docker-compose file without "sample" prepending the file name. Navigate to the root of the project. Copy `sample.env_docker_compose` to `.env_docker_compose`. @@ -208,7 +244,8 @@ $ cd $GOPATH/src/geeks-accelerator/oss/saas-starter-kit $ cp sample.env_docker_compose .env_docker_compose ``` -The example the docker-compose file specifies these environmental variables. The $ means that the variable is commented out. +The example the docker-compose file specifies these environmental variables. The $ means that the variable is commented +out. ``` $ AWS_ACCESS_KEY_ID= $ AWS_SECRET_ACCESS_KEY= @@ -217,19 +254,28 @@ $ AWS_USE_ROLE=false $ DD_API_KEY= ``` -In your new copy of the example docker-compose file ".env_docker_compose", set the AWS configs by updating the following environmental variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_REGION. Remember to remove the $ before the variable name. +In your new copy of the example docker-compose file ".env_docker_compose", set the AWS configs by updating the following +environmental variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_REGION. Remember to remove the $ before the +variable name. -As noted in the Local Installation section, the project is integrated with Datadog for observability. You can specify the API key for you Datadog account by setting the environmental variable: DD_API_KEY. +As noted in the Local Installation section, the project is integrated with Datadog for observability. You can specify +the API key for you Datadog account by setting the environmental variable: DD_API_KEY. ## Web API [cmd/web-api](https://gitlab.com/geeks-accelerator/oss/saas-starter-kit/tree/master/cmd/web-api) -REST API available to clients for supporting deeper integrations. This API is also a foundation for third-party integrations. The API implements JWT authentication that renders results as JSON to clients. +REST API available to clients for supporting deeper integrations. This API is also a foundation for third-party +integrations. The API implements JWT authentication that renders results as JSON to clients. -This web-api service is not directly used by the web-app service to prevent locking the functionally required for internally development of the web-app service to the same functionality exposed to clients via this web-api service. This separate web-api service can be exposed to clients and be maintained in a more rigid/structured process to manage client expectations. +This web-api service is not directly used by the web-app service to prevent locking the functionally required for +internally development of the web-app service to the same functionality exposed to clients via this web-api service. +This separate web-api service can be exposed to clients and be maintained in a more rigid/structured process to manage +client expectations. -The web-app will have its own internal API, similar to this external web-api service, but not exposed for third-party integrations. It is believed that in the beginning, having to define an additional API for internal purposes is worth the additional effort as the internal API can handle more flexible updates. +The web-app will have its own internal API, similar to this external web-api service, but not exposed for third-party +integrations. It is believed that in the beginning, having to define an additional API for internal purposes is worth +the additional effort as the internal API can handle more flexible updates. ### Making Requests to Web API @@ -239,21 +285,26 @@ http://localhost:3000 The easiest way to make requests to the web-api service is by using CURL via your CLI. -To make a request to the web-api service you must have an authenticated user. Users can be created with the API but an initial admin user must first be created. The initial admin user can be created with the web-app service. +To make a request to the web-api service you must have an authenticated user. Users can be created with the API but an +initial admin user must first be created. The initial admin user can be created with the web-app service. #### Creating Initial User -Create an initial user using the web-app service first. This pattern is how a user would signup to a SaaS product - a user would create an account on behalf of their organization. The subscription would then be associated with the organization and managed accordingly including billing. +Create an initial user using the web-app service first. This pattern is how a user would signup to a SaaS product - a +user would create an account on behalf of their organization. The subscription would then be associated with the +organization and managed accordingly including billing. While the web-app service is running, use the signup functionality to create a new user and corresponding account: http://localhost/signup -The email and password used to create the initial user and corresponding account can be used to make authenticated requests to the web-api service. +The email and password used to create the initial user and corresponding account can be used to make authenticated +requests to the web-api service. #### Authenticating -Before any authenticated requests can be sent you must acquire an auth token. Make a request using HTTP Basic auth with your email and password to get the token. +Before any authenticated requests can be sent you must acquire an auth token. Make a request using HTTP Basic auth with +your email and password to get the token. ```bash $ curl --user "admin@example.com:gophers" http://localhost:3000/v1/users/token @@ -278,19 +329,27 @@ $ curl -H "Authorization: Bearer ${TOKEN}" http://localhost:3000/v1/users ## Web App [cmd/web-app](https://gitlab.com/geeks-accelerator/oss/saas-starter-kit/tree/master/cmd/web-app) -Responsive web application that renders HTML using the `html/template` package from the standard library to enable direct interaction with clients and their users. It allows clients to sign up new accounts and provides user authentication with HTTP sessions. The web app relies on the Golang business logic packages developed to provide an API for internal requests. +Responsive web application that renders HTML using the `html/template` package from the standard library to enable +direct interaction with clients and their users. It allows clients to sign up new accounts and provides user +authentication with HTTP sessions. The web app relies on the Golang business logic packages developed to provide an API +for internal requests. Once the web-app service is running it will be available on port 80. http://localhost/ or http://localhost:80/ -While the web-api service is rocking, this web-app service is still in development. Only the signup functionality works in order for a user to create the initial user with role of admin and a corresponding account for their organization. If you would like to help, please email twins@geeksinthewoods.com. +While the web-api service is rocking, this web-app service is still in development. Only the signup functionality works +in order for a user to create the initial user with role of admin and a corresponding account for their organization. +If you would like to help, please email twins@geeksinthewoods.com. ### Functionality of Web App -The example web-app service is going to allow users to manage checklists. Users with role of admin will be allowed to create new checklists (projects). Each checklist will have tasks (items) associated with it. Tasks can be assigned to users with access to the checklist. Users can then update the status of a task. +The example web-app service is going to allow users to manage checklists. Users with role of admin will be allowed to +create new checklists (projects). Each checklist will have tasks (items) associated with it. Tasks can be assigned to +users with access to the checklist. Users can then update the status of a task. -We are referring to "checklists" as "projects" and "tasks" as "items" so this example web-app service will be generic enough for you to leverage and build upon without lots of renaming. +We are referring to "checklists" as "projects" and "tasks" as "items" so this example web-app service will be generic +enough for you to leverage and build upon without lots of renaming. This web-app service eventually will include the following functionality and corresponding web pages: - authentication @@ -327,19 +386,29 @@ This web-app service eventually will include the following functionality and cor ## Schema [cmd/schema](https://gitlab.com/geeks-accelerator/oss/saas-starter-kit/tree/master/cmd/schema) -Schema is a minimalistic database migration helper that can manually be invoked via CLI. It provides schema versioning and migration rollback. +Schema is a minimalistic database migration helper that can manually be invoked via CLI. It provides schema versioning +and migration rollback. -To support POD architecture, the schema for the entire project is defined globally and is located inside internal: [internal/schema](https://gitlab.com/geeks-accelerator/oss/saas-starter-kit/tree/master/internal/schema) +To support POD architecture, the schema for the entire project is defined globally and is located inside internal: +[internal/schema](https://gitlab.com/geeks-accelerator/oss/saas-starter-kit/tree/master/internal/schema) -Keeping a global schema helps ensure business logic can be decoupled across multiple packages. It is a firm belief that data models should not be part of feature functionality. Globally defined structs are dangerous as they create large code dependencies. Structs for the same database table can be defined by package to help mitigate large code dependencies. +Keeping a global schema helps ensure business logic can be decoupled across multiple packages. It is a firm belief that +data models should not be part of feature functionality. Globally defined structs are dangerous as they create large +code dependencies. Structs for the same database table can be defined by package to help mitigate large code +dependencies. The example schema package provides two separate methods for handling schema migration: * [Migrations](https://gitlab.com/geeks-accelerator/oss/saas-starter-kit/blob/master/internal/schema/migrations.go) - -List of direct SQL statements for each migration with defined version ID. A database table is created to persist executed migrations. Upon run of each schema migration run, the migraction logic checks the migration database table to check if it’s already been executed. Thus, schema migrations are only ever executed once. Migrations are defined as a function to enable complex migrations so results from query manipulated before being piped to the next query. +List of direct SQL statements for each migration with defined version ID. A database table is created to persist +executed migrations. Upon run of each schema migration run, the migraction logic checks the migration database table to +check if it’s already been executed. Thus, schema migrations are only ever executed once. Migrations are defined as a function to enable complex migrations so results from query manipulated before being piped to the next query. * [Init Schema](https://gitlab.com/geeks-accelerator/oss/saas-starter-kit/blob/master/internal/schema/init_schema.go) - -If you have a lot of migrations, it can be a pain to run all them. For example, when you are deploying a new instance of the app into a clean database. To prevent this, use the initSchema function that will run as-if no migration was run before (in a new clean database). +If you have a lot of migrations, it can be a pain to run all them. For example, when you are deploying a new instance of +the app into a clean database. To prevent this, use the initSchema function that will run as-if no migration was run before (in a new clean database). -Another bonus with the globally defined schema is that it enables the testing package to spin up database containers on-demand and automatically include all the migrations. This allows the testing package to programmatically execute schema migrations before running any unit tests. +Another bonus with the globally defined schema is that it enables the testing package to spin up database containers +on-demand and automatically include all the migrations. This allows the testing package to programmatically execute +schema migrations before running any unit tests. ### Accessing Postgres @@ -350,7 +419,8 @@ docker exec -it saas-starter-kit_postgres_1 /bin/bash bash-4.4# psql -u postgres shared ``` -The example project currently only includes a few tables. As more functionality is built into both the web-app and web-api services, the number of tables will expand. You can use the `show tables` command to list them. +The example project currently only includes a few tables. As more functionality is built into both the web-app and +web-api services, the number of tables will expand. You can use the `show tables` command to list them. ```commandline shared=# \dt List of relations @@ -384,7 +454,8 @@ Additional permissions required for unit tests. secretsmanager:DeleteSecret ``` -The example web app service allows static files to be served from AWS CloudFront for increased performance. Enable for static files to be served from CloudFront instead of from service directly. +The example web app service allows static files to be served from AWS CloudFront for increased performance. Enable for +static files to be served from CloudFront instead of from service directly. ``` cloudFront:ListDistributions ``` @@ -392,7 +463,8 @@ cloudFront:ListDistributions ### Datadog -Datadog has a custom init script to support setting multiple expvar urls for monitoring. The docker-compose file then can set a single env variable. +Datadog has a custom init script to support setting multiple expvar urls for monitoring. The docker-compose file then +can set a single env variable. ```bash DD_EXPVAR=service_name=web-app env=dev url=http://web-app:4000/debug/vars|service_name=web-api env=dev url=http://web-api:4001/debug/vars ``` @@ -405,7 +477,8 @@ DD_EXPVAR=service_name=web-app env=dev url=http://web-app:4000/debug/vars|servic ### Postgres and future MySQL support -Postgres is only supported based on its dependency of sqlxmigrate. MySQL should be easy to add to sqlxmigrate after determining a better method for abstracting the create table and other SQL statements from the main testing logic. +Postgres is only supported based on its dependency of sqlxmigrate. MySQL should be easy to add to sqlxmigrate after +determining a better method for abstracting the create table and other SQL statements from the main testing logic. ### SQLx bindvars @@ -609,9 +682,11 @@ instance will be a dedicated host since we need it always up and running, thus i ## What's Next -We are in the process of writing more documentation about this code. We welcome you to make enhancements to this documentation or just send us your feedback and suggestions ; ) +We are in the process of writing more documentation about this code. We welcome you to make enhancements to this +documentation or just send us your feedback and suggestions ; ) ## Join us on Gopher Slack -If you are having problems installing, troubles getting the project running or would like to contribute, join the channel #saas-starter-kit on [Gopher Slack](http://invite.slack.golangbridge.org/) +If you are having problems installing, troubles getting the project running or would like to contribute, join the +channel #saas-starter-kit on [Gopher Slack](http://invite.slack.golangbridge.org/) diff --git a/cmd/web-api/handlers/check.go b/cmd/web-api/handlers/check.go index f4da2ff..7d0e571 100644 --- a/cmd/web-api/handlers/check.go +++ b/cmd/web-api/handlers/check.go @@ -44,7 +44,6 @@ func (c *Check) Health(ctx context.Context, w http.ResponseWriter, r *http.Reque // Ping validates the service is ready to accept requests. func (c *Check) Ping(ctx context.Context, w http.ResponseWriter, r *http.Request, params map[string]string) error { - status := "pong" return web.RespondText(ctx, w, status, http.StatusOK) diff --git a/cmd/web-api/main.go b/cmd/web-api/main.go index ac55137..62422cc 100644 --- a/cmd/web-api/main.go +++ b/cmd/web-api/main.go @@ -79,7 +79,7 @@ func main() { var cfg struct { Env string `default:"dev" envconfig:"ENV"` HTTP struct { - Host string `default:"0.0.0.0:3000" envconfig:"HOST"` + Host string `default:"0.0.0.0:3001" envconfig:"HOST"` ReadTimeout time.Duration `default:"10s" envconfig:"READ_TIMEOUT"` WriteTimeout time.Duration `default:"10s" envconfig:"WRITE_TIMEOUT"` } @@ -369,7 +369,7 @@ func main() { var serviceMiddlewares []web.Middleware // Init redirect middleware to ensure all requests go to the primary domain contained in the base URL. - if primaryServiceHost != "127.0.0.0" && primaryServiceHost != "localhost" { + if primaryServiceHost != "127.0.0.1" && primaryServiceHost != "localhost" { redirect := mid.DomainNameRedirect(mid.DomainNameRedirectConfig{ RedirectConfig: mid.RedirectConfig{ Code: http.StatusMovedPermanently, diff --git a/cmd/web-app/main.go b/cmd/web-app/main.go index f5f2fb2..26bc283 100644 --- a/cmd/web-app/main.go +++ b/cmd/web-app/main.go @@ -6,6 +6,7 @@ import ( "encoding/json" "expvar" "fmt" + "geeks-accelerator/oss/saas-starter-kit/internal/mid" "html/template" "log" "net" @@ -21,7 +22,6 @@ import ( "time" "geeks-accelerator/oss/saas-starter-kit/cmd/web-app/handlers" - "geeks-accelerator/oss/saas-starter-kit/internal/mid" "geeks-accelerator/oss/saas-starter-kit/internal/platform/devops" "geeks-accelerator/oss/saas-starter-kit/internal/platform/flag" img_resize "geeks-accelerator/oss/saas-starter-kit/internal/platform/img-resize" @@ -347,7 +347,7 @@ func main() { var serviceMiddlewares []web.Middleware // Init redirect middleware to ensure all requests go to the primary domain contained in the base URL. - if primaryServiceHost != "127.0.0.0" && primaryServiceHost != "localhost" { + if primaryServiceHost != "127.0.0.1" && primaryServiceHost != "localhost" { redirect := mid.DomainNameRedirect(mid.DomainNameRedirectConfig{ RedirectConfig: mid.RedirectConfig{ Code: http.StatusMovedPermanently, @@ -555,7 +555,7 @@ func main() { // global variables exposed for rendering of responses with templates gvd := map[string]interface{}{ - "_App": map[string]interface{}{ + "_Service": map[string]interface{}{ "ENV": cfg.Env, "BuildInfo": cfg.BuildInfo, "BuildVersion": build, diff --git a/cmd/web-app/templates/layouts/base.tmpl b/cmd/web-app/templates/layouts/base.tmpl index 2f6a73c..148eeb7 100644 --- a/cmd/web-app/templates/layouts/base.tmpl +++ b/cmd/web-app/templates/layouts/base.tmpl @@ -30,7 +30,7 @@ diff --git a/cmd/web-app/templates/partials/buildinfo.tmpl b/cmd/web-app/templates/partials/buildinfo.tmpl index 14b6122..72fb96b 100644 --- a/cmd/web-app/templates/partials/buildinfo.tmpl +++ b/cmd/web-app/templates/partials/buildinfo.tmpl @@ -1,17 +1,17 @@ {{ define "partials/buildinfo" }} -
- {{if ne ._Site.BuildInfo.CiCommitTag ""}}
- Tag: {{ ._Site.BuildInfo.CiCommitRefName }}@{{ ._Site.BuildInfo.CiCommitSha }}
+
+ {{if ne ._Service.BuildInfo.CiCommitTag ""}}
+ Tag: {{ ._Service.BuildInfo.CiCommitRefName }}@{{ ._Service.BuildInfo.CiCommitSha }}
{{else}}
- Branch: {{ ._Site.BuildInfo.CiCommitRefName }}@{{ ._Site.BuildInfo.CiCommitSha }}
+ Branch: {{ ._Service.BuildInfo.CiCommitRefName }}@{{ ._Service.BuildInfo.CiCommitSha }}
{{end}}
- {{if ne ._Site.ENV "prod"}}
- Commit: {{ ._Site.BuildInfo.CiCommitTitle }}
- {{if ne ._Site.BuildInfo.CiJobId ""}}
- Job: {{ ._Site.BuildInfo.CiJobId }}
+ {{if ne ._Service.ENV "prod"}}
+ Commit: {{ ._Service.BuildInfo.CiCommitTitle }}
+ {{if ne ._Service.BuildInfo.CiJobId ""}}
+ Job: {{ ._Service.BuildInfo.CiJobId }}
{{end}}
- {{if ne ._Site.BuildInfo.CiPipelineId ""}}
- Pipeline: {{ ._Site.BuildInfo.CiPipelineId }}
+ {{if ne ._Service.BuildInfo.CiPipelineId ""}}
+ Pipeline: {{ ._Service.BuildInfo.CiPipelineId }}
{{end}}
{{end}}