本文整理匯總了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
}
示例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)
}
示例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)
}
示例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)
}
示例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
}
示例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)
}
}
示例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})
}
示例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)
}
示例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
}
示例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)
}
示例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)
}
示例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
}
示例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
}
示例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)
}
示例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
}