@cryptotaxi247 / kubo / commits / 2419ffdb2

cmd/ipfs: Load config and put in request context

Matt Bell committed Oct 27, 2014 at 17:32 UTC 2419ffdb2d074e5906922072942fda12d486a51a
2 files changed +18 -8
cmd/ipfs/daemon.go
+1 -1
@@ -24,7 +24,7 @@ var Daemon = &cmds.Command{
24 }
25
26 func daemonFunc(req cmds.Request, res cmds.Response) {
27 - configPath, err := getConfigPath(req)
27 + configPath, err := getConfigRoot(req)
28 if err != nil {
29 res.SetError(err, cmds.ErrNormal)
30 return
cmd/ipfs/ipfs.go
+17 -7
@@ -67,6 +67,22 @@ func main() {
67 }
68 }
69
70 + configPath, err := getConfigRoot(options)
71 + if err != nil {
72 + fmt.Println(err)
73 + os.Exit(1)
74 + }
75 +
76 + conf, err := getConfig(configPath)
77 + if err != nil {
78 + fmt.Println(err)
79 + os.Exit(1)
80 + }
81 +
82 + ctx := req.Context()
83 + ctx.ConfigRoot = configPath
84 + ctx.Config = conf
85 +
86 var res cmds.Response
87 if root == Root {
88 res = root.Call(req)
@@ -74,12 +90,6 @@ func main() {
90 } else {
91 local := true
92
77 - configPath, err := getConfigPath(options)
78 - if err != nil {
79 - fmt.Println(err)
80 - os.Exit(1)
81 - }
82 -
93 lockFilePath, err := config.Path(configPath, DaemonLockFile)
94 if err != nil {
95 fmt.Println(err)
@@ -138,7 +148,7 @@ func getOptions(req cmds.Request, root *cmds.Command) (cmds.Request, error) {
148 return tempReq, nil
149 }
150
141 -func getConfigPath(req cmds.Request) (string, error) {
151 +func getConfigRoot(req cmds.Request) (string, error) {
152 if opt, found := req.Option("config"); found {
153 return opt.(string), nil
154 }