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


Golang id.Valid函數代碼示例

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


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

示例1: Drop

// Drop removes a channel ID associated with the given device ID from
// memcached. Deregistration calls should call s.Unregister() instead.
// Implements Store.Drop().
func (s *EmceeStore) Drop(uaid, chid string) (err error) {
	if len(uaid) == 0 {
		return ErrNoID
	}
	if len(chid) == 0 {
		return ErrNoChannel
	}
	if !id.Valid(uaid) {
		return ErrInvalidID
	}
	if !id.Valid(chid) {
		return ErrInvalidChannel
	}
	client, err := s.getClient()
	if err != nil {
		return err
	}
	defer s.releaseWithout(client, &err)
	key, ok := s.IDsToKey(uaid, chid)
	if !ok {
		return ErrInvalidKey
	}
	if err = client.Delete(key, 0); err == nil || isMissing(err) {
		return nil
	}
	return err
}
開發者ID:shihuacai1989,項目名稱:pushgo,代碼行數:30,代碼來源:emcee_store.go

示例2: Register

// Register creates and stores a channel record for the given device ID and
// channel ID. If version > 0, the record will be marked as active. Implements
// Store.Register().
func (s *GomemcStore) Register(uaid, chid string, version int64) (err error) {
	if len(uaid) == 0 {
		return ErrNoID
	}
	if len(chid) == 0 {
		return ErrNoChannel
	}
	if !id.Valid(uaid) {
		return ErrInvalidID
	}
	if !id.Valid(chid) {
		return ErrInvalidChannel
	}
	return s.storeRegister(uaid, chid, version)
}
開發者ID:jrconlin,項目名稱:pushgo,代碼行數:18,代碼來源:gomemc_store.go

示例3: Unregister

// Unregister marks the channel ID associated with the given device ID
// as inactive. Implements Store.Unregister().
func (s *GomemcStore) Unregister(uaid, chid string) (err error) {
	if len(uaid) == 0 {
		return ErrNoID
	}
	if len(chid) == 0 {
		return ErrNoChannel
	}
	if !id.Valid(uaid) {
		return ErrInvalidID
	}
	if !id.Valid(chid) {
		return ErrInvalidChannel
	}
	return s.storeUnregister(uaid, chid)
}
開發者ID:jrconlin,項目名稱:pushgo,代碼行數:17,代碼來源:gomemc_store.go

示例4: Update

// Update updates the version for the given device ID and channel ID.
// Implements Store.Update().
func (s *GomemcStore) Update(uaid, chid string, version int64) (err error) {
	if len(uaid) == 0 {
		return ErrNoID
	}
	if len(chid) == 0 {
		return ErrNoChannel
	}
	// Normalize the device and channel IDs.
	if !id.Valid(uaid) {
		return ErrInvalidID
	}
	if !id.Valid(chid) {
		return ErrInvalidChannel
	}
	return s.storeUpdate(uaid, chid, version)
}
開發者ID:jrconlin,項目名稱:pushgo,代碼行數:18,代碼來源:gomemc_store.go

示例5: DropAll

// DropAll removes all channel records for the given device ID. Implements
// Store.DropAll().
func (s *EmceeStore) DropAll(uaid string) error {
	if !id.Valid(uaid) {
		return ErrInvalidID
	}
	chids, err := s.fetchAppIDArray(uaid)
	if err != nil && !isMissing(err) {
		return err
	}
	client, err := s.getClient()
	if err != nil {
		return err
	}
	defer s.releaseWithout(client, &err)
	for _, chid := range chids {
		key, ok := s.IDsToKey(uaid, chid)
		if !ok {
			return ErrInvalidKey
		}
		client.Delete(key, 0)
	}
	if err = client.Delete(uaid, 0); err != nil && !isMissing(err) {
		return err
	}
	return nil
}
開發者ID:shihuacai1989,項目名稱:pushgo,代碼行數:27,代碼來源:emcee_store.go

示例6: TestNilDeviceId

