Skip to content

My GoLang learning journey by building an AskFm clone

License

Notifications You must be signed in to change notification settings

lenaggar/go-askme

 
 

Repository files navigation

Go-ASKME Build Status

This GitHub repo has my attempt to build a web application in Go without any Web Frameworks

Introduction

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.

Design Goals

The code base follows Uncle Bob's Clean Architecture principals, where the code is broken down to

  1. Entities (model folder)
  2. Components
    1. Questions
    2. Answers
    3. Users
  3. Use Cases
  4. Shared

Entities

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

Components

Each component consists of all the basic layers needed to complete this component from top to bottom, like Use Cases, Repositories, Tests

Framework

This is shaping up to be a tiny MVC framework, interesting

Dependencies

This is not meant to depend on any fat frameworks, especially web frameworks, although a couple of things were used to tie things together.

  1. Uber's dig Dependency Injection framework
  2. Buffalo's box asset management
  3. Google's UUID package
  4. joho/godotenv godotenv
  5. gorm
  6. Okta Jwt Verifier

Build and Run

  • 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
  • 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

Setting up Okta Developer Account

For more up to date information make sure to read through Okta developer docs

  1. Sign up for a new Okta developer account
  2. Create a new Application
    1. Choose Web as an application type
  3. Add a login redirect URI
    1. For local development add http://localhost:8080/authorization-code/callback
  4. Add a logout redirect URI
    1. For local development add http://localhost:8080
  5. Accept other defaults, then Save
  6. Copy generated ClientID, Client Secret, and set them to corresponding OKTA_CLIENT_ID, OKTA_CLIENT_SECRET in your .env file
  7. Navigate to API > Authorization Servers
    1. Copy the default Authorization Server, and set it to OKTA_ISSUER in your .env file
    2. Click on the Trusted Origins tab
      1. Add a new origin, for local development add http://localhost:8080 as both a Redirect & CORS
  8. To enable Registration, navigate to Users > Registration
    1. Click on Enable Registration, fill in the details you need
    2. Make sure to set the Default redirect to http://localhost:8080

Want to Contribute?

All contributions are welcomed, check here for details

About

My GoLang learning journey by building an AskFm clone

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 87.4%
  • Shell 9.3%
  • CSS 2.3%
  • Dockerfile 1.0%