示例#1
0
文件: store.go 项目: thuvh/hal
// Run returns an int so we can return a proper exit code
func Run() int {
	robot, err := hal.NewRobot()
	if err != nil {
		fmt.Println(err)
		return 1
	}

	robot.Store.Set("foo", []byte("FOO"))

	robot.Handle(
		pingHandler,
		getHandler,
		setHandler,
		deleteHandler,
		usersHandler,
	)

	// spew.Dump(robot.Users())
	// spew.Dump(hal.Adapters)
	if err := robot.Run(); err != nil {
		hal.Logger.Error(err)
		return 1
	}
	return 0
}
示例#2
0
func run() int {
	robot, err := hal.NewRobot()
	if err != nil {
		hal.Logger.Error(err)
		return 1
	}

	robot.Handle(
		fooHandler,
		tableFlipHandler,
		eventHandler,
		synHandler,
		helpHandler,
		pingHandler,
		sourceHandler,
		issueHandler,
		cageMeHandler,
		whoisHandler,
		whoamHandler,
		isHandler,
		selfHandler,
		quitHandler,
		fizzBuzzHandler,
		noteStoreHandler,
		noteGetHandler,
		noteRemoveHandler,
		chadevCountHandler,
		chadevListAllHandler,
		chadevInfoHandler,
		fatherHandler,
		partyHandler,
		whoBackHandler,
		whatAreHandler,
		musicHandler,
		lunchHandler,
		talkHandler,
		addTalkHandler,
		devTalkLinkHandler,
		isAliveHandler,
		groupListHandler,
		groupDetailsHandler,
		groupRSVPHandler,
		devlunchRSVPHandler,
		karmaHandler,
		karmaStatsHandler,
		karmaRankingHandler,
		modHandler,
	)

	if err := robot.Run(); err != nil {
		hal.Logger.Error(err)
		return 1
	}
	return 0
}
示例#3
0
文件: main.go 项目: jlambert121/hal
func run() int {
	robot, err := hal.NewRobot()
	if err != nil {
		hal.Logger.Error(err)
		return 1
	}

	// Or define them inside another function...
	fooHandler := hal.Respond(`foo`, func(res *hal.Response) error {
		return res.Send("BAR")
	})

	tableFlipHandler := &hal.BasicHandler{
		Method:  hal.HEAR,
		Pattern: `tableflip`,
		Run: func(res *hal.Response) error {
			return res.Send(`(╯°□°)╯︵ ┻━┻`)
		},
	}

	robot.Handle(
		pingHandler,
		fooHandler,
		tableFlipHandler,

		// Or stick them in an entirely different package, and reference them
		// exactly in the way you would expect.
		handler.Ping,

		// Or use a hal.BasicHandler structure complete with usage...
		&hal.BasicHandler{
			Method:  hal.RESPOND,
			Pattern: `SYN`,
			Usage:   `hal syn - replies with "ACK"`,
			Run: func(res *hal.Response) error {
				return res.Reply("ACK")
			},
		},

		// Or even inline!
		hal.Hear(`yo`, func(res *hal.Response) error {
			return res.Send("lo")
		}),
	)

	if err := robot.Run(); err != nil {
		hal.Logger.Error(err)
		return 1
	}
	return 0
}
示例#4
0
文件: main.go 项目: thuvh/hal
func run() int {
	robot, err := hal.NewRobot()
	if err != nil {
		hal.Logger.Error(err)
		return 1
	}

	robot.Handle(
		pingHandler,
		echoHandler,
	)

	if err := robot.Run(); err != nil {
		hal.Logger.Error(err)
		return 1
	}
	return 0
}
示例#5
0
文件: redis.go 项目: thuvh/hal
// Run returns an int so we can return a proper exit code
func Run() int {
	robot, err := hal.NewRobot()
	if err != nil {
		fmt.Println(err)
		return 1
	}

	robot.Handle(
		getHandler,
		setHandler,
		deleteHandler,
		usersHandler,
		userHandler,
	)

	if err := robot.Run(); err != nil {
		hal.Logger.Error(err)
		return 1
	}
	return 0
}
示例#6
0
文件: halbot.go 项目: miku/halbot
func run() int {
	log.Printf("Starting halbot %s", AppVersion)
	usr, err := user.Current()
	if err != nil {
		log.Fatal(err)
	}
	config := path.Join(usr.HomeDir, ".halrc")
	if _, err := os.Stat(config); err == nil {
		file, err := ini.LoadFile(config)
		if err != nil {
			log.Fatal(err)
		}
		for k, v := range file["solr"] {
			log.Printf("Registering %s => %s", k, v)
			indices[k] = v
		}
	}

	robot, err := hal.NewRobot()
	if err != nil {
		hal.Logger.Error(err)
		return 1
	}

	robot.Handle(
		pingHandler,
		queryHandler,
		aboutHandler,
	)

	if err := robot.Run(); err != nil {
		hal.Logger.Error(err)
		return 1
	}
	return 0
}