一些看似奇怪的代码

golang 23-02-17 02:56 682  

1. [github.com/jumpjumpbean/go-activiti-rest](https://github.com/jumpjumpbean/go-activiti-rest/blob/master/client.go#L101) ```go // NewRequest constructs a request // Convert payload to a JSON func (c *ActClient) NewRequest(method, url string, payload interface{}) (*http.Request, error) { var buf io.Reader if payload != nil { var b []byte b, err := json.Marshal(&payload) if err != nil { return nil, err } buf = bytes.NewBuffer(b) } return http.NewRequest(method, url, buf) } ``` > 此处`json.Marshal(&payload)`个人认为不需要&取地址符号 经过查阅资料得到一个说法,`只不过指针更快,且能节省内存空间` 2. [github.com/Leizhenpeng/feishu-chatGpt](https://github.com/Leizhenpeng/feishu-chatGpt/blob/master/code/services/gpt3.go#L79) ```go if response.StatusCode/2 != 100 { return "", fmt.Errorf("gtp api %s", response.Status) } ``` > 除2xx外均认为是失败,巧妙使用int除法特性找齐2xx状态码

23-08-03 20:34

哈哈哈哈

23-05-29 21:14

测试2

23-05-29 21:14

测试1

23-05-15 22:13

432