1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-01 02:30:39 +08:00

cmd/ipfs: Load config and put in request context

This commit is contained in:
Matt Bell
2014-10-27 17:32:19 -07:00
committed by Juan Batiz-Benet
parent 7d53e736cf
commit 2419ffdb2d
2 changed files with 18 additions and 8 deletions

View File

@ -24,7 +24,7 @@ var Daemon = &cmds.Command{
} }
func daemonFunc(req cmds.Request, res cmds.Response) { func daemonFunc(req cmds.Request, res cmds.Response) {
configPath, err := getConfigPath(req) configPath, err := getConfigRoot(req)
if err != nil { if err != nil {
res.SetError(err, cmds.ErrNormal) res.SetError(err, cmds.ErrNormal)
return return

View File

@ -67,6 +67,22 @@ func main() {
} }
} }
configPath, err := getConfigRoot(options)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
conf, err := getConfig(configPath)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
ctx := req.Context()
ctx.ConfigRoot = configPath
ctx.Config = conf
var res cmds.Response var res cmds.Response
if root == Root { if root == Root {
res = root.Call(req) res = root.Call(req)
@ -74,12 +90,6 @@ func main() {
} else { } else {
local := true local := true
configPath, err := getConfigPath(options)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
lockFilePath, err := config.Path(configPath, DaemonLockFile) lockFilePath, err := config.Path(configPath, DaemonLockFile)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@ -138,7 +148,7 @@ func getOptions(req cmds.Request, root *cmds.Command) (cmds.Request, error) {
return tempReq, nil return tempReq, nil
} }
func getConfigPath(req cmds.Request) (string, error) { func getConfigRoot(req cmds.Request) (string, error) {
if opt, found := req.Option("config"); found { if opt, found := req.Option("config"); found {
return opt.(string), nil return opt.(string), nil
} }