Skip to content

Commit 1cfcb37

Browse files
committed
2025-08-19 10:12:54
1 parent 4db16a2 commit 1cfcb37

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

protocol/etch/engine.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package etch
2+
3+
import (
4+
"io"
5+
"log"
6+
"net"
7+
"net/http"
8+
)
9+
10+
// Server implemented the etch protocol.
11+
type Server struct {
12+
Closer io.Closer
13+
Listen string
14+
}
15+
16+
// ServeHTTP implements http.Handler.
17+
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
18+
log.Println(w)
19+
log.Println(r)
20+
}
21+
22+
// Close listener.
23+
func (s *Server) Close() error {
24+
if s.Closer != nil {
25+
return s.Closer.Close()
26+
}
27+
return nil
28+
}
29+
30+
// Run it.
31+
func (s *Server) Run() error {
32+
l, err := net.Listen("tcp", s.Listen)
33+
if err != nil {
34+
return err
35+
}
36+
log.Println("main: listen and serve on", s.Listen)
37+
srv := &http.Server{Handler: s}
38+
s.Closer = srv
39+
go srv.Serve(l)
40+
return nil
41+
}
42+
43+
// NewServer returns a new Server.
44+
func NewServer(listen string) *Server {
45+
return &Server{
46+
Listen: listen,
47+
}
48+
}

protocol/etch/etchmain/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package main
2+
3+
import "github.com/mohanson/daze/protocol/etch"
4+
5+
func main() {
6+
server := etch.NewServer("127.0.0.1:8080")
7+
server.Run()
8+
select {}
9+
}

0 commit comments

Comments
 (0)