Initial
This commit is contained in:
commit
3d7e638cc6
10
Main.go
Normal file
10
Main.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fileserver/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The entry point of the application.
|
||||||
|
func main() {
|
||||||
|
cli.Init()
|
||||||
|
}
|
1
Variables.go
Normal file
1
Variables.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package main
|
31
cli/CmdStart.go
Normal file
31
cli/CmdStart.go
Normal file
@ -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
|
||||||
|
}
|
22
cli/CmdVersion.go
Normal file
22
cli/CmdVersion.go
Normal file
@ -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
|
||||||
|
}
|
7
cli/Init.go
Normal file
7
cli/Init.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
func Init() {
|
||||||
|
rootCLI.AddCommand(cmdStart())
|
||||||
|
rootCLI.AddCommand(cmdVersion())
|
||||||
|
rootCLI.Execute()
|
||||||
|
}
|
12
cli/Variables.go
Normal file
12
cli/Variables.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fileserver/Configuration"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
rootCLI = &cobra.Command{Use: "SimpleFileServer"}
|
||||||
|
configData = &configuration.Container{}
|
||||||
|
)
|
7
configuration/Scheme.go
Normal file
7
configuration/Scheme.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package configuration
|
||||||
|
|
||||||
|
// The data container for the configuration.
|
||||||
|
type Container struct {
|
||||||
|
BindHostAndPort string
|
||||||
|
RootDirectory string
|
||||||
|
}
|
7
go.mod
Normal file
7
go.mod
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
module fileserver
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
|
github.com/spf13/cobra v0.0.3
|
||||||
|
github.com/spf13/pflag v1.0.2 // indirect
|
||||||
|
)
|
6
go.sum
Normal file
6
go.sum
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||||
|
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||||
|
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
|
||||||
|
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||||
|
github.com/spf13/pflag v1.0.2 h1:Fy0orTDgHdbnzHcsOgfCN4LtHf0ec3wwtiwJqwvf3Gc=
|
||||||
|
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
14
version/Version.go
Normal file
14
version/Version.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const VERSION = "1.0.0"
|
||||||
|
|
||||||
|
func GetGoversion() (ver string) {
|
||||||
|
ver = runtime.Version()
|
||||||
|
ver = strings.Replace(ver, "go", "", 1)
|
||||||
|
return
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user