我的 JSON 看起来像这样:
{
"a": [
[
"12.58861425",
10.52046452
],
[
"12.58861426",
4.1073
]
]
"b": [
[
"12.58861425",
10.52046452
],
[
"12.58861426",
4.1073
]
]
"c": "true"
"d": 1234
}
Run Code Online (Sandbox Code Playgroud)
我想将其解组到我创建的结构中:
type OrderBook struct {
A [][2]float32 `json:"a"`
B [][2]float32 `json:"b"`
C string `json:"c"`
D uint32 `json:"d"`
}
//Note this won't work because the JSON array contains a string and a float value pair rather than only floats.Run Code Online (Sandbox Code Playgroud)
通常我会将此 JSON 转换为 Golang 中的结构,如下所示:
orders := new(OrderBook)
err = json.Unmarshal(JSON, …Run Code Online (Sandbox Code Playgroud)我正在提取长十六进制字符串形式的数据,我需要将其转换为十进制表示法,截断18位小数,然后以JSON格式提供.
例如,我可能有十六进制字符串:
"0x00000000000000000000000000000000000000000000d3c21bcecceda1000000"
Run Code Online (Sandbox Code Playgroud)
起初我试图使用ParseUint(),但是因为它支持的最高int64,我的数字最终太大了.
转换和截断后的此示例导致10 ^ 6.然而,有些情况下这个数字可能高达10 ^ 12(意味着预截断10 ^ 30!).
攻击这个的最佳策略是什么?
我在 Python 的列表中有一个功能列表(所有点)。功能是动态的,源于每隔 30 分钟更新一次的数据库数据。因此,我从来没有静态数量的功能。
我需要生成一个包含列表中所有功能的功能集合。但是(据我所知)创建 FeatureCollection 的语法希望您将所有功能传递给它。
IE:
FeatureClct = FeatureCollection(feature1, feature2, feature3)
Run Code Online (Sandbox Code Playgroud)
在事先不知道有多少特征的情况下,如何生成 FeatureCollection?有没有办法将功能附加到现有的 FeatureCollection 中?
我创建了一个 Scheduler() 函数,它将按一定时间间隔执行传递的函数。
func scheduler(what func(), delay time.Duration) {
fmt.Printf("Starting scheduled process on interval %d\n", delay)
ticker := time.NewTicker(delay)
quit := make(chan bool, 1)
go func() {
for {
select {
case <- ticker.C:
what()
case <- quit:
ticker.Stop()
return
}
}
}()
<-quit
}
Run Code Online (Sandbox Code Playgroud)
安排以下 ping 功能可以完美运行。
func ping() {
fmt.Printf("Tick\n")
}
func main() {
scheduler(ping, time.Second)
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我更改 ping 以包含参数,如下所示:
func ping(msg string) {
fmt.Printf ("%s\n", msg)
}
func main() {
scheduler(ping("Hello"), time.Second)
}
Run Code Online (Sandbox Code Playgroud)
我收到编译错误:
ping("Hi") used as …Run Code Online (Sandbox Code Playgroud) 我正在尝试向以下 api 发送 GET 请求:
带 URL 参数:
货币对=BTC_ETH
深度=20
--> ¤cyPair=BTC_ETH&深度=20
我尝试按如下方式设置并执行我的请求:(请注意,为了简洁起见,我已删除了错误检查)
pair := "BTC_ETH"
depth := 20
reqURL := "https://poloniex.com/public?command=returnOrderBook"
values := url.Values { "currencyPair": []string{pair}, "depth": []string{depth}}
fmt.Printf("\n Values = %s\n", values.Encode()) //DEBUG
req, err := http.NewRequest("GET", reqURL, strings.NewReader(values.Encode()))
fmt.Printf("\nREQUEST = %+v\n", req) //DEBUG
resp, err := api.client.Do(req)
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
fmt.Printf("\nREST CALL RETURNED: %X\n",body) //DEBUG
Run Code Online (Sandbox Code Playgroud)
我的 DEBUG 打印语句打印出以下内容:
Values = currencyPair=BTC_ETH&depth=20
REQUEST = &{Method:GET URL:https://poloniex.com/public?command=returnOrderBook Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[User-Agent:[Poloniex GO API Agent]] …Run Code Online (Sandbox Code Playgroud)