当前位置: 首页>>代码示例>>Golang>>正文


Golang go-homedir.Dir函数代码示例

本文整理汇总了Golang中github.com/mitchellh/go-homedir.Dir函数的典型用法代码示例。如果您正苦于以下问题:Golang Dir函数的具体用法?Golang Dir怎么用?Golang Dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Dir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getConfigDir

func getConfigDir() string {
	d, e := homedir.Dir()
	if e != nil {
		logrus.Fatalf("config.go: failed to get home dir: error=%v", e)
	}
	return path.Join(d, ".otsimo")
}
开发者ID:otsimo,项目名称:otsimoctl,代码行数:7,代码来源:config.go

示例2: TestDefaultKeys

func TestDefaultKeys(t *testing.T) {
	util.AppFs = afero.NewMemMapFs()

	// Don't pull in keys from the host OS. Setting this environment variable
	// is safe because it won't affect the parent shell.
	os.Setenv("SSH_AUTH_SOCK", "")

	dir, err := homedir.Dir()
	if err != nil {
		t.Errorf("Failed to get homedir: %q", err.Error())
		return
	}

	sshDir := filepath.Join(dir, ".ssh")
	if err := util.AppFs.MkdirAll(sshDir, 0600); err != nil {
		t.Errorf("Failed to create SSH directory: %q", err.Error())
		return
	}

	for _, key := range []string{"id_rsa", "id_dsa", "ignored"} {
		if err := writeRandomKey(filepath.Join(sshDir, key)); err != nil {
			t.Errorf("Failed to write key: %q", err.Error())
			return
		}
	}

	signers := defaultSigners()
	if len(signers) != 2 {
		t.Errorf("Expected two default signers, but got %v", signers)
	}
}
开发者ID:NetSys,项目名称:quilt,代码行数:31,代码来源:native_test.go

示例3: parseConfig

func parseConfig() *viper.Viper {
	if verbose {
		logrus.SetLevel(logrus.DebugLevel)
		logrus.SetOutput(os.Stderr)
	}

	// Get home directory for current user
	homeDir, err := homedir.Dir()
	if err != nil {
		fatalf("Cannot get current user home directory: %v", err)
	}
	if homeDir == "" {
		fatalf("Cannot get current user home directory")
	}

	// By default our trust directory (where keys are stored) is in ~/.notary/
	mainViper.SetDefault("trust_dir", filepath.Join(homeDir, filepath.Dir(configDir)))

	// If there was a commandline configFile set, we parse that.
	// If there wasn't we attempt to find it on the default location ~/.notary/config
	if configFile != "" {
		configFileExt = strings.TrimPrefix(filepath.Ext(configFile), ".")
		configFileName = strings.TrimSuffix(filepath.Base(configFile), filepath.Ext(configFile))
		configPath = filepath.Dir(configFile)
	} else {
		configPath = filepath.Join(homeDir, filepath.Dir(configDir))
	}

	// Setup the configuration details into viper
	mainViper.SetConfigName(configFileName)
	mainViper.SetConfigType(configFileExt)
	mainViper.AddConfigPath(configPath)

	// Find and read the config file
	err = mainViper.ReadInConfig()
	if err != nil {
		logrus.Debugf("Configuration file not found, using defaults")
		// If we were passed in a configFile via -c, bail if it doesn't exist,
		// otherwise ignore it: we can use the defaults
		if configFile != "" || !os.IsNotExist(err) {
			fatalf("error opening config file %v", err)
		}
	}

	// At this point we either have the default value or the one set by the config.
	// Either way, the command-line flag has precedence and overwrites the value
	if trustDir != "" {
		mainViper.Set("trust_dir", trustDir)
	}

	// Expands all the possible ~/ that have been given, either through -d or config
	// If there is no error, use it, if not, attempt to use whatever the user gave us
	expandedTrustDir, err := homedir.Expand(mainViper.GetString("trust_dir"))
	if err == nil {
		mainViper.Set("trust_dir", expandedTrustDir)
	}
	logrus.Debugf("Using the following trust directory: %s", mainViper.GetString("trust_dir"))

	return mainViper
}
开发者ID:useidel,项目名称:notary,代码行数:60,代码来源:main.go

示例4: New

// Opens/creates a config file for the specified appName.
// The path to config file is ~/.config/appName/config.ini.
func New(appName string) (g *GlobalConf, err error) {
	hmdr, err := homedir.Dir()
	if err != nil {
		return
	}

	// Create config file's directory.
	dirPath := path.Join(hmdr, ".config", appName)
	if err = os.MkdirAll(dirPath, 0755); err != nil {
		return
	}
	// Touch a config file if it doesn't exit.
	filePath := path.Join(dirPath, defaultConfigFileName)
	if _, err = os.Stat(filePath); err != nil {
		if !os.IsNotExist(err) {
			return
		}
		// create file
		if err = ioutil.WriteFile(filePath, []byte{}, 0644); err != nil {
			return
		}
	}
	opts := Options{Filename: filePath}
	return NewWithOptions(&opts)
}
开发者ID:vodolaz095,项目名称:globalconf,代码行数:27,代码来源:globalconf.go

