Skip to content

Commit 542d6fe

Browse files
authored
Change [proto]-server to [proto]-listen (#9)
* add [proto]-listen versions * update docs * rename methods/errors
1 parent 023cb14 commit 542d6fe

18 files changed

+153
-153
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@ Any data that's fed into the input will be piped to the output.
2222

2323
## Examples
2424

25-
Pipe from stdin to a new TCP server on port 8080:
25+
Pipe from stdin to a new TCP listener on port 8080:
2626
```
27-
hookah -o tcp-server://localhost:8080
27+
hookah -o tcp-listen://localhost:8080
2828
```
2929

30-
Pipe from an existing TCP server on port 8080 to a new HTTP server on port 8081:
30+
Pipe from an existing TCP listener on port 8080 to a new HTTP listener on port 8081:
3131
```
32-
hookah -i tcp://localhost:8080 -o http-server://localhost:8081
32+
hookah -i tcp://localhost:8080 -o http-listen://localhost:8081
3333
```
3434

3535
Pipe from a new Unix domain socket listener to stdout:
3636
```
37-
hookah -i unix-server://path/to/sock
37+
hookah -i unix-listen://path/to/sock
3838
```
3939

40-
Pipe from a new HTTP server on port 8080 to an existing Unix domain socket:
40+
Pipe from a new HTTP listener on port 8080 to an existing Unix domain socket:
4141
```
42-
hookah -i http-server://localhost:8080 -o unix://path/to/sock
42+
hookah -i http-listen://localhost:8080 -o unix://path/to/sock
4343
```
4444

4545
# Usage instructions (Go package)

examples_test.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,39 @@ func ExampleNewInput_httpClient() {
3232
r, err = hookah.NewInput("http://localhost:8080")
3333
}
3434

35-
// Create HTTP server input.
36-
func ExampleNewInput_httpServer() {
37-
r, err = hookah.NewInput("http-server://localhost:8080")
35+
// Create HTTP listen input.
36+
func ExampleNewInput_httpListen() {
37+
r, err = hookah.NewInput("http-listen://localhost:8080")
3838
}
3939

4040
// Create TCP client input.
4141
func ExampleNewInput_tcpClient() {
4242
r, err = hookah.NewInput("tcp://localhost:8080")
4343
}
4444

45-
// Create TCP server input.
46-
func ExampleNewInput_tcpServer() {
47-
r, err = hookah.NewInput("tcp-server://localhost:8080")
45+
// Create TCP listen input.
46+
func ExampleNewInput_tcpListen() {
47+
r, err = hookah.NewInput("tcp-listen://localhost:8080")
4848
}
4949

5050
// Create Unix client input.
5151
func ExampleNewInput_unixClient() {
5252
r, err = hookah.NewInput("unix://path/to/sock")
5353
}
5454

55-
// Create Unix server input.
56-
func ExampleNewInput_unixServer() {
57-
r, err = hookah.NewInput("unix-server://path/to/sock")
55+
// Create Unix listen input.
56+
func ExampleNewInput_unixListen() {
57+
r, err = hookah.NewInput("unix-listen://path/to/sock")
5858
}
5959

6060
// Create WebSocket client input.
6161
func ExampleNewInput_wsClient() {
6262
r, err = hookah.NewInput("ws://localhost:8080")
6363
}
6464

65-
// Create WebSocket server input.
66-
func ExampleNewInput_wsServer() {
67-
r, err = hookah.NewInput("ws-server://localhost:8080")
65+
// Create WebSocket listen input.
66+
func ExampleNewInput_wsListen() {
67+
r, err = hookah.NewInput("ws-listen://localhost:8080")
6868
}
6969

7070
// NewOutput examples
@@ -94,37 +94,37 @@ func ExampleNewOutput_httpClient() {
9494
w, err = hookah.NewOutput("http://localhost:8080")
9595
}
9696

97-
// Create HTTP server output.
98-
func ExampleNewOutput_httpServer() {
99-
w, err = hookah.NewOutput("http-server://localhost:8080")
97+
// Create HTTP listen output.
98+
func ExampleNewOutput_httpListen() {
99+
w, err = hookah.NewOutput("http-listen://localhost:8080")
100100
}
101101

102102
// Create TCP client output.
103103
func ExampleNewOutput_tcpClient() {
104104
w, err = hookah.NewOutput("tcp://localhost:8080")
105105
}
106106

107-
// Create TCP server output.
108-
func ExampleNewOutput_tcpServer() {
109-
w, err = hookah.NewOutput("tcp-server://localhost:8080")
107+
// Create TCP listen output.
108+
func ExampleNewOutput_tcpListen() {
109+
w, err = hookah.NewOutput("tcp-listen://localhost:8080")
110110
}
111111

112112
// Create Unix client output.
113113
func ExampleNewOutput_unixClient() {
114114
w, err = hookah.NewOutput("unix://path/to/sock")
115115
}
116116

117-
// Create Unix server output.
118-
func ExampleNewOutput_unixServer() {
119-
w, err = hookah.NewOutput("unix-server://path/to/sock")
117+
// Create Unix listen output.
118+
func ExampleNewOutput_unixListen() {
119+
w, err = hookah.NewOutput("unix-listen://path/to/sock")
120120
}
121121

122122
// Create WebSocket client output.
123123
func ExampleNewOutput_wsClient() {
124124
w, err = hookah.NewOutput("ws://localhost:8080")
125125
}
126126

127-
// Create WebSocket server output.
128-
func ExampleNewOutput_wsServer() {
129-
w, err = hookah.NewOutput("ws-server://localhost:8080")
127+
// Create WebSocket listen output.
128+
func ExampleNewOutput_wsListen() {
129+
w, err = hookah.NewOutput("ws-listen://localhost:8080")
130130
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"sync"
77
)
88

9-
type httpServerApp struct {
9+
type httpListenApp struct {
1010
server *http.Server
1111
// Channel of messages
1212
ch chan []byte
@@ -16,9 +16,9 @@ type httpServerApp struct {
1616
top []byte
1717
}
1818

19-
// Create an HTTP server and return as ReadCloser
20-
func httpServer(addr string) (io.ReadCloser, error) {
21-
app := &httpServerApp{}
19+
// Create an HTTP listener and return as ReadCloser
20+
func httpListen(addr string) (io.ReadCloser, error) {
21+
app := &httpListenApp{}
2222
app.server = &http.Server{
2323
Addr: addr,
2424
Handler: http.HandlerFunc(app.handle),
@@ -30,7 +30,7 @@ func httpServer(addr string) (io.ReadCloser, error) {
3030
return app, nil
3131
}
3232

33-
func (app *httpServerApp) Read(b []byte) (int, error) {
33+
func (app *httpListenApp) Read(b []byte) (int, error) {
3434
app.mu.Lock()
3535
defer app.mu.Unlock()
3636
if len(app.top) == 0 {
@@ -45,12 +45,12 @@ func (app *httpServerApp) Read(b []byte) (int, error) {
4545
return n, nil
4646
}
4747

48-
func (app *httpServerApp) Close() error {
48+
func (app *httpListenApp) Close() error {
4949
close(app.ch)
5050
return app.server.Close()
5151
}
5252

53-
func (app *httpServerApp) handle(w http.ResponseWriter, r *http.Request) {
53+
func (app *httpListenApp) handle(w http.ResponseWriter, r *http.Request) {
5454
defer r.Body.Close()
5555
buffer := make([]byte, bufferSize)
5656
for {

pkg/input/input.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,56 +40,56 @@ func New(opts string) (io.ReadCloser, error) {
4040
return file(arg)
4141
case "http":
4242
if arg == "" {
43-
return nil, errors.New("http client: no address supplied")
43+
return nil, errors.New("http: no address supplied")
4444
}
4545
return httpClient("http://" + arg)
4646
case "https":
4747
if arg == "" {
48-
return nil, errors.New("https client: no address supplied")
48+
return nil, errors.New("https: no address supplied")
4949
}
5050
return httpClient("https://" + arg)
51-
case "http-server":
51+
case "http-listen", "http-server":
5252
if arg == "" {
53-
return nil, errors.New("http server: no address supplied")
53+
return nil, errors.New("http-listen: no address supplied")
5454
}
55-
return httpServer(arg)
55+
return httpListen(arg)
5656
case "tcp":
5757
if arg == "" {
58-
return nil, errors.New("tcp client: no address supplied")
58+
return nil, errors.New("tcp: no address supplied")
5959
}
6060
return tcpClient(arg)
61-
case "tcp-server":
61+
case "tcp-listen", "tcp-server":
6262
if arg == "" {
63-
return nil, errors.New("tcp server: no address supplied")
63+
return nil, errors.New("tcp-listen: no address supplied")
6464
}
65-
return tcpServer(arg)
65+
return tcpListen(arg)
6666
case "unix":
6767
if arg == "" {
68-
return nil, errors.New("unix client: no address supplied")
68+
return nil, errors.New("unix: no address supplied")
6969
}
7070
return unixClient(arg)
71-
case "unix-server":
71+
case "unix-listen", "unix-server":
7272
if arg == "" {
73-
return nil, errors.New("unix server: no address supplied")
73+
return nil, errors.New("unix-listen: no address supplied")
7474
}
75-
return unixServer(arg)
75+
return unixListen(arg)
7676
case "ws":
7777
if arg == "" {
78-
return nil, errors.New("ws client: no address supplied")
78+
return nil, errors.New("ws: no address supplied")
7979
}
8080
return wsClient("ws://" + arg)
8181
case "wss":
8282
if arg == "" {
83-
return nil, errors.New("wss client: no address supplied")
83+
return nil, errors.New("wss: no address supplied")
8484
}
8585
return wsClient("wss://" + arg)
86-
case "ws-server":
86+
case "ws-listen", "ws-server":
8787
if arg == "" {
88-
return nil, errors.New("ws server: no address supplied")
88+
return nil, errors.New("ws-listen: no address supplied")
8989
}
90-
return wsServer(arg)
90+
return wsListen(arg)
9191
default:
92-
return nil, errors.New("unknown in protocol: " + proto)
92+
return nil, errors.New("unknown input protocol: " + proto)
9393
}
9494
}
9595

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"sync"
77
)
88

9-
type listenServerApp struct {
9+
type listenApp struct {
1010
ln net.Listener
1111
// Channel of messages
1212
ch chan []byte
@@ -16,9 +16,9 @@ type listenServerApp struct {
1616
top []byte
1717
}
1818

19-
// Create a listen server and return as ReadCloser
20-
func listenServer(network, addr string) (io.ReadCloser, error) {
21-
app := &listenServerApp{}
19+
// Create a listener and return as ReadCloser
20+
func listen(network, addr string) (io.ReadCloser, error) {
21+
app := &listenApp{}
2222
ln, err := net.Listen(network, addr)
2323
if err != nil {
2424
return nil, err
@@ -31,7 +31,7 @@ func listenServer(network, addr string) (io.ReadCloser, error) {
3131
return app, nil
3232
}
3333

34-
func (app *listenServerApp) Read(b []byte) (int, error) {
34+
func (app *listenApp) Read(b []byte) (int, error) {
3535
app.mu.Lock()
3636
defer app.mu.Unlock()
3737
if len(app.top) == 0 {
@@ -46,12 +46,12 @@ func (app *listenServerApp) Read(b []byte) (int, error) {
4646
return n, nil
4747
}
4848

49-
func (app *listenServerApp) Close() error {
49+
func (app *listenApp) Close() error {
5050
close(app.ch)
5151
return app.ln.Close()
5252
}
5353

54-
func (app *listenServerApp) serve() {
54+
func (app *listenApp) serve() {
5555
defer app.ln.Close()
5656
for {
5757
conn, err := app.ln.Accept()
@@ -62,7 +62,7 @@ func (app *listenServerApp) serve() {
6262
}
6363
}
6464

65-
func (app *listenServerApp) handle(conn net.Conn) {
65+
func (app *listenApp) handle(conn net.Conn) {
6666
defer conn.Close()
6767
buffer := make([]byte, bufferSize)
6868
for {

pkg/input/tcplisten.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package input
2+
3+
import (
4+
"io"
5+
)
6+
7+
// Create a TCP listener and return as ReadCloser
8+
func tcpListen(addr string) (io.ReadCloser, error) {
9+
return listen("tcp", addr)
10+
}

pkg/input/tcpserver.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

pkg/input/unixlisten.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package input
2+
3+
import (
4+
"io"
5+
)
6+
7+
// Create a Unix listener and return as ReadCloser
8+
func unixListen(addr string) (io.ReadCloser, error) {
9+
return listen("unix", addr)
10+
}

pkg/input/unixserver.go

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)