diff --git a/.env.example b/.env.example
index 86c77e9..ba539bd 100644
--- a/.env.example
+++ b/.env.example
@@ -5,4 +5,9 @@ IS_RATE_LIMITER_ENABLED=true
THREADS_MAX_COUNT=50
POSTGRES_URL=postgres://localhost/micrach?pool_max_conns=5
THREAD_BUMP_LIMIT=500
-IS_CAPTCHA_ACTIVE=true
\ No newline at end of file
+IS_CAPTCHA_ACTIVE=true
+GATEWAY_URL=http://localhost:3001
+GATEWAY_API_KEY=example
+GATEWAY_BOARD_ID=b
+GATEWAY_BOARD_URL=http://localhost:3000
+GATEWAY_BOARD_DESCRIPTION=Random
\ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..913d0b1
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,2 @@
+dev:
+ nodemon --exec go run main.go --signal SIGTERM
diff --git a/config/config.go b/config/config.go
index 67dac10..45fcb40 100644
--- a/config/config.go
+++ b/config/config.go
@@ -7,6 +7,14 @@ import (
"strconv"
)
+type GatewayConfig struct {
+ Url string
+ ApiKey string
+ BoardId string
+ BoardUrl string
+ BoardDescription string
+}
+
type AppConfig struct {
Env string
Port int
@@ -15,6 +23,7 @@ type AppConfig struct {
ThreadsMaxCount int
ThreadBumpLimit int
IsCaptchaActive bool
+ Gateway GatewayConfig
}
type DbConfig struct {
@@ -46,6 +55,22 @@ func getValueOrDefaultString(value string, defaultValue string) string {
return value
}
+func getGatewayConfig() GatewayConfig {
+ url := os.Getenv("GATEWAY_URL")
+ apiKey := os.Getenv("GATEWAY_API_KEY")
+ boardId := os.Getenv("GATEWAY_BOARD_ID")
+ description := os.Getenv("GATEWAY_BOARD_DESCRIPTION")
+ boardUrl := os.Getenv("GATEWAY_BOARD_URL")
+
+ return GatewayConfig{
+ Url: url,
+ ApiKey: apiKey,
+ BoardId: boardId,
+ BoardUrl: boardUrl,
+ BoardDescription: description,
+ }
+}
+
func getAppConfig() AppConfig {
env := getValueOrDefaultString(os.Getenv("ENV"), "release")
port := getValueOrDefaultInt(os.Getenv("PORT"), 3000)
@@ -54,6 +79,7 @@ func getAppConfig() AppConfig {
threadsMaxCount := getValueOrDefaultInt(os.Getenv("THREADS_MAX_COUNT"), 50)
threadBumpLimit := getValueOrDefaultInt(os.Getenv("THREAD_BUMP_LIMIT"), 500)
isCaptchaActive := getValueOrDefaultBoolean(os.Getenv("IS_CAPTCHA_ACTIVE"), true)
+ gateway := getGatewayConfig()
return AppConfig{
Env: env,
@@ -63,6 +89,7 @@ func getAppConfig() AppConfig {
ThreadsMaxCount: threadsMaxCount,
ThreadBumpLimit: threadBumpLimit,
IsCaptchaActive: isCaptchaActive,
+ Gateway: gateway,
}
}
diff --git a/docker-compose.yml b/docker-compose.yml
index 256cc7b..0707256 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -12,6 +12,13 @@ services:
IS_RATE_LIMITER_ENABLED: ${IS_RATE_LIMITER_ENABLED}
THREADS_MAX_COUNT: ${THREADS_MAX_COUNT}
POSTGRES_URL: ${POSTGRES_URL}
+ THREAD_BUMP_LIMIT: ${THREAD_BUMP_LIMIT}
+ IS_CAPTCHA_ACTIVE: ${IS_CAPTCHA_ACTIVE}
+ GATEWAY_URL: ${GATEWAY_URL}
+ GATEWAY_API_KEY: ${GATEWAY_API_KEY}
+ GATEWAY_BOARD_ID: ${GATEWAY_BOARD_ID}
+ GATEWAY_BOARD_URL: ${GATEWAY_BOARD_URL}
+ GATEWAY_BOARD_DESCRIPTION: ${GATEWAY_BOARD_DESCRIPTION}
volumes:
- /root/micrach-go/uploads:/app/uploads
deploy:
@@ -33,11 +40,11 @@ services:
traefik.http.middlewares.micrach-https-redirect.redirectscheme.scheme: "https"
traefik.http.routers.micrach.entrypoints: "http"
- traefik.http.routers.micrach.rule: "Host(`micrach.igonin.dev`)"
+ traefik.http.routers.micrach.rule: "Host(`micrach.igonin.dev`) && PathPrefix(`/${GATEWAY_BOARD_ID}`)"
traefik.http.routers.micrach.middlewares: "micrach-https-redirect"
traefik.http.routers.micrach-secure.entrypoints: "https"
- traefik.http.routers.micrach-secure.rule: "Host(`micrach.igonin.dev`)"
+ traefik.http.routers.micrach-secure.rule: "Host(`micrach.igonin.dev`) && PathPrefix(`/${GATEWAY_BOARD_ID}`)"
traefik.http.routers.micrach-secure.tls: "true"
traefik.http.routers.micrach-secure.service: "micrach"
diff --git a/gateway/connect.go b/gateway/connect.go
new file mode 100644
index 0000000..2b859b2
--- /dev/null
+++ b/gateway/connect.go
@@ -0,0 +1,39 @@
+package gateway
+
+import (
+ "bytes"
+ "encoding/json"
+ "io/ioutil"
+ "log"
+ "net/http"
+
+ Config "micrach/config"
+)
+
+// Make http request to gateway to tell the board id and description
+func Connect() {
+ requestBody, _ := json.Marshal(map[string]string{
+ "id": Config.App.Gateway.BoardId,
+ "name": Config.App.Gateway.BoardDescription,
+ "url": Config.App.Gateway.Url,
+ })
+ url := Config.App.Gateway.Url + "/api/boards"
+ req, err := http.NewRequest("POST", url, bytes.NewBuffer(requestBody))
+ if err != nil {
+ log.Panicln(err)
+ }
+ req.Header.Set("Authorization", Config.App.Gateway.ApiKey)
+ req.Header.Set("Content-Type", "application/json")
+ client := &http.Client{}
+ resp, err := client.Do(req)
+ if err != nil {
+ log.Panicln(err)
+ }
+ //We Read the response body on the line below.
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ log.Panicln(err)
+ }
+ log.Println(string(body))
+ log.Println("gateway - online")
+}
diff --git a/gateway/controllers.go b/gateway/controllers.go
new file mode 100644
index 0000000..b0b7a16
--- /dev/null
+++ b/gateway/controllers.go
@@ -0,0 +1,19 @@
+package gateway
+
+import (
+ Config "micrach/config"
+ "net/http"
+
+ "github.com/gin-gonic/gin"
+)
+
+func Ping(c *gin.Context) {
+ headerKey := c.Request.Header.Get("Authorization")
+ if Config.App.Gateway.ApiKey != headerKey {
+ c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
+ return
+ }
+ c.JSON(200, gin.H{
+ "message": "pong",
+ })
+}
diff --git a/main.go b/main.go
index 5f8c232..20240c3 100644
--- a/main.go
+++ b/main.go
@@ -16,6 +16,7 @@ import (
Config "micrach/config"
Controllers "micrach/controllers"
Db "micrach/db"
+ Gateway "micrach/gateway"
Repositories "micrach/repositories"
Templates "micrach/templates"
Utils "micrach/utils"
@@ -62,6 +63,10 @@ func main() {
}
router.Static("/uploads", "./uploads")
router.Static("/static", "./static")
+ if Config.App.Gateway.Url != "" {
+ router.GET("/api/ping", Gateway.Ping)
+ Gateway.Connect()
+ }
router.GET("/", Controllers.GetThreads)
router.POST("/", Controllers.CreateThread)
router.GET("/:threadID", Controllers.GetThread)
diff --git a/static/icons/github.svg b/static/icons/github.svg
new file mode 100644
index 0000000..aa05db9
--- /dev/null
+++ b/static/icons/github.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/static/images/github-icon.png b/static/images/github-icon.png
deleted file mode 100644
index 8b25551..0000000
Binary files a/static/images/github-icon.png and /dev/null differ
diff --git a/static/styles/index.css b/static/styles/index.css
index 8fb0bdb..4d9fde7 100644
--- a/static/styles/index.css
+++ b/static/styles/index.css
@@ -1,3 +1,7 @@
#pagesList {
flex-wrap: wrap
}
+
+.github-icon {
+ width: 2.5rem;
+}
\ No newline at end of file
diff --git a/templates/components/footer.html b/templates/components/footer.html
index b8613a3..7234109 100644
--- a/templates/components/footer.html
+++ b/templates/components/footer.html
@@ -2,7 +2,7 @@
diff --git a/templates/head/static.html b/templates/head/static.html
index a7cf3d6..a8b980d 100644
--- a/templates/head/static.html
+++ b/templates/head/static.html
@@ -11,6 +11,6 @@
crossorigin="anonymous">
-
-
+
+
{{ end }}