本文整理匯總了Golang中github.com/nyxtom/broadcast/server.ProtocolClient.WriteString方法的典型用法代碼示例。如果您正苦於以下問題:Golang ProtocolClient.WriteString方法的具體用法?Golang ProtocolClient.WriteString怎麽用?Golang ProtocolClient.WriteString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/nyxtom/broadcast/server.ProtocolClient
的用法示例。
在下文中一共展示了ProtocolClient.WriteString方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: SInter
func (stats *StatsBackend) SInter(data interface{}, client server.ProtocolClient) error {
d, _ := data.([][]byte)
if len(d) < 2 {
client.WriteError(errors.New("SINTER takes at least 2 parameters (SINTER key [key ...])"))
client.Flush()
return nil
} else {
keys := make([]string, len(d))
for i, v := range d {
keys[i] = string(v)
}
results, err := stats.mem.SInter(keys)
if err != nil {
return err
}
if results == nil {
client.WriteNull()
client.Flush()
return nil
}
client.WriteLen('*', len(results))
for k, _ := range results {
client.WriteString(k)
}
client.Flush()
return nil
}
}
示例2: SMembers
func (stats *StatsBackend) SMembers(data interface{}, client server.ProtocolClient) error {
d, _ := data.([][]byte)
if len(d) == 0 {
client.WriteError(errors.New("SMEMBERS takes 1 parameter (SMEMBERS key)"))
client.Flush()
return nil
} else {
values, err := stats.mem.SMembers(string(d[0]))
if err != nil {
return err
}
if values == nil {
client.WriteNull()
client.Flush()
return nil
}
client.WriteLen('*', len(values))
for k, _ := range values {
client.WriteString(k)
}
client.Flush()
return nil
}
}
示例3: SDiff
func (stats *StatsBackend) SDiff(data interface{}, client server.ProtocolClient) error {
d, _ := data.([][]byte)
if len(d) < 2 {
client.WriteError(errors.New("SDIFF requires at least 2 parameters (SDIFF key [key ...])"))
client.Flush()
return nil
} else {
results, err := stats.mem.SMembers(string(d[0]))
if err != nil {
return err
} else if results == nil {
client.WriteNull()
client.Flush()
return nil
} else {
for _, v := range d[1:] {
results, err = stats.mem.SDiff(results, string(v))
if err != nil {
return err
} else if len(results) == 0 {
break
}
}
client.WriteLen('*', len(results))
for k, _ := range results {
client.WriteString(k)
}
client.Flush()
return nil
}
}
}
示例4: SaveFile
func (t *TermBackend) SaveFile(data interface{}, client server.ProtocolClient) error {
d, _ := data.([][]byte)
if len(d) >= 2 {
fileName := string(d[0])
content := d[1]
err := ioutil.WriteFile(fileName, content, 0644)
if err != nil {
client.WriteError(err)
client.Flush()
} else {
client.WriteString("saved " + fileName + " successfully")
client.Flush()
}
} else {
client.WriteError(errors.New("save takes at least 2 parameters (save filename filecontents...)"))
client.Flush()
}
return nil
}
示例5: RunClient
func (p *RedisProtocol) RunClient(client server.ProtocolClient) {
// defer panics to the loggable event routine
defer func() {
if e := recover(); e != nil {
buf := make([]byte, 4096)
n := runtime.Stack(buf, false)
buf = buf[0:n]
p.ctx.Events <- server.BroadcastEvent{"fatal", "client run panic", errors.New(fmt.Sprintf("%v", e)), buf}
}
client.Close()
return
}()
reqErr := client.RequestErrorChan()
for {
data, err := client.ReadBulkPayload()
if err != nil {
if err != io.EOF {
p.ctx.Events <- server.BroadcastEvent{"error", "read error", err, nil}
}
return
}
err = p.handleData(data, client, reqErr)
if err != nil {
if err == errQuit {
client.WriteString("OK")
client.Flush()
return
} else {
p.ctx.Events <- server.BroadcastEvent{"error", "accept error", err, nil}
client.WriteError(err)
client.Flush()
}
}
}
}
示例6: Keys
func (stats *StatsBackend) Keys(data interface{}, client server.ProtocolClient) error {
d, _ := data.([][]byte)
key := ""
if len(d) > 0 {
pattern, err := stats.readString(d[0])
if err != nil {
return err
}
key = pattern
}
results, err := stats.mem.Keys(key)
if err != nil {
client.WriteError(err)
client.Flush()
return nil
}
client.WriteLen('*', len(results))
for _, k := range results {
client.WriteString(k)
}
client.Flush()
return nil
}
示例7: echo
func (b *DefaultBackend) echo(data interface{}, client server.ProtocolClient) error {
d, okInterface := data.([]interface{})
if okInterface {
if len(d) == 0 {
client.WriteString("")
client.Flush()
return nil
} else {
if len(d) == 1 {
fmt.Printf("%v", d[0])
client.WriteInterface(d[0])
} else {
client.WriteArray(d)
}
client.Flush()
return nil
}
} else {
b, _ := data.([][]byte)
if len(b) == 0 {
client.WriteString("")
client.Flush()
return nil
} else {
if len(b) == 1 {
client.WriteString(string(b[0]))
} else {
s := make([]string, len(b))
for i, k := range b {
s[i] = string(k)
}
client.WriteString(strings.Join(s, " "))
}
client.Flush()
return nil
}
}
}
示例8: ping
func (b *DefaultBackend) ping(data interface{}, client server.ProtocolClient) error {
client.WriteString(PONG)
client.Flush()
return nil
}