Skip to content

Commit

Permalink
feat(bot): allow using custom daemon address
Browse files Browse the repository at this point in the history
  • Loading branch information
moul committed Sep 12, 2018
1 parent 448e55d commit b324854
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 3 additions & 2 deletions client/go/bot/examples/berty-bot-example/docker-compose.yml
Expand Up @@ -3,9 +3,9 @@ version: "3"
services:
daemon:
build: ../../../../..
command: daemon --log-level=debug
command: daemon --log-level=debug -b :6666
ports:
- 1337
- 6666
network_mode: host
bot:
build:
Expand All @@ -14,3 +14,4 @@ services:
network_mode: host
depends_on:
- daemon
command: -addr=127.0.0.1:6666
7 changes: 6 additions & 1 deletion client/go/bot/examples/berty-bot-example/main.go
@@ -1,14 +1,19 @@
package main

import (
"flag"
"log"

"berty.tech/client/go/bot"
)

var addr = flag.String("addr", "127.0.0.1:1337", "daemon gRPC address")

func main() {
flag.Parse()

b, err := bot.New(
bot.WithDefaultDaemon(),
bot.WithTCPDaemon(*addr),
bot.WithAutoAcceptInvites(),
bot.WithLogger(),
)
Expand Down
8 changes: 6 additions & 2 deletions client/go/bot/option.go
Expand Up @@ -13,16 +13,20 @@ import (

type Option func(b *Bot) error

func WithDefaultDaemon() Option {
func WithTCPDaemon(addr string) Option {
return func(b *Bot) error {
conn, err := grpc.Dial("127.0.0.1:1337", grpc.WithInsecure())
conn, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
return err
}
return WithGRPCConn(conn)(b)
}
}

func WithDefaultDaemon() Option {
return WithTCPDaemon("127.0.0.1:1337")
}

func WithGRPCConn(conn *grpc.ClientConn) Option {
return func(b *Bot) error {
b.client = client.New(conn)
Expand Down

0 comments on commit b324854

Please sign in to comment.