feat: update config

This commit is contained in:
Yanislav Igonin 2022-02-10 13:10:48 +02:00
parent e1eb14c19e
commit 5fe7b8ed74
2 changed files with 12 additions and 5 deletions

View File

@ -10,6 +10,8 @@ import (
type GatewayConfig struct { type GatewayConfig struct {
Url string Url string
ApiKey string ApiKey string
BoardId string
BoardDescription string
} }
type AppConfig struct { type AppConfig struct {
@ -55,10 +57,14 @@ func getValueOrDefaultString(value string, defaultValue string) string {
func getGatewayConfig() GatewayConfig { func getGatewayConfig() GatewayConfig {
url := os.Getenv("GATEWAY_URL") url := os.Getenv("GATEWAY_URL")
apiKey := os.Getenv("GATEWAY_API_KEY") apiKey := os.Getenv("GATEWAY_API_KEY")
boardId := os.Getenv("GATEWAY_BOARD_ID")
description := os.Getenv("GATEWAY_BOARD_DESCRIPTION")
return GatewayConfig{ return GatewayConfig{
Url: url, Url: url,
ApiKey: apiKey, ApiKey: apiKey,
BoardId: boardId,
BoardDescription: description,
} }
} }

View File

@ -2,6 +2,7 @@ package controllers
import ( import (
Config "micrach/config" Config "micrach/config"
"net/http"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -9,7 +10,7 @@ import (
func Ping(c *gin.Context) { func Ping(c *gin.Context) {
headerKey := c.Request.Header.Get("Authorization") headerKey := c.Request.Header.Get("Authorization")
if Config.App.Gateway.ApiKey != headerKey { if Config.App.Gateway.ApiKey != headerKey {
c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"}) c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
return return
} }
c.JSON(200, gin.H{ c.JSON(200, gin.H{