Skip to content

Commit d5e7859

Browse files
committed
Update our cmd
A little reordering here because we're now using the server package to manage our protocols and renderers. The most notable change is the server accepts many renderers which we use for the output.
1 parent 3634f0e commit d5e7859

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

cmd/protocol.go

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"github.com/aaronvb/request_hole/pkg/protocol"
45
"github.com/aaronvb/request_hole/pkg/renderer"
56
"github.com/aaronvb/request_hole/pkg/server"
67
"github.com/spf13/cobra"
@@ -20,25 +21,42 @@ func init() {
2021
}
2122

2223
func http(cmd *cobra.Command, args []string) {
23-
logOutput := &renderer.Logger{
24-
File: LogFile,
25-
Port: Port,
26-
Addr: Address,
24+
renderers := make([]renderer.Renderer, 0)
25+
26+
// Collect flag data into struct to use with renderers
27+
flagData := server.FlagData{
28+
Addr: Address,
29+
BuildInfo: BuildInfo,
30+
Details: Details,
31+
LogFile: LogFile,
32+
Port: Port,
33+
ResponseCode: ResponseCode,
2734
}
28-
output := &renderer.Printer{
29-
Port: Port,
30-
Addr: Address,
31-
BuildInfo: BuildInfo,
32-
LogFile: LogFile,
33-
Details: Details}
34-
35-
httpServer := server.Http{
35+
36+
printer := &renderer.Printer{Details: Details}
37+
renderers = append(renderers, printer)
38+
39+
if LogFile != "" {
40+
logger := &renderer.Logger{
41+
FilePath: LogFile,
42+
Details: Details,
43+
Addr: Address,
44+
Port: Port,
45+
}
46+
renderers = append(renderers, logger)
47+
}
48+
49+
httpServer := &protocol.Http{
3650
Addr: Address,
3751
Port: Port,
3852
ResponseCode: ResponseCode,
39-
Output: output,
40-
LogOutput: logOutput,
41-
Details: Details}
53+
}
54+
55+
srv := server.Server{
56+
FlagData: flagData,
57+
Protocol: httpServer,
58+
Renderers: renderers,
59+
}
4260

43-
httpServer.Start()
61+
srv.Start()
4462
}

0 commit comments

Comments
 (0)