我将我的java项目改为golang。我使用java注释并希望将其转换为go代码。我想知道转换此注释的最佳数据结构。
我的代码如下:
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strconv"
"time"
)
func getBody(method string, Id string, auth string, body []byte,timeStamp int64) ([]byte, error) {
url := "****************"+Id+"***********"+strconv.FormatInt(timeStamp,10)
client := &http.Client{}
req, err := http.NewRequest(method, url, bytes.NewReader(body))
if err != nil {
return nil, err
}
var header = make(map[string]string,2)
header["Accept"]="*******************"
header["Authorization"]=auth
for key, value := range header {
req.Header.Add(key, value)
}
res, err := client.Do(req)
defer res.Body.Close()
if err != nil {
return nil, err
}
var bodyBytes []byte
if res.StatusCode == 200 {
bodyBytes, err = ioutil.ReadAll(res.Body)
} else if err != nil {
return nil, err
} else {
return nil, fmt.Errorf("The remote end did not return a HTTP 200 (OK) response.")
}
return bodyBytes, nil
}
func main() {
method := "GET"
auth:="************"
var timeStamp int64 = 1441689793403
Id:="***********"
fmt.Println(timeStamp)
var cs int64 = time.Now().UnixNano()/1000000
for{
cs = time.Now().UnixNano()/1000000
bodyBytes, err := getBody(method, Id, auth, nil,timeStamp)
if err != nil {
fmt.Errorf("unable to retrieve the response body from the Glance API server: %v", err)
}
var obj []interface{}
err = json.Unmarshal(bodyBytes, &obj)
if err != nil {
fmt.Errorf("unable to parse the JSON response:", err)
}
for i,_:=range obj{
m := obj[i].(map[string]interface{})
fmt.Println(m["text"])
/* @OnKeyWord("hi")
public void HelloWorld(TeamchatAPI api) {
System.out.println("Hello word");
); */
}
timeStamp = cs
}
}
我想将注释的java代码转换为go代码。
另外,如果你愿意,你可以用你自己的例子来解释。