本文整理汇总了Golang中github.com/KiiPlatform/gateway-agent/internal/common.App类的典型用法代码示例。如果您正苦于以下问题:Golang App类的具体用法?Golang App怎么用?Golang App使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了App类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestOnboardEndnodeAppMapper_wrongPassword
func TestOnboardEndnodeAppMapper_wrongPassword(t *testing.T) {
mapper := newMapper()
defer mapper.clear()
app := common.App{
AppID: "app67890",
AppKey: "app0987654321abcdefghijklmn",
ServerLocation: "jp",
}
mapper.StateTable = &state.Table{
Gateway: state.DoneOnboard,
Apps: map[common.LocalID]state.State{
common.LocalID(app.LocalID()): state.DoneOnboard,
},
}
mapper.cloud.err4OnboardEndnodeApp = common.ErrWrongPassword
id, err := mapper.OnboardEndnodeApp(app)
if err == nil {
t.Fatal("should fail")
}
if id != "" {
t.Fatal("id should be empty")
}
if err.Error() != "wrong password of gateway" {
t.Fatal("fail with unexpected error", err)
}
}
开发者ID:KiiPlatform,项目名称:gateway-agent,代码行数:26,代码来源:mapper_test.go
示例2: TestOnboardEndnodeAppMapper_restoringGateway
func TestOnboardEndnodeAppMapper_restoringGateway(t *testing.T) {
mapper := newMapper()
defer mapper.clear()
app := common.App{
AppID: "app67890",
AppKey: "app0987654321abcdefghijklmn",
ServerLocation: "jp",
}
restoreStates := []state.State{state.WaitingRestore, state.Restoring}
for _, s := range restoreStates {
mapper.StateTable = &state.Table{
Gateway: s,
Apps: map[common.LocalID]state.State{
common.LocalID(app.LocalID()): state.WaitingRestore,
},
RestoreMode: true,
}
id, err := mapper.OnboardEndnodeApp(app)
if err == nil {
t.Fatal("should fail")
}
if id != "" {
t.Fatal("id should be empty")
}
if err.Error() != "state isn't expected one of WAITING_RESTORE nor RESTORING but actual: UNKNONWD_STATE" {
t.Fatal("fail with unexpected error", err)
}
}
}
开发者ID:KiiPlatform,项目名称:gateway-agent,代码行数:30,代码来源:mapper_test.go
示例3: TestOnboardEndnodeAppMapper_gatewayNotReady
func TestOnboardEndnodeAppMapper_gatewayNotReady(t *testing.T) {
mapper := newMapper()
defer mapper.clear()
app := common.App{
AppID: "app67890",
AppKey: "app0987654321abcdefghijklmn",
ServerLocation: "jp",
}
mapper.StateTable = &state.Table{
Gateway: state.Onboarding,
Apps: map[common.LocalID]state.State{
common.LocalID(app.LocalID()): state.DoneOnboard,
},
}
id, err := mapper.OnboardEndnodeApp(app)
if err == nil {
t.Fatal("should fail")
}
if id != "" {
t.Fatal("id should be empty")
}
if err.Error() != "state is expected one of DONE_ONBOARD but actual: UNKNONWD_STATE" {
t.Fatal("fail with unexpected error", err)
}
}
开发者ID:KiiPlatform,项目名称:gateway-agent,代码行数:25,代码来源:mapper_test.go
示例4: mqttDisconnect
func (cg *Gateway) mqttDisconnect(app common.App) error {
cg.mqttConnectLock.Lock()
defer cg.mqttConnectLock.Unlock()
localID := app.LocalID()
c, ok := cg.mqttClients[localID]
if !ok {
return fmt.Errorf("MQTT connection not found for: %s", localID)
}
c.disconnect(false)
return nil
}
开发者ID:KiiPlatform,项目名称:gateway-agent,代码行数:11,代码来源:mqtt.go
示例5: mqttConnect
func (cg *Gateway) mqttConnect(app common.App, info common.MQTTInfo) (*mqttConn, error) {
cg.mqttConnectLock.Lock()
defer cg.mqttConnectLock.Unlock()
localID := app.LocalID()
_, ok := cg.mqttClients[localID]
if ok {
return nil, fmt.Errorf("MQTT already connected: %s", app.AppID)
}
c := &mqttConn{
app: app,
Info: info,
}
if err := c.connect(cg); err != nil {
cg.mqttLogConnectError(err)
return nil, err
}
if err := c.subscribe(); err != nil {
cg.mqttLogConnectError(err)
return nil, err
}
c.autoReconn = true
cg.mqttClients[localID] = c
return c, nil
}
开发者ID:KiiPlatform,项目名称:gateway-agent,代码行数:24,代码来源:mqtt.go
示例6: DisconnectMQTTClient
// DisconnectMQTTClient disconnect mqtt connection with specified app
func (cg *Gateway) DisconnectMQTTClient(app common.App) error {
cg.mqttConnectLock.Lock()
defer cg.mqttConnectLock.Unlock()
if c, ok := cg.mqttClients[app.LocalID()]; ok {
c.disconnect(true)
delete(cg.mqttClients, app.LocalID())
return nil
}
return errors.New("not mqtt connection for App(" + app.LocalID() + ") not found")
}
开发者ID:KiiPlatform,项目名称:gateway-agent,代码行数:11,代码来源:mqtt.go
示例7: OnboardEndnodeApp
// OnboardEndnodeApp onboards the Gateway for the Endnode App
func (m *Mapper) OnboardEndnodeApp(app common.App) (string, error) {
if app.ServerLocation == m.Config.MasterApp.Site && app.AppID == m.Config.MasterApp.AppID {
return m.OnboardGatewayApp()
}
// verify state first
if m.StateTable.RestoreMode {
return "", state.ErrRestoringGateway
}
// if gateway state is not DoneOnboard, then resturn err
if err := m.StateTable.CheckGatewayState(state.DoneOnboard); err != nil {
return "", state.ErrGatewayAppGatewayNotReady
}
if err := m.StateTable.CheckAppState(common.LocalID(app.LocalID()), state.Onboarding); err == nil {
return "", state.ErrOnboarding
}
// change state of endnode app to onboarding before onboard
if err := m.StateTable.ChangeAppState(state.Onboarding, common.LocalID(app.LocalID())); err != nil {
return "", err
}
handleErr := func(err error) (string, error) {
m.StateTable.ChangeAppState(state.WaitingOnboard, common.LocalID(app.LocalID()))
return "", err
}
gwID, err := m.onboardGateway(app, true)
if err != nil {
return handleErr(err)
}
// change state of endnode app to DoneOnboard after onboard
if err := m.StateTable.ChangeAppState(state.DoneOnboard, common.LocalID(app.LocalID())); err != nil {
return handleErr(err)
}
return gwID, nil
}
开发者ID:KiiPlatform,项目名称:gateway-agent,代码行数:39,代码来源:mapper.go
示例8: TestOnboardEndnodeAppMapper_basic
// test OnboardEndnodeApp
func TestOnboardEndnodeAppMapper_basic(t *testing.T) {
mapper := newMapper()
defer mapper.clear()
app := common.App{
AppID: "app67890",
AppKey: "app0987654321abcdefghijklmn",
ServerLocation: "jp",
}
mapper.StateTable = &state.Table{
Gateway: state.DoneOnboard,
Apps: map[common.LocalID]state.State{
common.LocalID(app.LocalID()): state.WaitingOnboard,
},
}
id, err := mapper.OnboardEndnodeApp(app)
if err != nil {
t.Fatal("TestOnboardEndnodeAppMapper_basic failed", err)
}
if id != "th.0001endnode" {
t.Error("ThingID should be \"th.0001endnode\":", id)
}
if mapper.store.appID != "app67890" {
t.Error("AppID should be \"app67890\":", mapper.store.appID)
}
if mapper.cloud.app.AppID != "app67890" {
t.Error("AppID should be \"app67890\":", mapper.cloud.app.AppID)
}
if mapper.cloud.app.AppKey != "app0987654321abcdefghijklmn" {
t.Error("AppKey should be \"app0987654321abcdefghijklmn\":", mapper.cloud.app.AppKey)
}
if mapper.cloud.app.ServerLocation != "jp" {
t.Error("ServerLocation should be \"jp\":", mapper.cloud.app.ServerLocation)
}
if mapper.cloud.called4SaveEndnodeApp != true {
t.Error("endnode app should be saved on gateway app")
}
if mapper.StateTable.Apps[common.LocalID(app.LocalID())] != state.DoneOnboard {
t.Fatal("endnode app should be DoneOnboard", mapper.StateTable.Apps[common.LocalID(app.LocalID())])
}
}
开发者ID:KiiPlatform,项目名称:gateway-agent,代码行数:42,代码来源:mapper_test.go
注:本文中的github.com/KiiPlatform/gateway-agent/internal/common.App类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论