func TestNilDeviceId(t *testing.T) {
	origin, err := testServer.Origin()
	if err != nil {
		t.Fatalf("Error initializing test server: %#v", err)
	}
	conn, err := client.DialOrigin(origin)
	if err != nil {
		t.Fatalf("Error dialing origin: %#v", err)
	}
	defer conn.Close()
	defer conn.Purge()
	request := CustomHelo{
		MessageType: "hello",
		DeviceId:    NilId,
		ChannelIds:  []interface{}{},
		Extra:       "extra field",
		replies:     make(chan client.Reply),
		errors:      make(chan error),
	}
	reply, err := conn.WriteRequest(request)
	if err != nil {
		t.Fatalf("Error writing handshake request: %#v", err)
	}
	helo, ok := reply.(client.ServerHelo)
	if !ok {
		t.Errorf("Type assertion failed for handshake reply: %#v", reply)
	}
	if !id.Valid(helo.DeviceId) {
		t.Errorf("Got invalid device ID: %#v", helo.DeviceId)
	}
}
開發者ID:jrconlin,項目名稱:pushgo,代碼行數:31,代碼來源:api_smoke_test.go

示例7: PutPing

// PutPing stores the proprietary ping info blob for the given device ID in
// memcached. Implements Store.PutPing().
func (s *GomemcStore) PutPing(uaid string, pingData []byte) error {
	if !id.Valid(uaid) {
		return ErrInvalidID
	}
	return s.client.Set(&mc.Item{
		Key:        s.PingPrefix + uaid,
		Value:      pingData,
		Expiration: 0})
}
開發者ID:jrconlin,項目名稱:pushgo,代碼行數:11,代碼來源:gomemc_store.go

示例8: DropPing

// DropPing removes all proprietary ping info for the given device ID.
// Implements Store.DropPing().
func (s *GomemcStore) DropPing(uaid string) error {
	if len(uaid) == 0 {
		return ErrNoID
	}
	if !id.Valid(uaid) {
		return ErrInvalidID
	}
	return s.client.Delete(s.PingPrefix + uaid)
}
開發者ID:jrconlin,項目名稱:pushgo,代碼行數:11,代碼來源:gomemc_store.go

示例9: Drop

// Drop removes a channel ID associated with the given device ID from
// memcached. Deregistration calls should call s.Unregister() instead.
// Implements Store.Drop().
func (s *GomemcStore) Drop(uaid, chid string) (err error) {
	if len(uaid) == 0 {
		return ErrNoID
	}
	if len(chid) == 0 {
		return ErrNoChannel
	}
	if !id.Valid(uaid) {
		return ErrInvalidID
	}
	if !id.Valid(chid) {
		return ErrInvalidChannel
	}
	key := joinIDs(uaid, chid)
	if err = s.client.Delete(key); err != nil && err != mc.ErrCacheMiss {
		return err
	}
	return nil
}
開發者ID:jrconlin,項目名稱:pushgo,代碼行數:22,代碼來源:gomemc_store.go

示例10: PutPing

// PutPing stores the proprietary ping info blob for the given device ID in
// memcached. Implements Store.PutPing().
func (s *EmceeStore) PutPing(uaid string, pingData []byte) (err error) {
	if !id.Valid(uaid) {
		return ErrInvalidID
	}
	client, err := s.getClient()
	defer s.releaseWithout(client, &err)
	if err != nil {
		return err
	}
	return client.Set(s.PingPrefix+uaid, pingData, 0)
}
開發者ID:jrconlin,項目名稱:pushgo,代碼行數:13,代碼來源:emcee_store.go

示例11: Update

// Update updates the version for the given device ID and channel ID.
// Implements Store.Update().
func (s *EmceeStore) Update(key string, version int64) (err error) {
	uaid, chid, ok := s.KeyToIDs(key)
	if !ok {
		return ErrInvalidKey
	}
	if len(uaid) == 0 {
		return ErrNoID
	}
	if len(chid) == 0 {
		return ErrNoChannel
	}
	// Normalize the device and channel IDs.
	if !id.Valid(uaid) {
		return ErrInvalidID
	}
	if !id.Valid(chid) {
		return ErrInvalidChannel
	}
	return s.storeUpdate(uaid, chid, version)
}
開發者ID:shihuacai1989,項目名稱:pushgo,代碼行數:22,代碼來源:emcee_store.go

示例12: Run

