File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import (
16
16
"github.com/codingconcepts/dg/internal/pkg/model"
17
17
"github.com/codingconcepts/dg/internal/pkg/source"
18
18
"github.com/codingconcepts/dg/internal/pkg/ui"
19
+ "github.com/codingconcepts/dg/internal/pkg/web"
19
20
"github.com/samber/lo"
20
21
)
21
22
@@ -31,6 +32,7 @@ func main() {
31
32
createImports := flag .String ("i" , "" , "write import statements to file" )
32
33
cpuprofile := flag .String ("cpuprofile" , "" , "write cpu profile to file" )
33
34
versionFlag := flag .Bool ("version" , false , "display the current version number" )
35
+ port := flag .Int ("p" , 0 , "port to serve files from (omit to generate without serving)" )
34
36
flag .Parse ()
35
37
36
38
if * cpuprofile != "" {
@@ -78,6 +80,12 @@ func main() {
78
80
log .Fatalf ("error writing import statements: %v" , err )
79
81
}
80
82
}
83
+
84
+ if * port == 0 {
85
+ return
86
+ }
87
+
88
+ log .Fatal (web .Serve (* outputDir , * port ))
81
89
}
82
90
83
91
func loadConfig (filename string , tt ui.TimerFunc ) (model.Config , error ) {
Original file line number Diff line number Diff line change
1
+ package web
2
+
3
+ import (
4
+ "fmt"
5
+ "log"
6
+ "net/http"
7
+ )
8
+
9
+ // Serve files from the output csv directory on a given port.
10
+ //
11
+ // Note: This is a blocking call.
12
+ func Serve (dir string , port int ) error {
13
+ fs := http .FileServer (http .Dir (dir ))
14
+ http .Handle ("/" , fs )
15
+
16
+ addr := fmt .Sprintf (":%d" , port )
17
+
18
+ log .Printf ("Serving files on %s" , addr )
19
+ return http .ListenAndServe (addr , nil )
20
+ }
You can’t perform that action at this time.
0 commit comments