Stack Name - .go.tech.stack
The is the base reusable implementation for a Go type tech stack. Go is an open source programming language supported by Google.
The core features of Go include:
- it is a statically typed
- it is compiled programming language
- it is syntactically similar to C, but with memory safety, garbage collection, structural typing, and CSP-style concurrency
The Harbormaster Go tech stack contains the necessary templates and macros to generate a fully functional Go project complete with a vendor specific YAML pipeline file in order to install Go and the necessary dependencies to build, test, and deploy the resulting application.
Importantly, this tech stack uses gorm, an Object to Relational mapping library with support for MySQL, Postgres, SQLite, and SQL Server.
|Long Name||Base Go Tech Stack|
|Language(s)||Golang, YAML, XML, Velocity Macros|
|appPort||Port for Go app to listen on||input||default:8088|
|dbType||Supported database types||select|
|dbUserName||Name required to login to the database||input|
|dbPassword||Password required to login to the database||input|
|dbName||Name of the application database||input|
|dbArgs||Database args to append to connection statement||input|
|dbDisableForeignKeyConstraintWhenMigrating||Keep to true if the model contains associations||boolean||default:true|
- Vendor specific handlers using Velocity template files and macros to generate a pipeline YAML file for CI functionality
- Controllers used to handle URL invocation, business logic required for a given invocation and redirect to the DAO layer for read/write from/to the ORM layer
- Data access objects that interact with gorm to handle all CRUD activities with each model entity, including the contained data for an entity and its associations
- Handlers for formatting Request data to and from a JSON structure, and forces the HTTP header Content-Type to “application/json”
- Go struct declarations for each entity and enumeration found in the model. Includes an entities intrinsic data and associations with other structs
- Route handler for application HTTP requests for all CRUD capabilities including association related actions
- Leverages the Go test facility, contains the test handlers of core CRUD functionality for each model entity
- General handler for
- establishing a single database connection
- unmarshiling the HTTP Request body into a JSON object
- General handler for
If using a CI/CD platform such as CircleCI, AWS Codebuild, Jenkins, etc.., it is best to refer to the Pipeline YAML file generated for that platform.
If not using a CI/CD platform refer to the instructions below on how to use the generated project manually.
To get started manually
The following instructions assume Go is installed. If not, learn how to install GO here.
Go requires Git to be installed in order pull the required dependencies.
RUN go get github.com/gorilla/mux
RUN go get -u gorm.io/gorm
RUN go get github.com/joho/godotenv
RUN go get -u gorm.io/driver/mysql
Change the reference to mysql to whatever of the dependent database types is in use (postgres, sqlite, or sqlserver)
Change To Project Directory
To continue, change the current directory src/<app_name__> where <app_name> is the name given to the application during project generation.
List the directories content to verify being in the correct directory by seeing main.go in the list
RUN go mod init <>
RUN go mod tidy
where <> is the name given to the application during project generation.
go test <app_name>/api/test