示例5: GetLocalShell

func GetLocalShell() (*sh.Shell, error) {
	apiAddress := os.Getenv("IPFS_API")
	if apiAddress != "" {
		// IPFS_API takes priority.
		return sh.NewShell(apiAddress), nil
	}

	apiFilePath := ""
	ipath := os.Getenv("IPFS_PATH")
	if ipath != "" {
		apiFilePath = filepath.Join(ipath, "api")
	}
	home, err := hd.Dir() // Get home directory
	if err == nil {
		apiFilePath = filepath.Join(home, ".ipfs", "api")
	}

	// Read the file (hopefully) containing the location of an ipfs daemon
	apiFileContent, err := ioutil.ReadFile(apiFilePath)
	if err != nil {
		return nil, err
	}

	multiAddr := strings.Trim(string(apiFileContent), "\n\t ")
	apiAddress, err = multiaddrToNormal(multiAddr)
	if err != nil {
		return nil, err
	}
	return sh.NewShell(apiAddress), nil
}
开发者ID:kalmi,项目名称:ipfs-alt-sync,代码行数:30,代码来源:shell.go

示例6: getHomeDir

func getHomeDir() string {
	home, err := home.Dir()
	if err != nil {
		log.WithField("err", err).Fatal("failed to deterine a home directory")
	}
	return home
}
开发者ID:choplin,项目名称:pgenv,代码行数:7,代码来源:main.go

示例7: init

func init() {
	currentHomeDir, err := homedir.Dir()
	if err != nil {
		os.Stderr.WriteString(fmt.Sprintf("Cannot fetch your home directory: %v", err))
		os.Exit(1)
	}
	homeDir = currentHomeDir
}
开发者ID:9seconds,项目名称:ah,代码行数:8,代码来源:environments.go

示例8: vagrantDir

func vagrantDir() (string, error) {
	dir, err := homedir.Dir()
	if err != nil {
		return "", err
	}
	vagrantDir := dir + "/.vagrant/"
	return vagrantDir, nil
}
开发者ID:NetSys,项目名称:quilt,代码行数:8,代码来源:api.go

示例9: TestGetBucketsDirPath

func TestGetBucketsDirPath(t *testing.T) {
	actual, err := getBucketsDirPath()
	if err != nil {
		t.Errorf("occurred error when get bucket directory path: %v", err)
	}

	home, _ := homedir.Dir()
	expected := filepath.Join(home, ".honoka", "buckets")
	if actual != expected {
		t.Errorf("actual does not match expected. actual: %s , expected: %s", actual, expected)
	}
}
开发者ID:usk81,项目名称:honoka,代码行数:12,代码来源:honoka_test.go

示例10: HomeDir

// HomeDir is the home directory for the user. Light wrapper on the homedir lib.
func HomeDir() (string, error) {
	homish, err := homedir.Dir()
	if err != nil {
		return "", fmt.Errorf("Unable to acquire home directory: %v", err)
	}

	home, err := homedir.Expand(homish)
	if err != nil {
		return "", fmt.Errorf("Unable to expand home directory: %v", err)
	}

	return home, nil
}
开发者ID:rgbkrk,项目名称:iolopub,代码行数:14,代码来源:iolo.go

示例11: parseConfig

func parseConfig() {
	if verbose {
		logrus.SetLevel(logrus.DebugLevel)
		logrus.SetOutput(os.Stderr)
	}

	if trustDir == "" {
		// Get home directory for current user
		homeDir, err := homedir.Dir()
		if err != nil {
			fatalf("cannot get current user home directory: %v", err)
		}
		if homeDir == "" {
			fatalf("cannot get current user home directory")
		}
		trustDir = filepath.Join(homeDir, filepath.Dir(configDir))

		logrus.Debugf("no trust directory provided, using default: %s", trustDir)
	} else {
		logrus.Debugf("trust directory provided: %s", trustDir)
	}

	// If there was a commandline configFile set, we parse that.
	// If there wasn't we attempt to find it on the default location ~/.notary/config
	if configFile != "" {
		configFileExt = strings.TrimPrefix(filepath.Ext(configFile), ".")
		configFileName = strings.TrimSuffix(filepath.Base(configFile), filepath.Ext(configFile))
		configPath = filepath.Dir(configFile)
	} else {
		configPath = trustDir
	}

	// Setup the configuration details into viper
	mainViper.SetConfigName(configFileName)
	mainViper.SetConfigType(configFileExt)
	mainViper.AddConfigPath(configPath)

	// Find and read the config file
	err := mainViper.ReadInConfig()
	if err != nil {
		logrus.Debugf("configuration file not found, using defaults")
		// Ignore if the configuration file doesn't exist, we can use the defaults
		if !os.IsNotExist(err) {
			fatalf("fatal error config file: %v", err)
		}
	}
}
开发者ID:rogaha,项目名称:notary,代码行数:47,代码来源:main.go

