正在显示
1 个修改的文件
包含
18 行增加
和
19 行删除
@@ -39,42 +39,41 @@ func main() { | @@ -39,42 +39,41 @@ func main() { | ||
39 | if key == "" || iv == "" || privateKeyPath == "" || publicKeyPath == "" || ip == "" || bussinessCode == "" || ptCode == "" || reqBody == "" || resultFilePath == "" || errFilePath == "" { | 39 | if key == "" || iv == "" || privateKeyPath == "" || publicKeyPath == "" || ip == "" || bussinessCode == "" || ptCode == "" || reqBody == "" || resultFilePath == "" || errFilePath == "" { |
40 | os.Exit(1) | 40 | os.Exit(1) |
41 | } | 41 | } |
42 | - | ||
43 | - fd, _ := os.OpenFile(errFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) | ||
44 | - defer fd.Close() | ||
45 | - | ||
46 | - publicKey, err := ioutil.ReadFile(publicKeyPath) | 42 | + var err error |
43 | + var publicKey, privateKey []byte | ||
44 | + var req string | ||
45 | + var file, fd *os.File | ||
46 | + fd, err = os.OpenFile(errFilePath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) | ||
47 | if err != nil { | 47 | if err != nil { |
48 | + os.Exit(1) | ||
49 | + } | ||
50 | + defer fd.Close() | ||
51 | + defer func() { | ||
48 | write := bufio.NewWriter(fd) | 52 | write := bufio.NewWriter(fd) |
49 | write.WriteString("命令行执行错误:" + err.Error() + "\r\n") | 53 | write.WriteString("命令行执行错误:" + err.Error() + "\r\n") |
50 | write.Flush() | 54 | write.Flush() |
55 | + }() | ||
56 | + | ||
57 | + publicKey, err = ioutil.ReadFile(publicKeyPath) | ||
58 | + if err != nil { | ||
51 | return | 59 | return |
52 | } | 60 | } |
53 | - privateKey, err := ioutil.ReadFile(privateKeyPath) | 61 | + privateKey, err = ioutil.ReadFile(privateKeyPath) |
54 | if err != nil { | 62 | if err != nil { |
55 | - write := bufio.NewWriter(fd) | ||
56 | - write.WriteString("命令行执行错误:" + err.Error() + "\r\n") | ||
57 | - write.Flush() | ||
58 | return | 63 | return |
59 | } | 64 | } |
60 | 65 | ||
61 | client := socialwork_sdk.NewOrderClient(key, iv, string(privateKey), string(publicKey), ip, ptCode) | 66 | client := socialwork_sdk.NewOrderClient(key, iv, string(privateKey), string(publicKey), ip, ptCode) |
62 | - req, err := client.SendRequest(bussinessCode, reqBody) | 67 | + req, err = client.SendRequest(bussinessCode, reqBody) |
63 | if err != nil { | 68 | if err != nil { |
64 | - write := bufio.NewWriter(fd) | ||
65 | - write.WriteString("命令行执行错误:" + err.Error() + "\r\n") | ||
66 | - write.Flush() | ||
67 | return | 69 | return |
68 | } else { | 70 | } else { |
69 | - file, err := os.Create(resultFilePath) | ||
70 | - defer file.Close() | ||
71 | - | 71 | + file, err = os.Create(resultFilePath) |
72 | if err != nil { | 72 | if err != nil { |
73 | - write := bufio.NewWriter(fd) | ||
74 | - write.WriteString("命令行执行错误:" + err.Error() + "\r\n") | ||
75 | - write.Flush() | ||
76 | return | 73 | return |
77 | } | 74 | } |
75 | + defer file.Close() | ||
76 | + | ||
78 | file.WriteString(req) | 77 | file.WriteString(req) |
79 | return | 78 | return |
80 | } | 79 | } |
请
注册
或
登录
后发表评论