func initialize() (Config, *os.File, error) {
	// Overwrite default Usage()
	flag.Usage = func() {
		fmt.Fprintf(flag.CommandLine.Output(), "Cloudflare DynDNS - %s\n\n", Version)
		fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
		flag.PrintDefaults()
	}

	// Parse CLI Params
	configFile := flag.String("c", "", "Use `file.json` as configuration file")
	logFile := flag.String("l", os.Stdout.Name(), "Use `logfile` as output")
	logLevel := flag.Int("ll", 1, "Sets log level (1=fatal, 2=error, 3=warn, 4=info, 5=debug)")

	flag.Parse()

	if *configFile == "" || *logFile == "" {
		flag.Usage()
		return Config{}, &os.File{}, flag.ErrHelp
	}

	// Initialize Logging
	logFileFd, err := initializeLog(*logFile)
	if err != nil {
		return Config{}, &os.File{}, err
	}

	// Load configuration
	config, err := loadConfig(*configFile)
	if err != nil {
		return Config{}, &os.File{}, err
	}

	// Sets the required log level
	switch *logLevel {
	case 1:
		log.SetLevel(log.FatalLevel)
	case 2:
		log.SetLevel(log.ErrorLevel)
	case 3:
		log.SetLevel(log.WarnLevel)
	case 4:
		log.SetLevel(log.InfoLevel)
	case 5:
		log.SetLevel(log.DebugLevel)
	default:
		log.SetLevel(log.FatalLevel)
	}

	return config, logFileFd, nil
}
// Initializes the Application (param parsing, logger and config parsing)
Initializes the Application (param parsing, logger and config parsing)
// Initializes the Application ( param parsing logger and config parsing )
func initialize() (Config, *os.File, error) {
	flag.Usage = func() {
		fmt.Fprintf(flag.CommandLine.Output(), "Cloudflare DynDNS - %s\n\n", Version)
		fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
		flag.PrintDefaults()
	}
	configFile := flag.String("c", "", "Use `file.json` as configuration file")
	logFile := flag.String("l", os.Stdout.Name(), "Use `logfile` as output")
	logLevel := flag.Int("ll", 1, "Sets log level (1=fatal, 2=error, 3=warn, 4=info, 5=debug)")
	flag.Parse()
	if *configFile == "" || *logFile == "" {
		flag.Usage()
		return Config{}, &os.File{}, flag.ErrHelp
	}
	logFileFd, err := initializeLog(*logFile)
	if err != nil {
		return Config{}, &os.File{}, err
	}
	config, err := loadConfig(*configFile)
	if err != nil {
		return Config{}, &os.File{}, err
	}
	switch *logLevel {
	case 1:
		log.SetLevel(log.FatalLevel)
	case 2:
		log.SetLevel(log.ErrorLevel)
	case 3:
		log.SetLevel(log.WarnLevel)
	case 4:
		log.SetLevel(log.InfoLevel)
	case 5:
		log.SetLevel(log.DebugLevel)
	default:
		log.SetLevel(log.FatalLevel)
	}
	return config, logFileFd, nil
}
func initialize ( ) ( Config , * os . File , error ) { flag . Usage = func ( ) { fmt . Fprintf ( flag . CommandLine . Output ( ) , " \n \n " , Version ) fmt . Fprintf ( flag . CommandLine . Output ( ) , " \n " , os . Args [ 0 ] ) flag . PrintDefaults ( ) } configFile := flag . String ( " " , " " , " " ) logFile := flag . String ( " " , os . Stdout . Name ( ) , " " ) logLevel := flag . Int ( " " , 1 , " " ) flag . Parse ( ) if * configFile == " " || * logFile == " " { flag . Usage ( ) return Config { } , & os . File { } , flag . ErrHelp } logFileFd , err := initializeLog ( * logFile ) if err != nil { return Config { } , & os . File { } , err } config , err := loadConfig ( * configFile ) if err != nil { return Config { } , & os . File { } , err } switch * logLevel { case 1 : log . SetLevel ( log . FatalLevel ) case 2 : log . SetLevel ( log . ErrorLevel ) case 3 : log . SetLevel ( log . WarnLevel ) case 4 : log . SetLevel ( log . InfoLevel ) case 5 : log . SetLevel ( log . DebugLevel ) default : log . SetLevel ( log . FatalLevel ) } return config , logFileFd , nil }
Initializes the Application (param parsing, logger and config parsing)
Initializes the Application ( param parsing logger and config parsing )
// Overwrite default Usage() // Parse CLI Params // Initialize Logging // Load configuration // Sets the required log level