Created
August 13, 2018 04:13
-
-
Save nguyenvanduocit/cad44eed28ff70e3f3be5b5c945512cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (h *Handler) exec(requestBody utils.JsonIn) (*utils.JsonOut, error) { | |
cmd := exec.Command(h.Command) | |
cmd.Dir = h.WorkingDir | |
bRequestBody, err := json.Marshal(requestBody) | |
if err != nil { | |
return nil, err | |
} | |
cmd.Stdin = strings.NewReader(string(bRequestBody)) | |
var out bytes.Buffer | |
cmd.Stdout = &out | |
if err := cmd.Run(); err != nil { | |
return nil, err | |
} | |
var response utils.JsonOut | |
if err := json.Unmarshal(out.Bytes(), &response); err != nil { | |
return nil, err | |
} | |
return &response, nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "/location/geocode", | |
"endpoint": "/location/geocode", | |
"env": [ | |
"CLIENT=mapbox", | |
"MAPBOX_ACCESS_TOKEN=abc", | |
"FN_FORMAT=json", | |
"FN_TYPE=sync" | |
], | |
"working_dir": "/Users/duocnguyen/go/src/code.go1.com.au/microservices/location", | |
"command": "/usr/local/bin/go run /Users/duocnguyen/go/src/code.go1.com.au/microservices/location/geocode/func.go" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
exec.Command("/usr/local/bin/go", "run", "/Users/duocnguyen/go/src/code.go1.com.au/microservices/location/geocode/func.go")