-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
2,768 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
# Terigu | ||
|
||
## Start | ||
Me try to build 🍜 with [fiber](https://gofiber.io/) + [htmx](https://htmx.org/) + [sqlc](https://sqlc.dev/) | ||
|
||
## Development | ||
|
||
### Dependencies | ||
|
||
- [sqlc](https://docs.sqlc.dev/en/stable/overview/install.html) | ||
if using go install please make sure the go bin path is in $PATH | ||
|
||
### Run local | ||
|
||
- `docker-compose up -d` | ||
- `cp .env.staging .env` | ||
- run `make compose-up` | ||
- run `make migrate-up` | ||
- `npm install` | ||
- `make` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/kobamkode/terigu/internal/database" | ||
"github.com/kobamkode/terigu/internal/env" | ||
"github.com/kobamkode/terigu/internal/server" | ||
) | ||
"fmt" | ||
"log" | ||
|
||
func init() { | ||
env.Load() | ||
} | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/gofiber/template/html/v2" | ||
"github.com/kobamkode/terigu/config" | ||
"github.com/kobamkode/terigu/database" | ||
"github.com/kobamkode/terigu/internal/routes" | ||
) | ||
|
||
func main() { | ||
db := database.NewDBPool() | ||
engine := html.New("./views", ".html") | ||
|
||
app := fiber.New(fiber.Config{ | ||
Views: engine, | ||
}) | ||
|
||
db := database.PostgresConn() | ||
defer db.Close() | ||
|
||
server.Run(db) | ||
store := database.RedisConn() | ||
|
||
routes.Setup(app, db, store) | ||
|
||
log.Fatal(app.Listen(fmt.Sprintf(":%s", config.Get("APP_PORT")))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
services: | ||
db: | ||
postgres: | ||
image: postgres:alpine | ||
ports: | ||
- 5432:5432 | ||
volumes: | ||
- pgdata:/var/lib/postgresql/data | ||
environment: | ||
POSTGRES_PASSWORD: 123456 | ||
redis: | ||
image: redis:alpine | ||
ports: | ||
- 6379:6379 | ||
|
||
volumes: | ||
pgdata: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/gofiber/fiber/v2/middleware/csrf" | ||
"github.com/gofiber/fiber/v2/middleware/logger" | ||
"github.com/gofiber/fiber/v2/middleware/session" | ||
"github.com/gofiber/fiber/v2/utils" | ||
"github.com/gofiber/storage/redis/v3" | ||
"github.com/joho/godotenv" | ||
) | ||
|
||
func Get(key string) string { | ||
err := godotenv.Load(".env") | ||
if err != nil { | ||
log.Print("Error loading .env file") | ||
} | ||
return os.Getenv(key) | ||
} | ||
|
||
func GetInt(key string) int { | ||
g := Get(key) | ||
i, err := strconv.Atoi(g) | ||
if err != nil { | ||
return -1 | ||
} | ||
return i | ||
} | ||
|
||
func Session(storage *redis.Storage) session.Config { | ||
return session.Config{ | ||
Storage: storage, | ||
} | ||
} | ||
|
||
func Csrf(session *session.Store) csrf.Config { | ||
const HeaderName = "X-Csrf-Token" | ||
return csrf.Config{ | ||
KeyLookup: "header:" + HeaderName, | ||
CookieName: "__Host-csrf_", | ||
CookieSameSite: "Lax", | ||
CookieSecure: true, | ||
CookieSessionOnly: true, | ||
CookieHTTPOnly: true, | ||
Expiration: 1 * time.Hour, | ||
KeyGenerator: utils.UUIDv4, | ||
Extractor: csrf.CsrfFromHeader(HeaderName), | ||
Session: session, | ||
SessionKey: fmt.Sprintf("%s.csrf.token", Get("APP_NAME")), | ||
HandlerContextKey: fmt.Sprintf("%s.csrf.handler", Get("APP_NAME")), | ||
} | ||
} | ||
|
||
func Logger() logger.Config { | ||
return logger.Config{ | ||
Format: "${time} ${locals:requestid} ${latency} ${status} - ${method} ${path}\n", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package database | ||
|
||
import ( | ||
"github.com/gofiber/storage/redis/v3" | ||
"github.com/kobamkode/terigu/config" | ||
) | ||
|
||
func RedisConn() *redis.Storage { | ||
return redis.New(redis.Config{ | ||
Host: config.Get("REDIS_HOST"), | ||
Port: config.GetInt("REDIS_PORT"), | ||
Password: config.Get("REDIS_PASSWORD"), | ||
Database: 0, | ||
Reset: false, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.