mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-20 19:19:06 +08:00
Correct style.
This commit is contained in:
@ -49,7 +49,7 @@ func configCmd(c *commander.Command, inp []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
filename, err := config.GetConfigFilePath(confdir)
|
||||
filename, err := config.Filename(confdir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func initCmd(c *commander.Command, inp []string) error {
|
||||
}
|
||||
|
||||
u.POut("initializing ipfs node at %s\n", configpath)
|
||||
filename, err := config.GetConfigFilePath(configpath)
|
||||
filename, err := config.Filename(configpath)
|
||||
if err != nil {
|
||||
return errors.New("Couldn't get home directory path")
|
||||
}
|
||||
@ -63,11 +63,10 @@ func initCmd(c *commander.Command, inp []string) error {
|
||||
|
||||
cfg.Datastore = config.Datastore{}
|
||||
if len(dspath) == 0 {
|
||||
dspath, err = config.GetDefaultPathRoot()
|
||||
dspath, err = config.DataStorePath("")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dspath = dspath + "/datastore"
|
||||
}
|
||||
cfg.Datastore.Path = dspath
|
||||
cfg.Datastore.Type = "leveldb"
|
||||
|
@ -53,7 +53,7 @@ Use "ipfs help <command>" for more information about a command.
|
||||
}
|
||||
|
||||
func init() {
|
||||
config, err := config.GetDefaultPathRoot()
|
||||
config, err := config.PathRoot()
|
||||
if err != nil {
|
||||
config = ""
|
||||
}
|
||||
@ -78,7 +78,7 @@ func main() {
|
||||
}
|
||||
|
||||
func localNode(confdir string, online bool) (*core.IpfsNode, error) {
|
||||
filename, err := config.GetConfigFilePath(confdir)
|
||||
filename, err := config.Filename(confdir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -96,14 +96,14 @@ func localNode(confdir string, online bool) (*core.IpfsNode, error) {
|
||||
func getConfigDir(c *commander.Command) (string, error) {
|
||||
conf := c.Flag.Lookup("c").Value.Get()
|
||||
if conf == nil {
|
||||
return config.GetDefaultPathRoot()
|
||||
return config.PathRoot()
|
||||
}
|
||||
confStr, ok := conf.(string)
|
||||
if !ok {
|
||||
return "", errors.New("failed to retrieve config flag value.")
|
||||
}
|
||||
if len(confStr) == 0 {
|
||||
return config.GetDefaultPathRoot()
|
||||
return config.PathRoot()
|
||||
}
|
||||
|
||||
return u.TildeExpansion(confStr)
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
)
|
||||
@ -42,27 +43,44 @@ type Config struct {
|
||||
Bootstrap []*BootstrapPeer // local nodes's bootstrap peers
|
||||
}
|
||||
|
||||
// Return the default configuration root directory
|
||||
func GetDefaultPathRoot() (string, error) {
|
||||
dir := os.Getenv("IPFS_CONFIG_DIR")
|
||||
const DefaultPathRoot = "~/.go-ipfs"
|
||||
const DefaultConfigFile = "config"
|
||||
const DefaultDataStoreDirectory = "datastore"
|
||||
const EnvDir = "IPFS_DIR"
|
||||
|
||||
// PathRoot returns the default configuration root directory
|
||||
func PathRoot() (string, error) {
|
||||
dir := os.Getenv(EnvDir)
|
||||
var err error
|
||||
if len(dir) == 0 {
|
||||
dir, err = u.TildeExpansion("~/.go-ipfs")
|
||||
dir, err = u.TildeExpansion(DefaultPathRoot)
|
||||
}
|
||||
return dir, err
|
||||
}
|
||||
|
||||
// Return the configuration file path given a configuration root directory
|
||||
// If the configuration root directory is empty, use the default one
|
||||
func GetConfigFilePath(configroot string) (string, error) {
|
||||
// Path returns the path `extension` relative to the configuration root. If an
|
||||
// empty string is provided for `configroot`, the default root is used.
|
||||
func Path(configroot, extension string) (string, error) {
|
||||
if len(configroot) == 0 {
|
||||
dir, err := GetDefaultPathRoot()
|
||||
return dir+"/config", err
|
||||
dir, err := PathRoot()
|
||||
return filepath.Join(dir, extension), err
|
||||
} else {
|
||||
return configroot+"/config", nil
|
||||
return filepath.Join(configroot, extension), nil
|
||||
}
|
||||
}
|
||||
|
||||
// DataStorePath returns the default data store path given a configuration root
|
||||
// (set an empty string to have the default configuration root)
|
||||
func DataStorePath(configroot string) (string, error) {
|
||||
return Path(configroot, DefaultDataStoreDirectory);
|
||||
}
|
||||
|
||||
// Filename returns the configuration file path given a configuration root
|
||||
// directory. If the configuration root directory is empty, use the default one
|
||||
func Filename(configroot string) (string, error) {
|
||||
return Path(configroot, DefaultConfigFile);
|
||||
}
|
||||
|
||||
// DecodePrivateKey is a helper to decode the users PrivateKey
|
||||
func (i *Identity) DecodePrivateKey(passphrase string) (crypto.PrivateKey, error) {
|
||||
pkb, err := base64.StdEncoding.DecodeString(i.PrivKey)
|
||||
|
Reference in New Issue
Block a user