# README
Goframe
Go skeleton (MongoDB, Neo4J, Postgres), Remove unused or unnecessary function or code
Libraries
Use Go Module for install all dependencies required this application.
If use private repository dependency please make use GIT Private key created ssh-keygen -t rsa -P "" -C "email" -m PEM
How To Run and Deploy
Before run this service. Make sure all requirements dependencies has been installed likes Golang, Docker, and database
Structure
This service tries to implement the clean architecture.
├── app (Interface Adapters)
│ ├── controller
│ └── presenter
│── config (Application config)
│── console (Terminal console)
│── domain (Enterprise Business Rules)
│ ├── repository (Application Business Rules)
│ └── service (Application Business Rules)
│── infrastructure (Frameworks & Drivers)
│ ├── provider (Drivers)
│ └── web (Web Application)
│── migration (Migration Files)
│── test (Test Helper & Mocks)
└── main.go (Main Application)
Local
Use command go go run main.go
in root folder for run this application.
Migration
go run main.go migrate:run
Command used to run the migration files.go run main.go migrate:rollback
Command used to rollback the migration.go run main.go migrate:create
Command used to create a new migration file.
Docker
goframe uses docker multi stages build, minimal docker version is 17.05. If docker already installed use command.
Insert arguments GIT_PRIVATE_KEY
and GOPRIVATE
for create an image
This command will build the images.
docker build -f Dockerfile --build-arg GIT_PRIVATE_KEY=$GIT_PRIVATE_KEY --build-arg GOPRIVATE=$GOPRIVATE -t goframe:$(VERSION) .
To run service use this command
docker run --name goframe -d -e ADDRESS=:8080 -e <environment> $(IMAGE):$(VERSION)
Test
Local
For run unit test, from root project you can go to folder or package and execute command
go test -v -cover -coverprofile=coverage.out -covermode=set
go tool cover -html=coverage.out
go tool
will generate GUI for test coverage. Available package or folder can be tested.
/app/controller
/app/presenter
/config
/domain
Docker
Run docker-compose to run test
docker-compose -p "$(PROJECT_NAME)" -f docker/docker-compose.yaml build app
docker-compose -p "$(PROJECT_NAME)" -f docker/docker-compose.yaml run --rm app test
docker-compose -p "$(PROJECT_NAME)" -f docker/docker-compose.yaml down
Environment Variables
Environment variables for Development use config-example.yaml, Change the file name to config.yaml
SERVER_PORT
- Port address used by service, default is8080
LOGGER_LEVEL
- Log level(debug, info, error, warn, etc)LOGGER_CALLER_ENABLED
- Enabled log report caller.LOGGER_FORMAT
- Format specific for log.text
- Log format will become standard text output, this used for developmentjson
- Log format will become JSON format, usually used for production
NEO4J_ADDRESS
- Neo4J database addressbolt+routing://<host>:<port>
bolt+routing://
- Used with causal clusterbolt://
- Used with single server
NEO4J_USERNAME
- Neo4J database usernameNEO4J_PASSWORD
- Neo4J database passwordNEO4J_MAX_CONN_POOL
- Neo4j maximum number of connections per URL to allow on this driverNEO4J_MAX_CONN_LIFETIME
- Maximum connection life time on pooled connections. Values less than or equal to 0 disables the lifetime check (in Minutes)NEO4J_LOG_ENABLED
- Neo4J database log enabled (true
/false
)NEO4J_LOG_LEVEL
Neo4J type that default logging implementations1
- Level error2
- Level warning3
- Level info4
- Level debug
POSTGRES_ADDRESS
- Database hostnamePOSTGRES_DATABASE
- Database namePOSTGRES_USERNAME
- Database usernamePOSTGRES_PASSWORD
- Database PasswordPOSTGRES_PARAMS
- Database params, use space if more than one param (sslmode=disable)POSTGRES_MAX_OPEN_CONN
- Database max open connectionPOSTGRES_MAX_IDLE_CONN
- Database max idle connectionPOSTGRES_DEBUG_ENABLED
- Enable debug modePOSTGRES_LOG_LEVEL
- Database log level, default is 21
- Silent2
- Error3
- Warn4
- Info
MONGO_ADDRESS
- MongoDB address withmongodb://<host>:<port>
,mongodb+srv://<host>:<port>
, and"mongodb://<host>:<port>/?replicaSet=<replica>&connect=direct"
read the documentation for more informationMONGO_DATABASE
- MongoDB database nameMONGO_USERNAME
- MongoDB usernameMONGO_PASSWORD
- MongoDB passwordMONGO_MAX_POOL
- MongoDB max pool connectionELASTICSEARCH_ADDRESS
- Elasticsearch urls, use,
to separate urlshttp://localhost:9200,http://localhost:9201
ELASTICSEARCH_USERNAME
- Elasticsearch usernameELASTICSEARCH_PASSWORD
- Elasticsearch passwordELASTICSEARCH_MAX_CONN_PER_HOST
- Elasticsearch max connection per hostsELASTICSEARCH_MAX_IDLE_PER_HOST
- Elasticsearch max idle connection per hostsREDIS_ADDRESS
- Redis addresslocalhost:6379
REDIS_PASSWORD
- Redis passwordREDIS_DATABASE
- Redis databaseREDIS_POOL_SIZE
- Redis pool sizeREDIS_MIN_IDLE_CONN
- Redis min idle connection