Change Keybase type to a pointer so it can be re-used
This commit is contained in:
@ -149,7 +149,7 @@ func createFiltersString(channels []Channel) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run `keybase chat api-listen` to get new messages coming into keybase and send them into the channel
|
// Run `keybase chat api-listen` to get new messages coming into keybase and send them into the channel
|
||||||
func getNewMessages(k Keybase, c chan<- ChatIn, execOptions []string) {
|
func getNewMessages(k *Keybase, c chan<- ChatIn, execOptions []string) {
|
||||||
execString := []string{"chat", "api-listen"}
|
execString := []string{"chat", "api-listen"}
|
||||||
if len(execOptions) > 0 {
|
if len(execOptions) > 0 {
|
||||||
execString = append(execString, execOptions...)
|
execString = append(execString, execOptions...)
|
||||||
@ -171,7 +171,7 @@ func getNewMessages(k Keybase, c chan<- ChatIn, execOptions []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run runs `keybase chat api-listen`, and passes incoming messages to the message handler func
|
// Run runs `keybase chat api-listen`, and passes incoming messages to the message handler func
|
||||||
func (k Keybase) Run(handler func(ChatIn), options ...RunOptions) {
|
func (k *Keybase) Run(handler func(ChatIn), options ...RunOptions) {
|
||||||
var heartbeatFreq int64
|
var heartbeatFreq int64
|
||||||
runOptions := make([]string, 0)
|
runOptions := make([]string, 0)
|
||||||
if len(options) > 0 {
|
if len(options) > 0 {
|
||||||
@ -190,6 +190,7 @@ func (k Keybase) Run(handler func(ChatIn), options ...RunOptions) {
|
|||||||
if len(options[0].FilterChannels) > 0 {
|
if len(options[0].FilterChannels) > 0 {
|
||||||
runOptions = append(runOptions, "--filter-channels")
|
runOptions = append(runOptions, "--filter-channels")
|
||||||
runOptions = append(runOptions, createFiltersString(options[0].FilterChannels))
|
runOptions = append(runOptions, createFiltersString(options[0].FilterChannels))
|
||||||
|
|
||||||
}
|
}
|
||||||
if options[0].FilterChannel.Name != "" {
|
if options[0].FilterChannel.Name != "" {
|
||||||
runOptions = append(runOptions, "--filter-channel")
|
runOptions = append(runOptions, "--filter-channel")
|
||||||
|
|||||||
@ -131,7 +131,7 @@ func (c Chat) Delete(messageId int) (ChatOut, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ChatList returns a list of all conversations.
|
// ChatList returns a list of all conversations.
|
||||||
func (k Keybase) ChatList() ([]conversation, error) {
|
func (k *Keybase) ChatList() ([]conversation, error) {
|
||||||
m := chatOut{}
|
m := chatOut{}
|
||||||
m.Method = "list"
|
m.Method = "list"
|
||||||
|
|
||||||
|
|||||||
14
keybase.go
14
keybase.go
@ -27,7 +27,7 @@ type Keybase struct {
|
|||||||
|
|
||||||
// Chat holds basic information about a specific conversation
|
// Chat holds basic information about a specific conversation
|
||||||
type Chat struct {
|
type Chat struct {
|
||||||
keybase Keybase
|
keybase *Keybase
|
||||||
Channel Channel
|
Channel Channel
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,8 +53,8 @@ type status struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewKeybase returns a new Keybase. Optionally, you can pass a string containing the path to the Keybase executable as the first argument.
|
// NewKeybase returns a new Keybase. Optionally, you can pass a string containing the path to the Keybase executable as the first argument.
|
||||||
func NewKeybase(path ...string) Keybase {
|
func NewKeybase(path ...string) *Keybase {
|
||||||
k := Keybase{}
|
k := &Keybase{}
|
||||||
if len(path) < 1 {
|
if len(path) < 1 {
|
||||||
k.Path = "keybase"
|
k.Path = "keybase"
|
||||||
} else {
|
} else {
|
||||||
@ -69,7 +69,7 @@ func NewKeybase(path ...string) Keybase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewChat returns a new Chat instance
|
// NewChat returns a new Chat instance
|
||||||
func (k Keybase) NewChat(channel Channel) Chat {
|
func (k *Keybase) NewChat(channel Channel) Chat {
|
||||||
return Chat{
|
return Chat{
|
||||||
keybase: k,
|
keybase: k,
|
||||||
Channel: channel,
|
Channel: channel,
|
||||||
@ -77,7 +77,7 @@ func (k Keybase) NewChat(channel Channel) Chat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// username returns the username of the currently logged-in Keybase user.
|
// username returns the username of the currently logged-in Keybase user.
|
||||||
func (k Keybase) username() string {
|
func (k *Keybase) username() string {
|
||||||
cmd := exec.Command(k.Path, "status", "-j")
|
cmd := exec.Command(k.Path, "status", "-j")
|
||||||
cmdOut, err := cmd.Output()
|
cmdOut, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -91,7 +91,7 @@ func (k Keybase) username() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// loggedIn returns true if Keybase is currently logged in, otherwise returns false.
|
// loggedIn returns true if Keybase is currently logged in, otherwise returns false.
|
||||||
func (k Keybase) loggedIn() bool {
|
func (k *Keybase) loggedIn() bool {
|
||||||
cmd := exec.Command(k.Path, "status", "-j")
|
cmd := exec.Command(k.Path, "status", "-j")
|
||||||
cmdOut, err := cmd.Output()
|
cmdOut, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -105,7 +105,7 @@ func (k Keybase) loggedIn() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// version returns the version string of the client.
|
// version returns the version string of the client.
|
||||||
func (k Keybase) version() string {
|
func (k *Keybase) version() string {
|
||||||
cmd := exec.Command(k.Path, "version", "-S", "-f", "s")
|
cmd := exec.Command(k.Path, "version", "-S", "-f", "s")
|
||||||
cmdOut, err := cmd.Output()
|
cmdOut, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -93,7 +93,7 @@ func walletAPIOut(keybasePath string, w walletOut) (walletOutResult, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TxDetail returns details of a stellar transaction
|
// TxDetail returns details of a stellar transaction
|
||||||
func (k Keybase) TxDetail(txid string) (WalletResult, error) {
|
func (k *Keybase) TxDetail(txid string) (WalletResult, error) {
|
||||||
m := walletOut{}
|
m := walletOut{}
|
||||||
m.Method = "details"
|
m.Method = "details"
|
||||||
m.Params.Options.Txid = txid
|
m.Params.Options.Txid = txid
|
||||||
@ -103,7 +103,7 @@ func (k Keybase) TxDetail(txid string) (WalletResult, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StellarAddress returns the primary stellar address of a given user
|
// StellarAddress returns the primary stellar address of a given user
|
||||||
func (k Keybase) StellarAddress(user string) (string, error) {
|
func (k *Keybase) StellarAddress(user string) (string, error) {
|
||||||
m := walletOut{}
|
m := walletOut{}
|
||||||
m.Method = "lookup"
|
m.Method = "lookup"
|
||||||
m.Params.Options.Name = user
|
m.Params.Options.Name = user
|
||||||
|
|||||||
Reference in New Issue
Block a user