示例12: init

func init() {
	stdcli.RegisterCommand(cli.Command{
		Name:        "login",
		Description: "log into your convox rack",
		Usage:       "[hostname]",
		Action:      cmdLogin,
		Flags: []cli.Flag{
			cli.StringFlag{
				Name:  "password, p",
				Usage: "Password to use for authentication. If not specified, prompt for password.",
			},
		},
	})

	home, err := homedir.Dir()

	if err != nil {
		stdcli.Error(err)
		return
	}

	ConfigRoot = filepath.Join(home, ".convox")

	if root := os.Getenv("CONVOX_CONFIG"); root != "" {
		ConfigRoot = root
	}

	stat, err := os.Stat(ConfigRoot)

	if err != nil && !os.IsNotExist(err) {
		stdcli.Error(err)
		return
	}

	if stat != nil && !stat.IsDir() {
		err := upgradeConfig()

		if err != nil {
			stdcli.Error(err)
			return
		}
	}
}
开发者ID:cleblanc87,项目名称:rack,代码行数:43,代码来源:login.go

示例13: saveRuntimeInfo

func saveRuntimeInfo() {

	homeDir, _ := home.Dir()
	parentPath := path.Join(homeDir, ".logk")

	_, err := os.Stat(parentPath)
	if err != nil {
		os.Mkdir(parentPath, 0777)
	}

	file, err := os.OpenFile(path.Join(parentPath, "runtimeinfo"), os.O_CREATE|os.O_WRONLY, 0666)
	if err != nil {
		panic(err)
	}
	defer file.Close()

	for k, v := range runtimeInfo {
		file.Write([]byte(fmt.Sprintf("%s %d\n", k, v)))
	}
}
开发者ID:wenzuojing,项目名称:logk,代码行数:20,代码来源:logk.go

示例14: CompatLoad

func CompatLoad() (*CompatConfigFile, error) {
	dockerCfg := cliconfig.NewConfigFile(filepath.Join(cliconfig.ConfigDir(), cliconfig.ConfigFileName))
	configFile := CompatConfigFile{
		dockerCfg,
		dockerCfg.Filename(),
	}

	// Try .docker/config.json first
	if _, err := os.Stat(configFile.filename); err == nil {
		file, err := os.Open(configFile.filename)
		if err != nil {
			return &configFile, err
		}
		defer file.Close()
		err = configFile.LoadFromReader(file)
		return &configFile, err
	} else if !os.IsNotExist(err) {
		return &configFile, err
	}

	// Try the old .dockercfg
	homeDir, _ := homedir.Dir()
	configFile.filename = filepath.Join(homeDir, ".dockercfg")
	if _, err := os.Stat(configFile.filename); err != nil {
		return &configFile, nil //missing file is not an error
	}
	file, err := os.Open(configFile.filename)
	if err != nil {
		return &configFile, err
	}
	defer file.Close()
	err = configFile.LegacyLoadFromReader(file)
	if err != nil {
		return &configFile, err
	}

	return &configFile, nil
}
开发者ID:number9code,项目名称:dogestry,代码行数:38,代码来源:login.go

示例15: recoverRuntimeInfo

func recoverRuntimeInfo() {
	homeDir, _ := home.Dir()
	file, err := os.OpenFile(path.Join(homeDir, ".logk", "runtimeinfo"), os.O_RDONLY, 0666)
	if err != nil {
		return
	}

	defer file.Close()
	buf := bufio.NewReader(file)

	for {
		line, err := buf.ReadString('\n')

		if err != nil {
			if err == io.EOF {
				break
			}
			panic(err)
		}

		var f string
		var p int64
		fmt.Sscanf(line, "%s %d", &f, &p)

		stat, err := os.Stat(f)

		if err != nil {
			p = int64(0)
		} else {
			if stat.Size() < p {
				p = 0
			}
		}

		runtimeInfo[f] = p
	}
}
开发者ID:wenzuojing,项目名称:logk,代码行数:37,代码来源:logk.go


注:本文中的github.com/mitchellh/go-homedir.Dir函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。