Compare commits

...

3 Commits

Author SHA1 Message Date
95c7bfe933 Connect to db (not working yet) 2022-10-25 23:30:42 +02:00
9d3cec7cf6 Env Template 2022-10-25 23:11:29 +02:00
d96ba361fc Added support for API config 2022-10-25 23:11:06 +02:00
4 changed files with 84 additions and 2 deletions

View File

@@ -14,7 +14,7 @@ def template(filename, target_path):
# Load Template # Load Template
template = env.get_template(filename) template = env.get_template(filename)
# Render Output # Render Output
content = template.render(db=config.db) content = template.render(db=config.db,api=config.api)
# Write Template to file # Write Template to file
filename_without_ext = os.path.splitext(filename)[0] filename_without_ext = os.path.splitext(filename)[0]
cooked_file = target_path+filename_without_ext cooked_file = target_path+filename_without_ext
@@ -25,4 +25,7 @@ def template(filename, target_path):
# Render the templates: # Render the templates:
## Create Docker-Compose ## Create Docker-Compose
template("docker-compose.yml.j2", "./src/") template("docker-compose.yml.j2", "./src/")
## Create API Config
template(".env.j2", "./bin/")
## Create Cleanup script
template("clean-data.sh.j2", "./src/") template("clean-data.sh.j2", "./src/")

View File

@@ -40,7 +40,7 @@ api: api-start
api-init: api-init:
cd src/api; go build -o ../../bin/engine_x_mgmt cd src/api; go build -o ../../bin/engine_x_mgmt
api-start: api-start:
./bin/engine_x_mgmt & cd bin; ./engine_x_mgmt
api-stop: api-stop:
# Setup UI # Setup UI

View File

@@ -0,0 +1,40 @@
package helper
import (
"database/sql"
"encoding/json"
"fmt"
_ "github.com/go-sql-driver/mysql"
)
func QueryString(queryStr string) []byte {
db_string := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", Db_User, Db_Pass, Db_Host, Db_Port, Db_Default_Db)
conn, err := sql.Open("mysql", db_string)
if err != nil {
LogErrorWarning(err)
return []byte("Error while connecting to database")
}
defer conn.Close()
qdata, err := conn.Query(queryStr)
LogErrorWarning(err)
defer qdata.Close()
kvp := make(map[string]string)
for qdata.Next() {
var key string
var value string
err = qdata.Scan(&key, &value)
LogErrorWarning(err)
kvp[key] = value
}
jsonData, err := json.Marshal(kvp)
if err != nil {
return []byte("Error while generating json")
}
return jsonData
}

View File

@@ -0,0 +1,39 @@
# Nginx API
## Listen IP
{%- if api.ip is defined %}
NGINX_API_LISTEN_IP={{ api.ip }}
{%- else %}
NGINX_API_LISTEN_IP=localhost
{%- endif %}
## Listen Port
{%- if api.port is defined %}
NGINX_API_LISTEN_PORT={{ api.port }}
{%- else %}
NGINX_API_LISTEN_PORT=79
{%- endif %}
# Database
## Database Host
{%- if db.host is defined %}
DB_HOST={{ db.host }}
{%- else %}
DB_HOST=localhost
{%- endif %}
## Database Port
{%- if db.port is defined %}
DB_PORT={{ db.port }}
{%- else %}
DB_PORT=3306
{%- endif %}
## Database User
{%- if db.user is defined %}
DB_USER={{ db.user }}
{%- else %}
DB_USER={{0/0}} # Throw error if not set / can be overwritten by envrionment variable
{%- endif %}
## Database Password
{%- if db.user_pw is defined %}
DB_USERPW={{ db.user_pw }}
{%- else %}
DB_USERPW={{0/0}} # Throw error if not set / can be overwritten by envrionment variable
{%- endif %}