当我运行goroutines时,我通常得到40作为值,我知道它的并发性,但为什么最后一个数字来了?我想输出必须是:
Page number: 34
Page number: 12
Page number: 8
Page number: 2
Page number: 29
Run Code Online (Sandbox Code Playgroud)
示例源代码:
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func getWebPageContent(url string, c chan int, val int) interface{} {
if r, err := http.Get(url); err == nil {
defer r.Body.Close()
if body, err := ioutil.ReadAll(r.Body); err == nil {
c <- val
return string(body)
}
} else {
fmt.Println(err)
}
return "XoX"
}
const MAX_TH = 40
func main() {
// pln := …Run Code Online (Sandbox Code Playgroud) 整数可以是8个字节,即2 ^ 64.很多价值观.
假设我想编写一个小程序,将这样的值存储在一个文件中:
3 1 5 6 2 8 9 0 1 2 ....
在任何时候我的值都不会高于9.所以我只需要10个组合,我可以通过仅采用2 ^ 4(16种组合)的数据类型获得.不是2 ^ 64.
不会更有效率......我怎么能做到这一点.C++是否具有本机单数字类型.
我正在阅读GAE数据存储区中的行,我想按字母顺序对它们进行排序.
假设我有这样的事情:
key name description sequence
===========================================
ASD.. maths1 it is maths chap21.1
ASD.. maths2 it is maths chap21.10
ASD.. maths3 it is maths chap21.2
Run Code Online (Sandbox Code Playgroud)
我希望结果按字母顺序排序在序列字段上,如下所示:
key name description sequence
===========================================
ASD.. maths1 it is maths chap21.1
ASD.. maths3 it is maths chap21.2
ASD.. maths2 it is maths chap21.10
Run Code Online (Sandbox Code Playgroud) 我用 Go 编写了一个程序,可以查找列表中的最小数字并且它可以工作。但是,我不太明白其中的逻辑。您能解释一下它是如何工作的吗?
package main
import "fmt"
func main() {
x := []int{
48, 96, 86, 68,
57, 82, 63, 70,
37, 34, 83, 27,
19, 97, 9, 17,
}
for i, num := range x {
if num < i {
fmt.Println(num)
}
}
}
Run Code Online (Sandbox Code Playgroud)
游乐场:https://play.golang.org/p/Awuw2Th1g2V
输出:
9
Run Code Online (Sandbox Code Playgroud)
我教科书上的解决方案是不同的,我理解其中的逻辑。
我遇到了关于使用 time 包在 golang 中进行日期字符串解析的最奇怪的问题。
错误:
parsing time "07-20-2018" as "2006-01-02": cannot parse "0-2018" as "2006"
Run Code Online (Sandbox Code Playgroud)
代码块:
log.Println(datestring) //07-20-2018
date, err := time.Parse("2006-01-02", datestring)
log.Println(err) //parsing time "07-20-2018" as "2006-01-02": cannot parse "0-2018" as "2006"
log.Println(date) //parsing time "07-20-2018" as "2006-01-02": cannot parse "0-2018" as "2006"
Run Code Online (Sandbox Code Playgroud)
我完全不知道这个问题指的是什么,该字符串是用 gorilla mux 从 golang 中的 URI 解析的。
datestring, _ := vars["date"] //some/path/{date}, date is 07-20-2018
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我正在努力寻找一种方法来检查一个字符串是否包含一个或多个符号,如下所示:#}{&*"(£)虽然检查这些符号中的一个或多个是相当简单的,但我并不打算构建和维护一个列表或可能的条目字典.有没有一种方法可以检查,看是否有字符串包含一个或多个的任何最好使用标准库中去非标准符号?
具体来说,我正在寻找任何不是a-zA-Z0-9因为我的问题的基础将被视为非标准符号的东西.
我得到一个float64值43701.330694444441,在我调用strconv.ParseFloat(v, 64)函数后,结果是43701.33069444444。任何人都可以解决这个问题吗?
v := "43701.330694444441"
f, err := strconv.ParseFloat(v, 64)
if err != nil {
return
}
fmt.Println(f) // it output 43701.33069444444, the tail '1' is missing.
Run Code Online (Sandbox Code Playgroud) 我需要迭代任何指定的日期范围,例如2017-12-21至2018-01-05。在Go中实现该功能的最佳方法是什么?
output?
20171221
20171222
20171223
...
20180104
20180105
Run Code Online (Sandbox Code Playgroud) 我想检查我传递的值是否是浮点数。我有一段代码可以检查它是某个字符串还是浮点数。如果两者都不是,则给出错误。这是代码:
if sensorData.Passport.Geolocation.Latitude != "gps" && sensorData.Passport.Geolocation.Latitude != "internet" && sensorData.Passport.Geolocation.Latitude != "unknown" && sensorData.Passport.Geolocation.Latitude != //a float nmber{
fmt.Println("Incorrect option")
}
Run Code Online (Sandbox Code Playgroud)
如何检查数据是否为浮点数?
给定, stringvalue := "zzzzzzzzzzzzzzzzzzzzzz"
i, err := strconv.ParseInt(stringvalue, 36, 0)
Run Code Online (Sandbox Code Playgroud)
我如何返回 int128,因为我的字符串值足够长以返回 int128?
我有一个词包含其中一些人物 - šđžčć.当我从那个单词中取出第一个字母时,我会有一个byte,当我将其转换byte为字符串时,我会得到错误解码的字符串.有人可以帮我弄清楚如何正确解码extracter字母.这是示例代码:
package main
import (
"fmt"
)
func main() {
word := "ŠKOLA"
c := word[0]
fmt.Println(word, string(c)) // ŠKOLA Å
}
Run Code Online (Sandbox Code Playgroud)
我有以下代码:
import "github.com/kless/osutil/user/crypt/sha512_crypt"
c := sha512_crypt.New()
hash, err := c.Generate([]byte("enter-new-password"), []byte("$2a$09$f5561d2634fb28a969f2dO8QeQ70f4bjCnF/.GvPpjj.8jgmtzZP2"))
if err != nil {
panic(err)
}
Run Code Online (Sandbox Code Playgroud)
它产生了以下错误
http:恐慌服务192.168.0.16:56730:无效的魔术前缀
为什么会发生这种情况,我该如何解决?