Exemplo n.º 1
0
func (r *robot) initHTTP() {
	log.Println("Initializing victor's HTTP server.")
	r.http = httpserver.New()
	r.httpRouter = handlers(r)
	r.http.Handle("/", r.httpRouter)
	r.http.ListenAndServe(r.httpAddr)
}
Exemplo n.º 2
0
Arquivo: robot.go Projeto: virb/victor
// New returns a robot
func New(config Config) *robot {
	chatAdapter := config.ChatAdapter
	if chatAdapter == "" {
		chatAdapter = "shell"
	}

	chatInitFunc, err := chat.Load(config.ChatAdapter)

	if err != nil {
		log.Println(err)
		os.Exit(1)
	}

	storeAdapter := config.StoreAdapter
	if storeAdapter == "" {
		storeAdapter = "memory"
	}

	storeInitFunc, err := store.Load(storeAdapter)

	if err != nil {
		log.Println(err)
		os.Exit(1)
	}

	botName := config.Name
	if botName == "" {
		botName = "victor"
	}

	httpAddr := config.HTTPAddr
	if httpAddr == "" {
		httpAddr = ":9000"
	}

	bot := &robot{
		name:     botName,
		http:     httpserver.New(),
		httpAddr: httpAddr,
		incoming: make(chan chat.Message),
		store:    storeInitFunc(),
		stop:     make(chan struct{}),
	}

	bot.dispatch = newDispatch(bot)
	bot.chat = chatInitFunc(bot)
	bot.httpRouter = handlers(bot)

	defaults(bot)
	return bot
}