Initial
This commit is contained in:
commit
3d7e638cc6
10 files changed
+117
No files matched your search
@@ -0,0 +1,31 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fileserver/version"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func cmdStart() (cmd *cobra.Command) {
|
||||
cmd = &cobra.Command{
|
||||
Use: "start",
|
||||
Short: "Starts the Simple File Server with the given configuration.",
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// Run the server
|
||||
log.Printf("Simple File Server v%s", version.VERSION)
|
||||
log.Printf("Compiled with Go %s", version.GetGoversion())
|
||||
log.Printf("Configuration: root directory='%s', bind to='%s", configData.RootDirectory, configData.BindHostAndPort)
|
||||
log.Println("Start the file server now...")
|
||||
|
||||
http.Handle("/", http.FileServer(http.Dir(configData.RootDirectory)))
|
||||
http.ListenAndServe(configData.BindHostAndPort, nil)
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringVarP(&configData.RootDirectory, "rootDirectory", "d", ".", "The root directory. All files in this directory and its sub-directories get published.")
|
||||
cmd.Flags().StringVarP(&configData.BindHostAndPort, "bindHostPort", "b", "0.0.0.0:8080", "The address or hostname and port where to bind the file server.")
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fileserver/version"
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func cmdVersion() (cmd *cobra.Command) {
|
||||
cmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Prints the current version",
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Printf("Simple File Server v%s\n", version.VERSION)
|
||||
fmt.Printf("Compiled with Go %s", version.GetGoversion())
|
||||
},
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package cli
|
||||
|
||||
func Init() {
|
||||
rootCLI.AddCommand(cmdStart())
|
||||
rootCLI.AddCommand(cmdVersion())
|
||||
rootCLI.Execute()
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fileserver/Configuration"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
rootCLI = &cobra.Command{Use: "SimpleFileServer"}
|
||||
configData = &configuration.Container{}
|
||||
)
|
||||
Reference in new issue
Block a user