Skip to content

Commit

Permalink
Big updates :v
Browse files Browse the repository at this point in the history
  • Loading branch information
dzungtran committed Mar 28, 2023
1 parent 764d410 commit 5c8d503
Show file tree
Hide file tree
Showing 36 changed files with 1,744 additions and 372 deletions.
11 changes: 8 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ ENV=development

# DB configs
DATABASE_URL=postgres://world:hello@postgres/echo_rest_api?sslmode=disable
REDIS_URL=redis://redis:6379
# REDIS_URL=redis://redis:6379

AUTH_PROVIDER=firebase
FIREBASE_CREDENTIALS='{firebase json admin key}'
FIREBASE_AUTH_CREDENTIALS='{filebase json auth key}'

# KRATOS_API_ENDPOINT=http://kratos:4433/
# KRATOS_WEBHOOK_API_KEY=very-very-very-secure-api-key

KRATOS_API_ENDPOINT=http://kratos:4433/
KRATOS_WEBHOOK_API_KEY=very-very-very-secure-api-key
AUTO_MIGRATE=true
PORT=8088
25 changes: 25 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch API",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/api",
"cwd": "${workspaceFolder}/cmd/api",
"envFile": "${workspaceFolder}/.env",
},
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"envFile": "${workspaceFolder}/.env"
}
]
}
2 changes: 0 additions & 2 deletions .vscode/settings.json

This file was deleted.

6 changes: 0 additions & 6 deletions 3rd-parties/kratos/config/hooks/body.jsonnet

This file was deleted.

57 changes: 0 additions & 57 deletions 3rd-parties/kratos/identity.schema.json

This file was deleted.

122 changes: 0 additions & 122 deletions 3rd-parties/kratos/kratos.yml

This file was deleted.

2 changes: 0 additions & 2 deletions 3rd-parties/postgres-scripts/kratos.sql

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Load golang image to build
FROM golang:1.18-alpine as builder
FROM golang:1.19-alpine as builder
ARG APP_PATH

RUN mkdir -p /app
Expand Down
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ Any feedback and pull requests are welcome and highly appreciated. Feel free to

<!--toc-->
- [Echo REST API boilerplate](#echo-rest-api-boilerplate)
* [Overview](#overview)
* [Features](#features)
* [Running the project](#running-the-project)
* [Environment variables](#environment-variables)
* [Commands](#commands)
* [Folder structure](#folder-structure)
* [Open source refs](#open-source-refs)
* [Contributing](#contributing)
* [TODOs](#todos)
- [HOW TO USE THIS TEMPLATE](#how-to-use-this-template)
- [Features](#features)
- [Running the project](#running-the-project)
- [Environment variables](#environment-variables)
- [Commands](#commands)
- [Folder structure](#folder-structure)
- [Open source refs](#open-source-refs)
- [Contributing](#contributing)
- [TODOs](#todos)

<!-- tocstop -->

Expand All @@ -37,13 +37,14 @@ Any feedback and pull requests are welcome and highly appreciated. Feel free to

> **NOTE**: **WAIT** until first CI run on github actions before cloning your new project.
<!--
## Overview

![Request processing flow - Sequence Diagram](out/docs/diagrams/overview/request_flow.svg)
![Request processing flow - Sequence Diagram](out/docs/diagrams/overview/request_flow.svg) -->

## Features

- [x] User Auth functionality (Signup, Login, Forgot Password, Reset Password, 2FA) using [Ory/Kratos](https://github.com/ory/kratos).
- [x] User Auth functionality (Signup, Login, Forgot Password, Reset Password, 2FA) using **Firebase Auth**
- [x] REST API using [labstack/echo](https://github.com/labstack/echo).
- [x] DB Migration using [golang-migrate/migrate](https://github.com/golang-migrate/migrate).
- [x] Modular structure.
Expand All @@ -59,10 +60,8 @@ Any feedback and pull requests are welcome and highly appreciated. Feel free to

- Make sure you have docker installed.
- Copy `.env.example` to `.env.docker`
- Add a new line `127.0.0.1 echo-rest.local` to `/etc/hosts` file.
- Run `docker compose up -d`.
- Go to `echo-rest.local:8088` to verify if the API server works.
- Go to `echo-rest.local:4455` to verify if the Kratos works.
- Go to `localhost:8088` to verify if the API server works.

## Environment variables

Expand All @@ -75,13 +74,15 @@ Setting your config as Environment Variables is recommended as by 12-Factor App.
| Name | Type | Description | Example value |
|------------------------|---------|------------------------------------------------------------------|-----------------------------------------------|
| DATABASE_URL | string | Data source URL for main DB | postgres://world:hello@postgres/echo_rest_api |
| KRATOS_API_ENDPOINT | string | Public endpoint of Kratos | http://kratos:4433/ |
| KRATOS_WEBHOOK_API_KEY | string | Api key for Kratos integration | very-very-very-secure-api-key |
| PORT | integer | Http port (accepts also port number only for heroku compability) | 8088 |
| AUTO_MIGRATE | boolean | Enable run migration every time the application starts | true |
| ENV | string | Environment name | development |
| REDIS_URL | string | Optional | redis://redis:6379 |

| AUTH_PROVIDER | string | Optional | firebase_auth |
| FIREBASE_CREDENTIALS | json | firebase json admin key | {firebase_admin_key} |
| FIREBASE_AUTH_CREDENTIALS | json | filebase json auth key | {firebase_auth_key} |
| KRATOS_API_ENDPOINT | string | [DEPRECATED] Public endpoint of Kratos | http://kratos:4433/ |
| KRATOS_WEBHOOK_API_KEY | string | [DEPRECATED] Api key for Kratos integration | very-very-very-secure-api-key |
</details>

## Commands
Expand All @@ -92,7 +93,7 @@ Setting your config as Environment Variables is recommended as by 12-Factor App.
| `make build-api` | Build application binary |
| `make setup` | Run commands to setup development env |
| `make run-db` | Run DB docker container on local |
| `go run ./tools/mod/ gen` | Generate module component codes. |
| `go run ./tools/mod/ gen` | Generate module component codes. e.g: `go run ./tools/mod/ gen -n Booking` |
| `make migration-create [migration_name]` | Create migration files. migration_name should be snake case |
| `make git-hooks` | Setup git hooks |
| `make routes` | Generate routes file for authorization |
Expand Down Expand Up @@ -132,7 +133,6 @@ Setting your config as Environment Variables is recommended as by 12-Factor App.
```

## Open source refs
- https://www.ory.sh/docs/kratos/self-service
- https://cuelang.org/docs/about/
- https://www.openpolicyagent.org/docs/latest/
- https://echo.labstack.com/guide/
Expand Down
7 changes: 7 additions & 0 deletions cmd/api/di/di.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package di

import (
"io/fs"

"github.com/dzungtran/echo-rest-api/config"
"github.com/dzungtran/echo-rest-api/infrastructure/datastore"
"github.com/dzungtran/echo-rest-api/modules/core"
coreTemplates "github.com/dzungtran/echo-rest-api/modules/core/handlers/templates"
"github.com/dzungtran/echo-rest-api/modules/projects"
"github.com/dzungtran/echo-rest-api/pkg/logger"
"github.com/dzungtran/echo-rest-api/pkg/middlewares"
Expand Down Expand Up @@ -70,3 +73,7 @@ func RegisterModules(e *echo.Echo, container *dig.Container) error {

return err
}

func GetCoreTemplates() fs.FS {
return coreTemplates.CoreTemplates
}
Loading

0 comments on commit 5c8d503

Please sign in to comment.