本文整理匯總了Golang中github.com/KiiPlatform/gateway-agent/internal/common.CloudAddress.IDString方法的典型用法代碼示例。如果您正苦於以下問題:Golang CloudAddress.IDString方法的具體用法?Golang CloudAddress.IDString怎麽用?Golang CloudAddress.IDString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/KiiPlatform/gateway-agent/internal/common.CloudAddress
的用法示例。
在下文中一共展示了CloudAddress.IDString方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FindByCloudAddress
// FindByCloudAddress returns an item which matches with cloud address.
func (db *DB) FindByCloudAddress(c common.CloudAddress) (common.MapItem, error) {
n, ok := db.cloudIndex[c.IDString()]
if !ok {
return common.MapItem{}, common.ErrUnknownEndnode
}
return db.items[n], nil
}
示例2: RegisterEndnode
// RegisterEndnode registers cloud address for a end-node.
func (m *Mapper) RegisterEndnode(ea common.EndnodeAddress, ca common.CloudAddress) error {
item, err := m.Store.UpdateCloud(ea, ca)
if err != nil {
return err
}
m.Log.Printf("mapped: endnodeID=%s cloudID=%s\n", ea.IDString(), ca.IDString())
return m.Cloud.SendState(*item.CloudAddress, item.States)
}
示例3: GetEndnodeToken
// GetEndnodeToken returns a stored token for the endnode.
func (db *DB) GetEndnodeToken(a common.CloudAddress) (common.Token, error) {
db.lock.Lock()
defer db.lock.Unlock()
t, ok := db.endnodeTokens[a.IDString()]
if !ok {
return common.Token{}, common.ErrTokenNotFound
}
return t, nil
}
示例4: GetEndnodeToken
// GetEndnodeToken returns a stored token for the endnode.
func (m *DB) GetEndnodeToken(a common.CloudAddress) (common.Token, error) {
var t common.Token
err := m.db.View(func(tx *bolt.Tx) (err error) {
t, err = m.getToken(tx, a.IDString())
return err
})
if err != nil {
return common.Token{}, err
}
return t, nil
}
示例5: UpdateCloud
// UpdateCloud updates CloudAddress field of a end-node.
func (db *DB) UpdateCloud(ea common.EndnodeAddress, caddr common.CloudAddress) (common.MapItem, error) {
db.lock.Lock()
defer db.lock.Unlock()
n, ok := db.endnodeIndex[ea.IDString()]
if !ok {
return common.MapItem{}, common.ErrUnknownEndnode
}
db.items[n].CloudAddress = &caddr
db.cloudIndex[caddr.IDString()] = n
db.dumpTable()
return db.items[n], nil
}
示例6: testUpdateCloud
func testUpdateCloud(t *testing.T, s mapper.Store, ea common.EndnodeAddress, ca common.CloudAddress) common.MapItem {
m, err := s.UpdateCloud(ea, ca)
if err != nil {
t.Fatal("UpdateCloud failed:", err)
}
if m.EndnodeAddress == nil || m.EndnodeAddress.IDString() != ea.IDString() {
t.Fatalf("UpdateCloud modified EndnodeAddress: %#v", m.EndnodeAddress)
}
if m.CloudAddress == nil || m.CloudAddress.IDString() != ca.IDString() {
t.Fatalf("UpdateCloud returned unexpected CloudAddress: %#v",
m.CloudAddress)
}
return m
}
示例7: FindByCloudAddress
// FindByCloudAddress returns an item which matches with cloud address.
func (m *DB) FindByCloudAddress(c common.CloudAddress) (common.MapItem, error) {
var item common.MapItem
err := m.db.View(func(tx *bolt.Tx) (err error) {
ck := []byte(c.IDString())
cloud := tx.Bucket([]byte(boltCloudBucket))
k := cloud.Get(ck)
if k == nil {
return common.ErrUnknownEndnode
}
item, err = m.getMapItem(tx, cloud.Get(ck))
return err
})
if err != nil {
return common.MapItem{}, err
}
return item, nil
}
示例8: UpdateEndnode
// UpdateEndnode update EndnodeAddress for existing endnode
func (db *DB) UpdateEndnode(newEA common.EndnodeAddress, caddr common.CloudAddress) (common.MapItem, error) {
db.lock.Lock()
defer db.lock.Unlock()
// retrieve mapItem by cloudAddress
item, err := db.FindByCloudAddress(caddr)
if err != nil {
return common.MapItem{}, err
}
n := db.cloudIndex[caddr.IDString()]
// update endnodeIndex
delete(db.endnodeIndex, item.EndnodeAddress.IDString())
db.endnodeIndex[newEA.IDString()] = n
// update mapitem
db.items[n].EndnodeAddress = &newEA
db.dumpTable()
return db.items[n], nil
}
示例9: PutEndnodeToken
// PutEndnodeToken puts a token as endnode's token.
func (db *DB) PutEndnodeToken(a common.CloudAddress, t common.Token) error {
db.lock.Lock()
defer db.lock.Unlock()
db.endnodeTokens[a.IDString()] = t
return nil
}
示例10: PutEndnodeToken
// PutEndnodeToken puts a token as endnode's token.
func (m *DB) PutEndnodeToken(a common.CloudAddress, t common.Token) error {
err := m.db.Update(func(tx *bolt.Tx) (err error) {
return m.putToken(tx, a.IDString(), t)
})
return err
}