commit
This commit is contained in:
34
main.go
Normal file
34
main.go
Normal file
@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
var port uint
|
||||
var folderPath string
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&folderPath, "p", "", "Path to folder (required)")
|
||||
flag.UintVar(&port, "l", 8080, "Listening port (default 8080)")
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
if folderPath == "" {
|
||||
fmt.Fprintf(os.Stderr, "Error: parametr 'path' is required")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
server := &http.Server{
|
||||
Addr: fmt.Sprintf(":%d", port),
|
||||
Handler: &fileHandler{
|
||||
root: folderPath,
|
||||
},
|
||||
}
|
||||
|
||||
server.ListenAndServe()
|
||||
}
|
Reference in New Issue
Block a user