fix import/varname conflict
This commit is contained in:
parent
2baee4a066
commit
9fa18b8736
|
@ -3,14 +3,14 @@ package driver
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.xdrm.io/go/aicra/err"
|
e "git.xdrm.io/go/aicra/err"
|
||||||
"git.xdrm.io/go/aicra/response"
|
"git.xdrm.io/go/aicra/response"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Load implements the Driver interface
|
// Load implements the Driver interface
|
||||||
func (d *Generic) Load(_path []string, _method string) (func(response.Arguments) response.Response, err.Error) {
|
func (d *Generic) Load(_path []string, _method string) (func(response.Arguments) response.Response, e.Error) {
|
||||||
|
|
||||||
/* (1) Build controller path */
|
/* (1) Build controller path */
|
||||||
path := strings.Join(_path, "-")
|
path := strings.Join(_path, "-")
|
||||||
|
@ -29,42 +29,42 @@ func (d *Generic) Load(_path []string, _method string) (func(response.Arguments)
|
||||||
|
|
||||||
/* (1) Prepare stdin data */
|
/* (1) Prepare stdin data */
|
||||||
d["_HTTP_METHOD_"] = method
|
d["_HTTP_METHOD_"] = method
|
||||||
stdin, err2 := json.Marshal(d)
|
stdin, err := json.Marshal(d)
|
||||||
if err2 != nil {
|
if err != nil {
|
||||||
res.Err = err.UncallableController
|
res.Err = e.UncallableController
|
||||||
return *res
|
return *res
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (2) Try to load command with <stdin> -> stdout */
|
/* (2) Try to load command with <stdin> -> stdout */
|
||||||
cmd := exec.Command(path, string(stdin))
|
cmd := exec.Command(path, string(stdin))
|
||||||
|
|
||||||
stdout, err2 := cmd.Output()
|
stdout, err := cmd.Output()
|
||||||
if err2 != nil {
|
if err != nil {
|
||||||
res.Err = err.UncallableController
|
res.Err = e.UncallableController
|
||||||
return *res
|
return *res
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (3) Get output json */
|
/* (3) Get output json */
|
||||||
var outputI interface{}
|
var outputI interface{}
|
||||||
err2 = json.Unmarshal(stdout, &outputI)
|
err = json.Unmarshal(stdout, &outputI)
|
||||||
if err2 != nil {
|
if err != nil {
|
||||||
res.Err = err.UncallableController
|
res.Err = e.UncallableController
|
||||||
return *res
|
return *res
|
||||||
}
|
}
|
||||||
|
|
||||||
output, ok := outputI.(map[string]interface{})
|
output, ok := outputI.(map[string]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
res.Err = err.UncallableController
|
res.Err = e.UncallableController
|
||||||
return *res
|
return *res
|
||||||
}
|
}
|
||||||
|
|
||||||
res.Err = err.Success
|
res.Err = e.Success
|
||||||
|
|
||||||
// extract error (success by default or on error)
|
// extract error (success by default or on error)
|
||||||
if outErr, ok := output["error"]; ok {
|
if outErr, ok := output["error"]; ok {
|
||||||
errCode, ok := outErr.(float64)
|
errCode, ok := outErr.(float64)
|
||||||
if ok {
|
if ok {
|
||||||
res.Err = err.Error{int(errCode), "unknown reason", nil}
|
res.Err = e.Error{int(errCode), "unknown reason", nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(output, "error")
|
delete(output, "error")
|
||||||
|
@ -77,5 +77,5 @@ func (d *Generic) Load(_path []string, _method string) (func(response.Arguments)
|
||||||
|
|
||||||
return *res
|
return *res
|
||||||
|
|
||||||
}, err.Success
|
}, e.Success
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue