This GitHub repo has my attempt to build a web application in Go without any Web Frameworks
The idea is a Q/A website where users can send questions to a user they follow, the user may choose to answer all or some of these questions, the answers are public to everyone.
This is not meant to be a production ready product at least initially, it is meant as an educational vehicle to learn good design principals, Go language, as well as other DevOps toolchain like Docker, Kubernetes, ...etc.
The code base follows Uncle Bob's Clean Architecture principals, where the code is broken down to
- Entities (model folder)
- Components
- Questions
- Answers
- Users
- Use Cases
- Shared
The main domain models, which in our case so far Question, Answer, User as well as base entity types and helpers, and basic domain operations on domain models using the domain ubiquitous language, like Ask, Answer, Like ... etc
Each component consists of all the basic layers needed to complete this component from top to bottom, like Use Cases, Repositories, Tests
This is shaping up to be a tiny MVC framework, interesting
This is not meant to depend on any fat frameworks, especially web frameworks, although a couple of things were used to tie things together.
- Uber's dig Dependency Injection framework
- Buffalo's box asset management
- Google's UUID package
- joho/godotenv godotenv
- gorm
- Okta Jwt Verifier
- Install Go
- Make sure your GOPATH environment variable is set correctly
- Clone the project in any directory outside of your $GOPATH location, this will ensure go modules work as expected, and all dependencies will be downloaded on first run
- (Optional) Install Docker
- Clone the repo on your machine
- Create a new .env file using the .env.dist as a template
- Fill in the missing secrets suitable for your environment
- Never check in the .env file, it is already included in .gitignore, and never add actual secrets in .env.dist
- There are two authentications methods supported
- Basic Username / Password Auth
- if you want to use this mode, make sure that AuthController is used in the ask.go instead of OktaController
- Okta based auth
- You will need to sign up for Okta developer account, more information on setting up mentioned below
- Basic Username / Password Auth
- From root of the repo on your terminal run the
following command
docker-compose -f docker-local.yml up go run main.go
- (Optional) if you prefer Docker, run the following commands
docker build -t go-askme . docker run --env-file=.env --rm -p 8080:8080 go-askme
- (Optional) Use docker compose
docker-compose build docker-compose up
Then from a browser window, navigate to http://localhost:8080
For more up to date information make sure to read through Okta developer docs
- Sign up for a new Okta developer account
- Create a new Application
- Choose Web as an application type
- Add a login redirect URI
- For local development add http://localhost:8080/authorization-code/callback
- Add a logout redirect URI
- For local development add http://localhost:8080
- Accept other defaults, then Save
- Copy generated ClientID, Client Secret, and set them to corresponding OKTA_CLIENT_ID, OKTA_CLIENT_SECRET in your .env file
- Navigate to API > Authorization Servers
- Copy the default Authorization Server, and set it to OKTA_ISSUER in your .env file
- Click on the Trusted Origins tab
- Add a new origin, for local development add http://localhost:8080 as both a Redirect & CORS
- To enable Registration, navigate to Users > Registration
- Click on Enable Registration, fill in the details you need
- Make sure to set the Default redirect to http://localhost:8080
All contributions are welcomed, check here for details