func (t typeTest) Run() error {
	origin, err := testServer.Origin()
	if err != nil {
		return fmt.Errorf("On test %v, error initializing test server: %#v", t.name, err)
	}
	conn, err := client.DialOrigin(origin)
	if err != nil {
		return fmt.Errorf("On test %v, error dialing origin: %#v", t.name, err)
	}
	defer conn.Close()
	defer conn.Purge()
	request := CustomHelo{
		MessageType: t.messageType,
		DeviceId:    t.deviceId,
		ChannelIds:  []interface{}{"1", "2"},
		Extra:       "custom value",
		replies:     make(chan client.Reply),
		errors:      make(chan error),
	}
	reply, err := conn.WriteRequest(request)
	if t.statusCode >= 200 && t.statusCode < 300 {
		if err != nil {
			return fmt.Errorf("On test %v, error writing handshake request: %#v", t.name, err)
		}
		helo, ok := reply.(client.ServerHelo)
		if !ok {
			return fmt.Errorf("On test %v, type assertion failed for handshake reply: %#v", t.name, reply)
		}
		if helo.StatusCode != t.statusCode {
			return fmt.Errorf("On test %v, unexpected reply status: got %#v; want %#v", t.name, helo.StatusCode, t.statusCode)
		}
		deviceId, _ := t.deviceId.(string)
		if len(deviceId) == 0 && !id.Valid(helo.DeviceId) {
			return fmt.Errorf("On test %v, got invalid device ID: %#v", t.name, helo.DeviceId)
		} else if !t.shouldReset && deviceId != helo.DeviceId {
			return fmt.Errorf("On test %v, mismatched device ID: got %#v; want %#v", t.name, helo.DeviceId, deviceId)
		} else if t.shouldReset && deviceId == helo.DeviceId {
			return fmt.Errorf("On test %v, want new device ID; got %#v", t.name, deviceId)
		}
		return nil
	}
	if err != io.EOF {
		return fmt.Errorf("On test %v, error writing handshake: got %#v; want io.EOF", t.name, err)
	}
	err = conn.Close()
	clientErr, ok := err.(client.Error)
	if !ok {
		return fmt.Errorf("On test %v, type assertion failed for close error: %#v", t.name, err)
	}
	if clientErr.Status() != t.statusCode {
		return fmt.Errorf("On test %v, unexpected close error status: got %#v; want %#v", t.name, clientErr.Status(), t.statusCode)
	}
	return nil
}
開發者ID:jrconlin,項目名稱:pushgo,代碼行數:54,代碼來源:api_smoke_test.go

示例13: FetchPing

// FetchPing retrieves proprietary ping information for the given device ID
// from memcached. Implements Store.FetchPing().
func (s *GomemcStore) FetchPing(uaid string) (pingData []byte, err error) {
	if len(uaid) == 0 {
		return nil, ErrNoID
	}
	if !id.Valid(uaid) {
		return nil, ErrInvalidID
	}
	raw, err := s.client.Get(s.PingPrefix + uaid)
	if err != nil {
		return nil, err
	}
	return raw.Value, nil
}
開發者ID:jrconlin,項目名稱:pushgo,代碼行數:15,代碼來源:gomemc_store.go

示例14: DropPing

// DropPing removes all proprietary ping info for the given device ID.
// Implements Store.DropPing().
func (s *EmceeStore) DropPing(uaid string) (err error) {
	if len(uaid) == 0 {
		return ErrNoID
	}
	if !id.Valid(uaid) {
		return ErrInvalidID
	}
	client, err := s.getClient()
	defer s.releaseWithout(client, &err)
	if err != nil {
		return err
	}
	return client.Delete(s.PingPrefix+uaid, 0)
}
開發者ID:jrconlin,項目名稱:pushgo,代碼行數:16,代碼來源:emcee_store.go

示例15: FetchPing

// FetchPing retrieves proprietary ping information for the given device ID
// from memcached. Implements Store.FetchPing().
func (s *EmceeStore) FetchPing(uaid string) (pingData []byte, err error) {
	if len(uaid) == 0 {
		return nil, ErrNoID
	}
	if !id.Valid(uaid) {
		return nil, ErrInvalidID
	}
	client, err := s.getClient()
	defer s.releaseWithout(client, &err)
	if err != nil {
		return
	}
	err = client.Get(s.PingPrefix+uaid, &pingData)
	return
}
開發者ID:jrconlin,項目名稱:pushgo,代碼行數:17,代碼來源:emcee_store.go


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