45 lines
952 B
Go
45 lines
952 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"expvar"
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"time"
|
|
|
|
"tulpa.dev/cadey/iconia/agent"
|
|
)
|
|
|
|
var (
|
|
agentURL = flag.String("agent-url", "iconia://127.0.0.1:3045/test.local.cetacean.club", "url of iconia server")
|
|
agentToken = flag.String("agent-token", "95FD1C09-47E0-438E-B1AA-40CF41E1CD01", "token to use for iconia")
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
hitCounter := expvar.NewInt("hits")
|
|
|
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
http.Error(w, "Hello world!", http.StatusOK)
|
|
hitCounter.Add(1)
|
|
})
|
|
|
|
http.HandleFunc("/messages", func(w http.ResponseWriter, r *http.Request) {
|
|
f := w.(http.Flusher)
|
|
|
|
for range make([]struct{}, 50) {
|
|
fmt.Fprintln(w, time.Now().Format(time.RFC3339))
|
|
f.Flush()
|
|
time.Sleep(time.Second)
|
|
}
|
|
})
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
log.Fatal(agent.Handle(ctx, *agentURL, *agentToken, http.DefaultServeMux))
|
|
}
|