當前位置: 首頁>>代碼示例>>Golang>>正文


Golang server.ProtocolClient類代碼示例

本文整理匯總了Golang中github.com/nyxtom/broadcast/server.ProtocolClient的典型用法代碼示例。如果您正苦於以下問題:Golang ProtocolClient類的具體用法?Golang ProtocolClient怎麽用?Golang ProtocolClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ProtocolClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: subscribe

// subscribe will add the given protocol client to the channel to subscribe to
func (b *PubSubBackend) subscribe(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) < 1 {
		return nil
	} else {
		for _, k := range d {
			key := string(k)
			if topic, ok := b.topics[key]; ok {
				topic.Lock()
				id := client.Address()
				if _, ok = topic.clients[id]; !ok {
					topic.clients[id] = empty
					topic.size++
				}
				topic.Unlock()
			} else {
				topic := new(TopicChannel)
				topic.clients = make(map[string]struct{})
				topic.size = 1
				topic.clients[client.Address()] = empty
				b.topics[key] = topic
			}
		}

		return nil
	}
}
開發者ID:nyxtom,項目名稱:broadcast,代碼行數:28,代碼來源:pubsub_backend.go

示例2: Count

func (stats *StatsBackend) Count(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) == 0 {
		client.WriteError(errors.New("COUNTER takes at least 1 parameter (i.e. key to increment)"))
		client.Flush()
		return nil
	} else {
		key, err := stats.readString(d[0])
		if err != nil {
			return err
		}
		values := d[1:]
		if len(values) > 0 {
			value, err := stats.readInt64(values[0])
			if err != nil {
				return err
			}
			_, err = stats.mem.CounterBy(key, value)
			return err
		} else {
			_, err := stats.mem.Counter(key)
			return err
		}
	}
}
開發者ID:nyxtom,項目名稱:broadcast,代碼行數:25,代碼來源:metrics.go

示例3: SRem

func (stats *StatsBackend) SRem(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	key := ""
	if len(d) < 2 {
		client.WriteError(errors.New("SREM takes at least 2 parameters (SREM key member)"))
		client.Flush()
		return nil
	} else {
		key = string(d[0])
		members := d[1:]
		result := int64(0)
		for _, v := range members {
			r, err := stats.mem.SRem(key, string(v))
			if err != nil {
				return err
			} else if r == -1 {
				return stats.FlushInt(r, nil, client)
			} else {
				result += r
			}
		}

		return stats.FlushInt(result, nil, client)
	}
}
開發者ID:nyxtom,項目名稱:broadcast,代碼行數:25,代碼來源:metrics.go

示例4: FlushInt

func (stats *StatsBackend) FlushInt(i int64, err error, client server.ProtocolClient) error {
	if err != nil {
		return err
	}
	client.WriteInt64(i)
	client.Flush()
	return nil
}
開發者ID:nyxtom,項目名稱:broadcast,代碼行數:8,代碼來源:metrics.go

示例5: Exists

func (stats *StatsBackend) Exists(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) == 0 {
		client.WriteError(errors.New("EXISTS takes at least 1 parameter (i.e. key to find)"))
		client.Flush()
		return nil
	} else {
		key, err := stats.readString(d[0])
		if err != nil {
			return err
		}
		i, err := stats.mem.Exists(key)
		return stats.FlushInt(i, err, client)
	}
}
開發者ID:nyxtom,項目名稱:broadcast,代碼行數:15,代碼來源:metrics.go

示例6: Set

func (stats *StatsBackend) Set(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) < 2 {
		client.WriteError(errors.New("SET takes at least 2 parameters (i.e. key to set and value to set to)"))
		client.Flush()
		return nil
	} else {
		key, value, err := stats.readStringInt64(d)
		if err != nil {
			return err
		}
		i, err := stats.mem.Set(key, value)
		return stats.FlushInt(i, err, client)
	}
}
開發者ID:nyxtom,項目名稱:broadcast,代碼行數:15,代碼來源:metrics.go

示例7: Get

func (stats *StatsBackend) Get(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) == 0 {
		client.WriteError(errors.New("GET takes at least 1 parameter (i.e. key to get)"))
		client.Flush()
		return nil
	} else {
		key, err := stats.readString(d[0])
		if err != nil {
			return err
		}
		i, err := stats.mem.Get(key)
		if err == ErrNotFound {
			return stats.FlushNil(client)
		}
		return stats.FlushInt(i, err, client)
	}
}
開發者ID:nyxtom,項目名稱:broadcast,代碼行數:18,代碼來源:metrics.go

