package main import ( "encoding/json" "flag" "fmt" "os" "strconv" "strings" ) type Config struct { 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` Grayscale bool Sepia bool Amount int Quiet bool } // 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) } // Set output file dimensions using string symbol (x) 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 } func initConfigRegister() { // command line arguments flag.StringVar(&ConfigRegister.Method, "blending", "darken", "Blending methods : darken, lighten, fuckyfun") flag.StringVar(&ConfigRegister.OutputDir, "output", "./", "Output directory") flag.StringVar(&ConfigRegister.InputDir, "input", "/home/gator/Photos", "Input directory. Where to look the images from") flag.StringVar(&ConfigRegister.BaseImage, "base-img", "", "Path to the base image to work with. Random image if not set") flag.StringVar(&ConfigRegister.Dimensions, "dimensions", "1280x1024", "Out image dimensions. x") flag.BoolVar(&ConfigRegister.Grayscale, "grayscale", false, "Output image in shade of gray (around 50)") flag.BoolVar(&ConfigRegister.Sepia, "sepia", false, "Output image with sepia tone") flag.IntVar(&ConfigRegister.Amount, "amount", 2, "Number of images to blend together") flag.BoolVar(&ConfigRegister.Quiet, "quiet", false, "No progress messages") flag.Parse() // set output's width and height ConfigRegister.SetOutputDimensions() } // global register to acccess configuration values var ConfigRegister Config