Esempio n. 1
0
func init() {
	flag.Parse()
	confPath := *flag.String("conf", path.Join(os.Getenv("HOME"), "conf/chirp.conf"), "conf file path")
	var err error
	Conf, err = goprop.Load(confPath)
	util.StartupFatalErr(err)
	fmt.Printf("%+v\n", Conf)
}
Esempio n. 2
0
/**
 * read basedir, uploaddir, port from conf file.
 */
func readConf() {
	if len(os.Args) < 2 {
		fmt.Fprintln(os.Stderr, "Usage: local_file_server [conf path]")
		os.Exit(1)
	}

	confpath := os.Args[1]
	kv, err := goprop.Load(confpath)
	checkErr(err)
	fmt.Println(kv)

	// check contains
	var contains bool = false
	if basedir, contains = kv["basedir"]; !contains {
		checkErr(errors.New("There is no basedir configuration in " + confpath))
	}
	if uploaddir, contains = kv["uploaddir"]; !contains {
		checkErr(errors.New("There is no uploaddir configuration in " + confpath))
	}
	if port, contains = kv["port"]; !contains {
		checkErr(errors.New("There is no port configuration in " + confpath))
	}

	checkDir(basedir)
	checkDir(uploaddir)

	// if the last char is '/', delete
	if strings.HasSuffix(basedir, "/") {
		basedir = basedir[:len(basedir)-1]
	}
	if strings.HasSuffix(uploaddir, "/") {
		uploaddir = uploaddir[:len(uploaddir)-1]
	}

	fmt.Printf("basedir = %s, uploaddir = %s, port = %s\n", basedir, uploaddir, port)
}