示例8: CatFile

func (t *TermBackend) CatFile(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) > 0 {
		fileName := string(d[0])
		content, err := ioutil.ReadFile(path.Join(t.homeDir, fileName))
		if err != nil {
			client.WriteError(err)
		} else {
			client.WriteBytes(content)
		}
		client.Flush()
	} else {
		client.WriteError(errors.New("cat takes at least 1 parameter (cat filename)"))
		client.Flush()
	}

	return nil
}
開發者ID:supertigim,項目名稱:webterm,代碼行數:18,代碼來源:term_backend.go

示例9: Counters

func (stats *StatsBackend) Counters(data interface{}, client server.ProtocolClient) error {
	results, err := stats.mem.Counters()
	if err != nil {
		client.WriteError(err)
		client.Flush()
		return nil
	}

	client.WriteJson(results)
	client.Flush()
	return nil
}
開發者ID:nyxtom,項目名稱:broadcast,代碼行數:12,代碼來源:metrics.go

示例10: unsubscribe

func (b *PubSubBackend) unsubscribe(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) < 1 {
		return nil
	} else {
		for _, k := range d {
			key := string(k)
			if topic, ok := b.topics[key]; ok {
				topic.Lock()
				id := client.Address()
				if _, ok = topic.clients[id]; ok {
					delete(topic.clients, id)
					topic.size--
				}
				topic.Unlock()
			}
		}

		return nil
	}
}
開發者ID:nyxtom,項目名稱:broadcast,代碼行數:21,代碼來源:pubsub_backend.go

示例11: Del

func (stats *StatsBackend) Del(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) == 0 {
		client.WriteError(errors.New("DEL takes at least 1 parameter (i.e. key to delete)"))
		client.Flush()
		return nil
	} else {
		i := int64(0)
		for _, k := range d {
			key, err := stats.readString(k)
			if err != nil {
				return err
			}
			i2, err := stats.mem.Del(key)
			if err != nil {
				return err
			} else {
				i += i2
			}
		}
		return stats.FlushInt(i, nil, client)
	}
}
開發者ID:nyxtom,項目名稱:broadcast,代碼行數:23,代碼來源:metrics.go

示例12: 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
}
開發者ID:nyxtom,項目名稱:broadcast,代碼行數:24,代碼來源:metrics.go

示例13: SUnion

func (stats *StatsBackend) SUnion(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) < 2 {
		client.WriteError(errors.New("SUNION 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.SUnion(keys)
		if err != nil {
			return err
		}

		client.WriteLen('*', len(results))
		for k, _ := range results {
			client.WriteString(k)
		}
		client.Flush()
		return nil
	}
}
開發者ID:nyxtom,項目名稱:broadcast,代碼行數:24,代碼來源:metrics.go

示例14: ListFiles

func (t *TermBackend) ListFiles(data interface{}, client server.ProtocolClient) error {
	files, err := ioutil.ReadDir(t.homeDir)

	filenames := []interface{}{}
	if err != nil {
		client.WriteError(err)
		client.Flush()
	} else {
		for _, f := range files {
			if !f.IsDir() {
				filenames = append(filenames, f.Name())
			}
		}
		client.WriteArray(filenames)
		client.Flush()
	}
	return nil
}
開發者ID:supertigim,項目名稱:webterm,代碼行數:18,代碼來源:term_backend.go

示例15: EditFile

func (t *TermBackend) EditFile(data interface{}, client server.ProtocolClient) error {
	d, _ := data.([][]byte)
	if len(d) > 0 {
		fileName := string(d[0])
		content, err := ioutil.ReadFile(path.Join(t.homeDir, fileName))
		if err == nil {
			fileMap := make(map[string]string)
			fileMap["filename"] = fileName
			fileMap["contents"] = string(content)
			client.WriteJson(fileMap)
			client.Flush()
		} else {
			fileMap := make(map[string]string)
			fileMap["filename"] = fileName
			fileMap["contents"] = ""
			client.WriteJson(fileMap)
			client.Flush()
		}
	}

	return nil
}
開發者ID:supertigim,項目名稱:webterm,代碼行數:22,代碼來源:term_backend.go


注:本文中的github.com/nyxtom/broadcast/server.ProtocolClient類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。