func main()

in image/resources/knfsd-fsidd/main.go [41:101]


func main() {
	var err error

	cfg := new(Config)
	f := pflag.NewFlagSet(os.Args[0], pflag.ContinueOnError)

	// setup flags before reading the config files , otherwise the pflag package
	// will overwrite the config with the default values
	f.StringVar(&cfg.SocketPath, "socket", defaultSocketPath, "")
	f.StringVar(&cfg.Database.URL, "database-url", "", "")
	f.StringVar(&cfg.Database.Instance, "database-instance", "", "")
	f.StringVar(&cfg.Database.TableName, "table-name", "", "")
	f.BoolVar(&cfg.Database.IAMAuth, "iam-auth", false, "")
	f.BoolVar(&cfg.Database.PrivateIP, "private-ip", false, "")
	f.BoolVar(&cfg.Debug, "debug", false, "")
	f.BoolVar(&cfg.Cache, "cache", true, "")

	// read the config file before parsing the command line arguments so
	// that the command line arguments override any config values
	err = readDefaultConfig(cfg)
	if err != nil {
		log.Error.Printf("could not read config: %s", err)
		os.Exit(2)
	}

	// override values from the config file with environment variables
	err = readEnv(cfg)
	if err != nil {
		printConfigError(err)
		os.Exit(2)
	}

	// command line arguments overrides all other sources
	err = f.Parse(os.Args[1:])
	if errors.Is(err, pflag.ErrHelp) {
		os.Exit(0)
	}
	if err != nil {
		log.Error.Print(err)
		os.Exit(2)
	}

	if cfg.Debug {
		log.EnableDebug()
	}

	err = cfg.Validate()
	if err != nil {
		printConfigError(err)
		os.Exit(2)
	}

	ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
	defer cancel()

	err = run(ctx, cfg)
	if err != nil {
		log.Error.Print(err)
		os.Exit(1)
	}
}