Ejemplo n.º 1
0
// This is a minimal commandline client to connect through a websocket
func main() {
	guble.LogLevel = guble.LEVEL_ERR

	args = loadArgs()
	if args.LogInfo {
		guble.LogLevel = guble.LEVEL_INFO
	}
	if args.LogDebug {
		guble.LogLevel = guble.LEVEL_DEBUG
	}

	origin := "http://localhost/"
	url := fmt.Sprintf("%v/user/%v", removeTrailingSlash(args.Url), args.User)
	client, err := client.Open(url, origin, 100, true)
	if err != nil {
		log.Fatal(err)
	}

	go writeLoop(client)
	go readLoop(client)

	for _, cmd := range args.Commands {
		client.WriteRawMessage([]byte(cmd))
	}
	if args.Exit {
		return
	}
	waitForTermination(func() {})
}
Ejemplo n.º 2
0
// This is a minimal commandline client to connect through a websocket
func main() {
	kingpin.Parse()

	// set log level
	level, err := log.ParseLevel(*logLevel)
	if err != nil {
		logger.WithField("error", err).Fatal("Invalid log level")
	}
	log.SetLevel(level)

	origin := "http://localhost/"
	url := fmt.Sprintf("%v/user/%v", removeTrailingSlash(*url), *user)
	client, err := client.Open(url, origin, 100, true)
	if err != nil {
		log.Fatal(err)
	}

	go writeLoop(client)
	go readLoop(client)

	for _, cmd := range *commands {
		client.WriteRawMessage([]byte(cmd))
	}
	if *exit {
		return
	}
	waitForTermination(func() {})
}