tangled
alpha
login
or
join now
moth11.net
/
lrcdaemon
0
fork
atom
just a runnable instance of lrcd
0
fork
atom
overview
issues
pulls
pipelines
upgrade to lrcd v0.1.0, render message count
moth11.net
5 months ago
ff21a3eb
5c0e3e3f
+26
-13
3 changed files
expand all
collapse all
unified
split
go.mod
go.sum
main.go
+4
-3
go.mod
···
2
2
3
3
go 1.24.2
4
4
5
5
+
require github.com/rachel-mp4/lrcd v0.1.0
6
6
+
5
7
require (
6
8
github.com/gorilla/websocket v1.5.3 // indirect
7
7
-
github.com/rachel-mp4/lrcd v0.0.1 // indirect
8
8
-
github.com/rachel-mp4/lrcproto v0.0.0-20250905151943-8e3a1989ea5a // indirect
9
9
-
google.golang.org/protobuf v1.36.6 // indirect
9
9
+
github.com/rachel-mp4/lrcproto v1.2.0 // indirect
10
10
+
google.golang.org/protobuf v1.36.10 // indirect
10
11
)
+8
-6
go.sum
···
1
1
+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
2
2
+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
1
3
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
2
4
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
3
3
-
github.com/rachel-mp4/lrcd v0.0.1 h1:9d5if0HJ/+TLKdupd7Zu9dISA5fF3QRtI/yr+gYVqXM=
4
4
-
github.com/rachel-mp4/lrcd v0.0.1/go.mod h1:aWUVglSyrLf2RGpQdqTucX498b434yWBFJkD6Yzr0OE=
5
5
-
github.com/rachel-mp4/lrcproto v0.0.0-20250905151943-8e3a1989ea5a h1:W3zPeGz/jHYyWj8ZfsuA9yigPMNlA/h7Fu+SQKgiBmQ=
6
6
-
github.com/rachel-mp4/lrcproto v0.0.0-20250905151943-8e3a1989ea5a/go.mod h1:hQzO36tQELGbkmRnUtKeM6NMU34t79ZcTlhM+MO7pHw=
7
7
-
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
8
8
-
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
5
5
+
github.com/rachel-mp4/lrcd v0.1.0 h1:iW3ux8otqo+9tYpP2Bsxu5VgbhP324Mjy0vOBf3M39Q=
6
6
+
github.com/rachel-mp4/lrcd v0.1.0/go.mod h1:CyBPWmy94oQ0sTOj24VJjxWoZ9zSnqCKQ/qlR+vhtVE=
7
7
+
github.com/rachel-mp4/lrcproto v1.2.0 h1:nZI80WQKO6yKgX0O5H6OO1cM/tiJqugs0p52KCoIDOw=
8
8
+
github.com/rachel-mp4/lrcproto v1.2.0/go.mod h1:hQzO36tQELGbkmRnUtKeM6NMU34t79ZcTlhM+MO7pHw=
9
9
+
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
10
10
+
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
+14
-4
main.go
···
9
9
)
10
10
11
11
func main() {
12
12
-
server, err := lrcd.NewServer(lrcd.WithLogging(os.Stdout, false), lrcd.WithWelcome("welcome to the beginning of the rest of your life"))
12
12
+
messages := 0
13
13
+
pubchan := make(chan lrcd.PubEvent)
14
14
+
go incrementMessageCount(pubchan, &messages)
15
15
+
server, err := lrcd.NewServer(lrcd.WithLogging(os.Stdout, false), lrcd.WithWelcome("welcome to the beginning of the rest of your life"), lrcd.WithPubChannel(pubchan))
13
16
if err != nil {
14
17
panic(err)
15
18
}
···
19
22
}
20
23
fmt.Println("serving lrcd on localhost:8080")
21
24
now := time.Now()
22
22
-
http.ListenAndServe(":8080", guessIfUpgradeFail(server, now))
25
25
+
http.ListenAndServe(":8080", guessIfUpgradeFail(server, now, &messages))
23
26
}
24
27
25
25
-
func guessIfUpgradeFail(server *lrcd.Server, now time.Time) http.HandlerFunc {
28
28
+
func incrementMessageCount(pubchan chan lrcd.PubEvent, messages *int) {
29
29
+
for range pubchan {
30
30
+
*messages = *messages + 1
31
31
+
}
32
32
+
}
33
33
+
34
34
+
func guessIfUpgradeFail(server *lrcd.Server, now time.Time, messages *int) http.HandlerFunc {
26
35
return func(w http.ResponseWriter, r *http.Request) {
27
36
if r.Header.Get("Upgrade") != "websocket" {
28
37
fmt.Fprintf(w, `~ live ~~ hi! i am an lrc server!
···
33
42
it'll be more fun for us both! (tangled.org/moth11.net/ttyxcvr)
34
43
35
44
currently connected: %d
36
36
-
live since: %s`, server.Connected(), now.Format(time.RubyDate))
45
45
+
live since: %s
46
46
+
message count: %d`, server.Connected(), now.Format(time.RubyDate), *messages)
37
47
} else {
38
48
server.WSHandler()(w, r)
39
49
}