提交 d6a808791a8b9687899c9dead818b8e4ae405f6a

作者 yuyang
1 个父辈 34631c44

update

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