本文整理汇总了Golang中github.com/keybase/client/go/protocol.NotifyCtlClient类的典型用法代码示例。如果您正苦于以下问题:Golang NotifyCtlClient类的具体用法?Golang NotifyCtlClient怎么用?Golang NotifyCtlClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NotifyCtlClient类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: OnConnect
// OnConnect implements the ConnectionHandler interface.
func (k *KeybaseDaemonRPC) OnConnect(ctx context.Context,
conn *rpc.Connection, rawClient rpc.GenericClient,
server *rpc.Server) error {
protocols := []rpc.Protocol{
keybase1.LogUiProtocol(daemonLogUI{k.daemonLog}),
keybase1.IdentifyUiProtocol(daemonIdentifyUI{k.daemonLog}),
keybase1.NotifySessionProtocol(k),
keybase1.NotifyUsersProtocol(k),
}
for _, p := range protocols {
err := server.Register(p)
if err != nil {
if _, ok := err.(rpc.AlreadyRegisteredError); !ok {
return err
}
}
}
// Using conn.GetClient() here would cause problematic
// recursion.
c := keybase1.NotifyCtlClient{Cli: rawClient}
err := c.SetNotifications(ctx, keybase1.NotificationChannels{
Session: true,
Users: true,
})
if err != nil {
return err
}
// Introduce ourselves. TODO: move this to SharedKeybaseConnection
// somehow?
configClient := keybase1.ConfigClient{Cli: rawClient}
err = configClient.HelloIAm(ctx, keybase1.ClientDetails{
Pid: os.Getpid(),
ClientType: keybase1.ClientType_KBFS,
Argv: os.Args,
Version: VersionString(),
})
if err != nil {
return err
}
return nil
}
开发者ID:keybase,项目名称:kbfs-beta,代码行数:45,代码来源:keybase_daemon_rpc.go
示例2: TestTrackingNotifications
func TestTrackingNotifications(t *testing.T) {
tc := setupTest(t, "signup")
tc2 := cloneContext(tc)
tc5 := cloneContext(tc)
libkb.G.LocalDb = nil
// Hack the various portions of the service that aren't
// properly contextified.
defer tc.Cleanup()
stopCh := make(chan error)
svc := service.NewService(tc.G, false)
startCh := svc.GetStartChannel()
go func() {
err := svc.Run()
if err != nil {
t.Logf("Running the service produced an error: %v", err)
}
stopCh <- err
}()
userInfo := randomUser("sgnup")
tui := trackingUI{
signupUI: signupUI{
info: userInfo,
Contextified: libkb.NewContextified(tc2.G),
},
}
tc2.G.SetUI(&tui)
signup := client.NewCmdSignupRunner(tc2.G)
signup.SetTest()
<-startCh
if err := signup.Run(); err != nil {
t.Fatal(err)
}
tc2.G.Log.Debug("Login State: %v", tc2.G.LoginState())
nh := newTrackingNotifyHandler()
// Launch the server that will listen for tracking notifications.
launchServer := func(nh *trackingNotifyHandler) error {
cli, xp, err := client.GetRPCClientWithContext(tc5.G)
if err != nil {
return err
}
srv := rpc.NewServer(xp, nil)
if err = srv.Register(keybase1.NotifyTrackingProtocol(nh)); err != nil {
return err
}
ncli := keybase1.NotifyCtlClient{Cli: cli}
if err = ncli.SetNotifications(context.TODO(), keybase1.NotificationChannels{
Tracking: true,
}); err != nil {
return err
}
return nil
}
// Actually launch it in the background
go func() {
err := launchServer(nh)
if err != nil {
nh.errCh <- err
}
}()
// Have our test user track t_alice.
trackCmd := client.NewCmdTrackRunner(tc2.G)
trackCmd.SetUser("t_alice")
trackCmd.SetOptions(keybase1.TrackOptions{BypassConfirm: true})
err := trackCmd.Run()
if err != nil {
t.Fatal(err)
}
// Do a check for new tracking statements that should fire off a
// notification. Currently the track command above does not fetch the new
// chain link from the server, so this call is required. It's possible that
// TrackEngine (or our signature caching code) might change in the future,
// making this call unnecessary.
checkTrackingCmd := client.NewCmdCheckTrackingRunner(tc2.G)
err = checkTrackingCmd.Run()
if err != nil {
t.Fatal(err)
}
// Wait to get a notification back as we expect.
// NOTE: If this test ever starts deadlocking here, it's possible that
// we've changed how we cache signatures that we make on the local client,
// in such a way that the fetch done by CheckTracking above doesn't find
// any "isOwnNewLinkFromServer" links. If so, one way to fix this test
// would be to blow away the local db before calling CheckTracking.
tc.G.Log.Debug("Waiting for two tracking notifications.")
for i := 0; i < 2; i++ {
select {
//.........这里部分代码省略.........
开发者ID:qbit,项目名称:client,代码行数:101,代码来源:tracking_test.go
示例3: TestSignupLogout
func TestSignupLogout(t *testing.T) {
tc := setupTest(t, "signup")
tc2 := cloneContext(tc)
tc5 := cloneContext(tc)
libkb.G.LocalDb = nil
// Hack the various portions of the service that aren't
// properly contextified.
defer tc.Cleanup()
stopCh := make(chan error)
svc := service.NewService(tc.G, false)
startCh := svc.GetStartChannel()
go func() {
err := svc.Run()
if err != nil {
t.Logf("Running the service produced an error: %v", err)
}
stopCh <- err
}()
userInfo := randomUser("sgnup")
sui := signupUI{
info: userInfo,
Contextified: libkb.NewContextified(tc2.G),
}
tc2.G.SetUI(&sui)
signup := client.NewCmdSignupRunner(tc2.G)
signup.SetTest()
logout := client.NewCmdLogoutRunner(tc2.G)
<-startCh
nh := newNotifyHandler()
// Launch the server that will listen for notifications on updates, such as logout
launchServer := func(nh *notifyHandler) error {
cli, xp, err := client.GetRPCClientWithContext(tc5.G)
if err != nil {
return err
}
srv := rpc.NewServer(xp, nil)
if err = srv.Register(keybase1.NotifySessionProtocol(nh)); err != nil {
return err
}
if err = srv.Register(keybase1.NotifyUsersProtocol(nh)); err != nil {
return err
}
ncli := keybase1.NotifyCtlClient{Cli: cli}
if err = ncli.SetNotifications(context.TODO(), keybase1.NotificationChannels{
Session: true,
Users: true,
}); err != nil {
return err
}
return nil
}
// Actually launch it in the background
go func() {
err := launchServer(nh)
if err != nil {
nh.errCh <- err
}
}()
if err := signup.Run(); err != nil {
t.Fatal(err)
}
tc2.G.Log.Debug("Login State: %v", tc2.G.LoginState())
select {
case err := <-nh.errCh:
t.Fatalf("Error before notify: %v", err)
case u := <-nh.loginCh:
if u != userInfo.username {
t.Fatalf("bad username in login notifcation: %q != %q", u, userInfo.username)
}
tc.G.Log.Debug("Got notification of login for %q", u)
}
btc := client.NewCmdBTCRunner(tc2.G)
btc.SetAddress("1HUCBSJeHnkhzrVKVjaVmWg2QtZS1mdfaz")
if err := btc.Run(); err != nil {
t.Fatal(err)
}
// Now let's be sure that we get a notification back as we expect.
select {
case err := <-nh.errCh:
t.Fatalf("Error before notify: %v", err)
case uid := <-nh.userCh:
tc.G.Log.Debug("Got notification from user changed handled (%s)", uid)
if e := libkb.CheckUIDAgainstUsername(uid, userInfo.username); e != nil {
t.Fatalf("Bad UID back: %s != %s (%s)", uid, userInfo.username, e)
}
}
//.........这里部分代码省略.........
开发者ID:qbit,项目名称:client,代码行数:101,代码来源:user_test.go
注:本文中的github.com/keybase/client/go/protocol.NotifyCtlClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论