commit 194cb62412490b6d43233ad01d1a38c22a832bc9 Author: Caleb Vorderbruggen Date: Mon Apr 18 18:13:53 2022 -0400 initial diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..44eb6db --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [2022] [Caleb Vorderbruggen] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..bacf0c1 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# Handler + +Provides simple HTTP file server; Its so simple to do with golang; looks like nobody bothers to provide a ready-to-download package to actually do it. + + +## Examples + +Calling without any arguments defaults to serving ./ at 0.0.0.0:8080 + +### Changing default settings + +- a sets ip address +- p sets port +- d sets directory to serve + +```golang +$ ./handler -a 127.0.0.1 -p 3000 -d ./foo/bar +``` \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..97c7e21 --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module git.thirdage.dev/night/handler + +go 1.18 + +require ( + github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/spf13/cobra v1.4.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..0dd8697 --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q= +github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/handler.go b/handler.go new file mode 100644 index 0000000..9536c8f --- /dev/null +++ b/handler.go @@ -0,0 +1,28 @@ +/* +Project: Handler + +Purpose: Provide simple HTTP file server; Its so simple to do with golang; looks like nobody bothers to provide a ready-to-download package to actually do it. + +Author: Caleb Vorderbruggen + +*/ +package main + +import ( + "flag" + "log" + "net/http" +) + +func main() { + p := flag.String("p", "8080", "HTTP Server Port") + dir := flag.String("d", "./", "Directory to serve") + address := flag.String("a", "0.0.0.0", "IP Address to use") + + flag.Parse() + + http.Handle("/", http.FileServer(http.Dir(*dir))) + + log.Printf("Serving HTTP on %s port %s at %s (http://%s:%s/)\n", *address, *p, *dir, *address, *p) + log.Fatal(http.ListenAndServe(*address+":"+*p, nil)) +}