Beispiel #1
0
func main() {
	client := pusher.NewClient("4115", "23ed642e81512118260e", "cd72de5494540704dcf1", false)

	done := make(chan bool)

	go func() {
		users, err := client.Users("common")
		if err != nil {
			fmt.Printf("Error %s\n", err)
		} else {
			ids := []int{}
			for k := range users.List {
				ids = append(ids, k)
			}
			sort.Ints(ids)
			fmt.Println("User Count:", len(ids))
			fmt.Println(ids)
		}
		done <- true
	}()

	select {
	case <-done:
		fmt.Println("Done :-)")
	case <-time.After(1 * time.Minute):
		fmt.Println("Timeout :-(")
	}
}
Beispiel #2
0
func main() {
	client := pusher.NewClient("4115", "23ed642e81512118260e", "cd72de5494540704dcf1", false)

	done := make(chan bool)

	go func() {
		channels, err := client.AllChannels()
		if err != nil {
			fmt.Printf("Error %s\n", err)
		} else {
			names := []string{}
			for k := range channels.List {
				names = append(names, k)
			}
			sort.Strings(names)
			fmt.Println("Channel Count:", len(names))
			fmt.Println(names)
		}
		done <- true
	}()

	select {
	case <-done:
		fmt.Println("Done :-)")
	case <-time.After(1 * time.Minute):
		fmt.Println("Timeout :-(")
	}
}
Beispiel #3
0
func main() {
	client := pusher.NewClient("4115", "23ed642e81512118260e", "cd72de5494540704dcf1", false)

	done := make(chan bool)

	go func() {
		queryParameters := map[string]string{
			"info":             "user_count",
			"filter_by_prefix": "presence-",
		}
		channels, err := client.Channels(queryParameters)
		if err != nil {
			fmt.Printf("Error %s\n", err)
		} else {
			fmt.Println(channels)
		}
		done <- true
	}()

	select {
	case <-done:
		fmt.Println("Done :-)")
	case <-time.After(1 * time.Minute):
		fmt.Println("Timeout :-(")
	}
}
Beispiel #4
0
func SetupPusher() *pusher.Client {
	app_id := os.Getenv("PUSHER_APP_ID")
	key := os.Getenv("PUSHER_KEY")
	secret := os.Getenv("PUSHER_SECRET")

	return pusher.NewClient(app_id, key, secret)
}
Beispiel #5
0
func main() {
	var err error
	ver := false
	runtime.GOMAXPROCS(1)
	pusherC = pusher.NewClient(config.PusherAppID, config.PusherKey, config.PusherSecret)
	flag.StringVar(&dockerAddr, "docker", "unix:///var/run/docker.sock", "Set a custom endpoint for your local Docker service")
	flag.StringVar(&Env, "env", "production", "If you want to run the agent in development mode uses different ports")
	flag.BoolVar(&ver, "version", false, "Print the version")
	flag.Parse()
	if ver {
		fmt.Println(VERSION)
		os.Exit(0)
	}

	fmt.Println("Starting up Delancey with Docker at", dockerAddr)
	DockerClient, err = docker.NewClient(dockerAddr)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	err = DockerClient.PullImage(config.DockerBaseImage+":latest", nil)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	currentContainer, _ = LoadContainer()

	go logClient.Info("agent starting", map[string]interface{}{
		"version": VERSION,
		"arch":    runtime.GOARCH,
		"os":      runtime.GOOS,
		"ip":      agentHost,
	})

	port := config.DelanceyProdPort
	if Env == "development" {
		port = config.DelanceyDevPort
	}

	server := web.NewServer(":"+port, []web.Handler{
		new(web.SlashHandler),
	}, Routes)
	server.AuthHandler = &web.AuthHandler{Auth: web.DefaultAuthHandler}

	err = server.ListenAndServe()
	if err != nil {
		go logClient.Error(err.Error(), map[string]interface{}{
			"ip": agentHost,
		})
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
Beispiel #6
0
func NewPusher(key string, secret string, appId string) (Pusher, error) {
	if key == "" {
		return nil, fmt.Errorf("pusher key was empty")
	}

	if secret == "" {
		return nil, fmt.Errorf("pusher secret was empty")
	}

	if appId == "" {
		return nil, fmt.Errorf("pusher app id was empty")
	}

	client := pusher.NewClient(appId, key, secret)

	return &LivePusher{client}, nil
}
Beispiel #7
0
func main() {
	client := pusher.NewClient("34420", "87bdfd3a6320e83b9289", "f25dfe88fb26ebf75139", false)

	done := make(chan bool)

	go func() {
		err := client.Publish("test", "test", "test")
		if err != nil {
			fmt.Printf("Error %s\n", err)
		} else {
			fmt.Println("Message Published!")
		}
		done <- true
	}()

	select {
	case <-done:
		fmt.Println("Done :-)")
	case <-time.After(1 * time.Minute):
		fmt.Println("Timeout :-(")
	}
}
Beispiel #8
0
func main() {
	workers := 100
	messageCount := 5000
	messages := make(chan string)
	done := make(chan bool)

	client := pusher.NewClient("34420", "87bdfd3a6320e83b9289", "f25dfe88fb26ebf75139", false)

	for i := 0; i < workers; i++ {
		go func() {
			for data := range messages {
				err := client.Publish(data, "test", "test")
				if err != nil {
					fmt.Printf("E", err)
				} else {
					fmt.Print(".")
				}
			}
		}()
	}

	go func() {
		for i := 0; i < messageCount; i++ {
			messages <- "test"
		}
		done <- true
		close(messages)
		close(done)
	}()

	select {
	case <-done:
		fmt.Println("\nDone :-)")
	case <-time.After(1 * time.Minute):
		fmt.Println("\nTimeout :-(")
	}

	fmt.Println("")
}
Beispiel #9
0
func main() {
	client := pusher.NewClient("4115", "23ed642e81512118260e", "cd72de5494540704dcf1", false)

	done := make(chan bool)

	go func() {
		channel, err := client.Channel("common", nil)
		if err != nil {
			fmt.Printf("Error %s\n", err)
		} else {
			fmt.Println(channel)
		}
		done <- true
	}()

	select {
	case <-done:
		fmt.Println("Done :-)")
	case <-time.After(1 * time.Minute):
		fmt.Println("Timeout :-(")
	}
}