diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 19 |
1 files changed, 16 insertions, 3 deletions
| @@ -5,6 +5,7 @@ import ( | |||
| 5 | "fmt" | 5 | "fmt" |
| 6 | "html/template" | 6 | "html/template" |
| 7 | "log" | 7 | "log" |
| 8 | "net/http" | ||
| 8 | "os" | 9 | "os" |
| 9 | "path" | 10 | "path" |
| 10 | "path/filepath" | 11 | "path/filepath" |
| @@ -91,6 +92,13 @@ func cleanHTMLTags(htmlString string) string { | |||
| 91 | return cleanString | 92 | return cleanString |
| 92 | } | 93 | } |
| 93 | 94 | ||
| 95 | func simpleServer(projectRoot string) { | ||
| 96 | fs := http.FileServer(http.Dir(path.Join(projectRoot, "public"))) | ||
| 97 | http.Handle("/", fs) | ||
| 98 | log.Println("Server started on http://localhost:6969") | ||
| 99 | log.Fatal(http.ListenAndServe(":6969", nil)) | ||
| 100 | } | ||
| 101 | |||
| 94 | func initializeProject(projectRoot string) { | 102 | func initializeProject(projectRoot string) { |
| 95 | log.Println("Initializing new project") | 103 | log.Println("Initializing new project") |
| 96 | 104 | ||
| @@ -353,13 +361,14 @@ func main() { | |||
| 353 | } | 361 | } |
| 354 | 362 | ||
| 355 | var args struct { | 363 | var args struct { |
| 356 | Init bool `arg:"-i,--init" help:"initialize new project"` | 364 | Init bool `arg:"-i,--init" help:"initialize new project"` |
| 357 | Build bool `arg:"-b,--build" help:"build the website"` | 365 | Build bool `arg:"-b,--build" help:"build the website"` |
| 366 | Server bool `arg:"-s,--server" help:"simple embedded HTTP server"` | ||
| 358 | } | 367 | } |
| 359 | 368 | ||
| 360 | arg.MustParse(&args) | 369 | arg.MustParse(&args) |
| 361 | 370 | ||
| 362 | if !args.Init && !args.Build { | 371 | if !args.Init && !args.Build && !args.Server { |
| 363 | fmt.Println("No arguments provided. Try using `jbmafp --help`") | 372 | fmt.Println("No arguments provided. Try using `jbmafp --help`") |
| 364 | os.Exit(0) | 373 | os.Exit(0) |
| 365 | } | 374 | } |
| @@ -371,4 +380,8 @@ func main() { | |||
| 371 | if args.Build { | 380 | if args.Build { |
| 372 | buildProject(projectRoot) | 381 | buildProject(projectRoot) |
| 373 | } | 382 | } |
| 383 | |||
| 384 | if args.Server { | ||
| 385 | simpleServer(projectRoot) | ||
| 386 | } | ||
| 374 | } | 387 | } |
