2022-04-26 13:51:49 +02:00
|
|
|
package main
|
|
|
|
|
2022-05-01 09:36:52 +02:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2022-05-01 15:33:55 +02:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2022-05-01 09:36:52 +02:00
|
|
|
)
|
|
|
|
|
2022-04-26 13:51:49 +02:00
|
|
|
type Config struct {
|
2022-05-01 15:33:55 +02:00
|
|
|
Method string `json:method`
|
|
|
|
OutputDir string `json:outputdir`
|
|
|
|
InputDir string `json:inputdir`
|
|
|
|
BaseImage string `json:baseimage`
|
|
|
|
Dimensions string `json:dimensions`
|
|
|
|
OutputWidth int `json:output_width`
|
|
|
|
OutputHeight int `json:output_height`
|
2022-05-01 17:49:51 +02:00
|
|
|
Grayscale bool
|
2022-05-01 20:52:03 +02:00
|
|
|
Amount int
|
2022-05-01 09:36:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// loads configuration values from json file
|
|
|
|
func (c *Config) LoadConfigFromFile(filePath string) {
|
|
|
|
file, _ := os.Open("conf.json")
|
|
|
|
defer file.Close()
|
|
|
|
decoder := json.NewDecoder(file)
|
|
|
|
configuration := Config{}
|
|
|
|
err := decoder.Decode(&configuration)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("error:", err)
|
|
|
|
}
|
|
|
|
fmt.Println(configuration.Method)
|
|
|
|
fmt.Println(configuration.OutputDir)
|
2022-04-26 13:51:49 +02:00
|
|
|
}
|
|
|
|
|
2022-05-01 15:33:55 +02:00
|
|
|
// Set output file dimensions using string symbol (<width>x<height>)
|
|
|
|
func (c *Config) SetOutputDimensions() {
|
|
|
|
split := strings.Split(c.Dimensions, "x")
|
|
|
|
width, _ := strconv.Atoi(split[0])
|
|
|
|
height, _ := strconv.Atoi(split[1])
|
|
|
|
c.OutputWidth = width
|
|
|
|
c.OutputHeight = height
|
|
|
|
}
|
|
|
|
|
2022-05-01 09:36:52 +02:00
|
|
|
// global register to acccess configuration values
|
2022-04-26 13:51:49 +02:00
|
|
|
var ConfigRegister Config
|