package main

import (
	"context"
	"log"
	"os"
	"os/signal"
	"syscall"

	"github.com/coder/websocket"
)

func main() {
	ctx, can := signal.NotifyContext(context.Background(), syscall.SIGINT)
	defer can()

	c, _, err := websocket.Dial(ctx, os.Args[1], &websocket.DialOptions{
		HTTPHeader: map[string][]string{
			"Cookie": []string{"uuid=x"},
		},
	})
	if err != nil {
		panic(err)
	}
	defer c.CloseNow()

	for {
		mt, b, err := c.Read(ctx)
		if err != nil {
			log.Println(err)
			return
		}
		log.Printf("[%s] %s", mt, b)
	}
}
