
The template for this project was taken from the project of Nikolay Tuzov. This project is developed as a grps microservice for authentication, authorization and permissions.
- Standard CRUD operations of a database table
- JWT-based authentication
- Environment dependent application configuration management
- Structured logging with contextual information
- Error handling with proper error response generation
- Database migration
- Data validation
- Containerizing an application in Docker
- RPC framework: grpc
- Database access: pgx
- Database migration: golang-migrate
- Data validation: go-playground validator
- Logging: log/slog
- JWT: jwt-go
- Config reader: cleanv
- Env reader: godotenv

Note
This project is a microservice that works in conjunction with other microservice. For example you can use url-shortener
If this is your first time encountering Go, please follow the instructions to install Go on your computer. The project requires Go 1.21 or above.
Docker is also needed if you want to try the kit without setting up your own database server. The project requires Docker 17.05 or higher for the multi-stage build support.
Also for simple run commands i use Taskfile.
After installing Go, Docker and TaskFile, run the following commands to start experiencing:
## RUN SSO
# download the project
git clone [https://github.com/neepooha/url_shortener.git](https://github.com/neepooha/sso)
cd sso
# create config.env with that text:
$ nano config.env {
CONFIG_PATH=./config/local.yaml
POSTGRES_DB=url
POSTGRES_USER=myuser
POSTGRES_PASSWORD=mypass
}
# start a PostgreSQL database server in a Docker container
task db-start
# run the SSO server
go run ./cmd/sso
Also, you can start project in dev mode. For that you need rename in config.env "CONFIG_PATH=./config/local.yaml" to "CONFIG_PATH=./config/dev.yaml" in both projects and run following commads:
# run the SSO server
cd sso/
docker compose up --build
SSO-grpc Server running at http://localhost:44044. The server provides the following endpoints:
Regiter
: register new user in dbLogin
: log in to the applicationGETUserID
: get user ID by name
SetAdmin
: set exists user to admin in your app. You need be creator of appDelAdmin
: delete exists user from admin in your app. You need be creator of appIsAdmin
: is the user an admin by userIDIsCreator
: is the user a creator by userID
SetApp
: set new app in db. You will be creator of the appDelApp
: delete exists apps. You need be creator of appUpdApp
: update app name and secretGetAppID
: get app id by app name
Project has the following project layout:
sso/
├── cmd/ start of applications of the project
├── config/ configuration files for different environments
├── deployment/ configuration for create daemon in linux
├── internal/ private application and library code
│ ├── app/ application assembly
│ ├── config/ configuration library
│ ├── domain/ models of apps and users
│ ├── grpc/ grpc handlers
│ │ ├── apps/ handlers of apps
│ │ ├── auth/ handlers of auth
│ │ └── permissions/ handlers of permissions
│ ├── lib/ additional functions for logging, error handling, migration
│ ├── services/ logics of handlers
│ │ ├── apps/ handlers of apps
│ │ ├── auth/ handlers of auth
│ │ └── permissions/ handlers of permissions
│ └── storage/ storage library
├── migrations/ migrations
└── config.env config for sercret variables
The top level directories cmd
, internal
, lib
are commonly found in other popular Go projects, as explained in
Standard Go Project Layout.
Within each feature package, code are organized in layers (grpc server, service, db), following the dependency guidelines as described in the clean architecture.
for simple migration you can use the following commands
# For up migrations
task up
# For drop migrations
task drop
# Revert the last database migration.
tasl rollback
The application configuration is represented in internal/config/config.go
. When the application starts,
it loads the configuration from a configuration environment as well as environment variables. The path to the configuration environment
should be in the project root folder.
The config
directory contains the configuration files named after different environments. For example,
config/local.yml
corresponds to the local development environment and is used when running the application
via go run ./cmd/url-shortener
You can keep secrets in local/dev confing, but do not keep secrets in the prud and in the configuration environment. For set secret variable user github secrets and deploy.yaml.