github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/service/test_handler.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package service 5 6 import ( 7 "github.com/keybase/client/go/libkb" 8 keybase1 "github.com/keybase/client/go/protocol/keybase1" 9 airdrop "github.com/keybase/client/go/stellar/airdrop" 10 "github.com/keybase/go-framed-msgpack-rpc/rpc" 11 "golang.org/x/net/context" 12 ) 13 14 type TestHandler struct { 15 *BaseHandler 16 libkb.Contextified 17 } 18 19 func NewTestHandler(xp rpc.Transporter, g *libkb.GlobalContext) *TestHandler { 20 return &TestHandler{ 21 BaseHandler: NewBaseHandler(g, xp), 22 Contextified: libkb.NewContextified(g), 23 } 24 } 25 26 func (t TestHandler) Test(ctx context.Context, arg keybase1.TestArg) (test keybase1.Test, err error) { 27 client := t.rpcClient() 28 cbArg := keybase1.TestCallbackArg(arg) 29 var cbReply string 30 err = client.Call(ctx, "keybase.1.test.testCallback", []interface{}{cbArg}, &cbReply, 0) 31 if err != nil { 32 return 33 } 34 35 test.Reply = cbReply 36 return 37 } 38 39 func (t TestHandler) TestCallback(_ context.Context, arg keybase1.TestCallbackArg) (s string, err error) { 40 return 41 } 42 43 func (t TestHandler) Panic(_ context.Context, message string) error { 44 t.G().Log.Info("Received panic() RPC") 45 go func() { 46 panic(message) 47 }() 48 return nil 49 } 50 51 func (t TestHandler) TestAirdropReg(ctx context.Context) error { 52 mctx := libkb.NewMetaContext(ctx, t.G()).WithLogTag("ADREG") 53 cli := airdrop.NewClient() 54 return cli.Register(mctx) 55 } 56 57 func (t TestHandler) Echo(ctx context.Context, arg keybase1.Generic) (keybase1.Generic, error) { 58 return arg, nil 59 }