本文整理汇总了Golang中bytes.Map函数的典型用法代码### 示例。如果您正苦于以下问题:Golang Map函数的具体用法?Golang Map怎么用?Golang Map使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。
在下文中一共展示了Map函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: run
func (h *hub) run(st *store) {
h.db = db
for {
select {
case c := <-h.register:
Log("Registering...\n")
h.connections[c] = true
c.stcmd = st.cmd
case c := <-h.unregister:
if _, ok := h.connections[c]; ok {
Log("UnRegistering...\n")
delete(h.connections, c)
close(c.cmd)
}
case m := <-h.broadcast:
Log("Broadcasting...\n")
m = bytes.Map(func(r rune) rune {
if r < ' ' {
return -1
}
return r
}, m)
for c := range h.connections {
c.cmd <- m
}
}
}
}
开发者ID:jrconlin,项目名称:awfy,代码行数:28,代码来源:awfy_server.go
示例2: BenchmarkReadString
func BenchmarkReadString(b *testing.B) {
b.StopTimer()
c := new(Context)
rand.Seed(time.Now().UnixNano())
max := 64
length := 64
strings := make([]*bytes.Buffer, max)
for i := 0; i < max; i++ {
w := new(bytes.Buffer)
s := bytes.Repeat([]byte{'a'}, length)
b := bytes.Map(randRune, s)
w.Write([]byte{ettString})
binary.Write(w, binary.BigEndian, uint16(len(b)))
w.Write(b)
strings[i] = w
}
b.StartTimer()
for i := 0; i < b.N; i++ {
in := strings[i%max]
_, err := c.Read(in)
if err != io.EOF && err != nil {
b.Fatal(err)
}
}
}
开发者ID:agelin,项目名称:etf,代码行数:30,代码来源:read_b_test.go
示例3: BenchmarkReadPid
func BenchmarkReadPid(b *testing.B) {
b.StopTimer()
c := new(Context)
rand.Seed(time.Now().UnixNano())
max := 64
length := 16
pids := make([]*bytes.Buffer, max)
for i := 0; i < max; i++ {
w := new(bytes.Buffer)
s := bytes.Repeat([]byte{'a'}, length)
b := bytes.Map(randRune, s)
b[6] = '@'
w.Write([]byte{ettPid, ettSmallAtom, byte(length)})
w.Write(b)
w.Write([]byte{0, 0, 0, uint8(rand.Int())})
w.Write([]byte{0, 0, 0, uint8(rand.Int())})
w.Write([]byte{uint8(rand.Int())})
pids[i] = w
}
b.StartTimer()
for i := 0; i < b.N; i++ {
in := pids[i%max]
_, err := c.Read(in)
if err != io.EOF && err != nil {
b.Fatal(err)
}
}
}
开发者ID:agelin,项目名称:etf,代码行数:33,代码来源:read_b_test.go
示例4: BenchmarkWriteBinary
func BenchmarkWriteBinary(b *testing.B) {
b.StopTimer()
c := new(Context)
rand.Seed(time.Now().UnixNano())
max := 64
length := 64
binaries := make([][]byte, max)
for i := 0; i < max; i++ {
s := bytes.Repeat([]byte{'a'}, length)
binaries[i] = bytes.Map(
func(rune) rune { return rune(byte(rand.Int())) },
s,
)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
in := binaries[i%max]
if err := c.writeBinary(Discard, in); err != nil {
b.Fatal(in, err)
}
}
}
开发者ID:agelin,项目名称:etf,代码行数:26,代码来源:write_b_test.go
示例5: APIRequest
func APIRequest(api string, values url.Values) ([]byte, error) {
query := values.Encode()
if query != "" {
query = "?" + query
}
url := api + query
response, err := http.Get(url)
if err != nil {
return []byte{}, err
}
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return []byte{}, err
}
res := bytes.Map(func(r rune) rune {
switch r {
case '\r', '\n':
return -1
default:
return r
}
}, body)
return res, nil
}
开发者ID:ichyo,项目名称:go-aoj,代码行数:28,代码来源:util.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng