commit 86f7cd4ecffe7dc97828c7b1f17417af4f67ee36 Author: vxclutch Date: Thu May 21 10:59:14 2026 -0400 Inital version diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8990af7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,15 @@ +ISC License + +Copyright (c) 2026 vxc + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0985a9d --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# LASH (Local Area Share HTTP) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5446f41 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module lash + +go 1.26.3 + +require github.com/google/uuid v1.6.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7790d7c --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= diff --git a/lash b/lash new file mode 100755 index 0000000..4f9bc97 Binary files /dev/null and b/lash differ diff --git a/main.go b/main.go new file mode 100644 index 0000000..5b851e8 --- /dev/null +++ b/main.go @@ -0,0 +1,65 @@ +package main + +import ( + _ "embed" + "errors" + "fmt" + "html/template" + "log" + "net/http" + "os" + "github.com/google/uuid" +) + +//go:embed version +var version string + +var fp string +var read []byte +var id string = uuid.New().String() + +type Data struct { + Version string + FileName string + Contents []byte + UUID string +} + +func main() { + if len(os.Args) < 2 { + fmt.Println("error: lash: not enough arguments") + return + } + fp = os.Args[1] + var err error + read, err = os.ReadFile(fp) + if err != nil { + if errors.Is(err, os.ErrNotExist) { + fmt.Printf("error: lash: file `%s` does not exist", fp) + } else { + panic(err) + } + } + + + http.HandleFunc("/", shareHandler) + http.HandleFunc(fmt.Sprintf("/%s", id), fileHandler) + fmt.Println("lash: starting server at http://127.0.0.1:1337") + log.Fatal(http.ListenAndServe("127.0.0.1:1337", nil)) +} + +func shareHandler(w http.ResponseWriter, r *http.Request) { + tmpl := template.Must(template.ParseFiles("templates/share.html")) + + data := Data{ + Version: version, + FileName: fp, + UUID: id, + } + + tmpl.ExecuteTemplate(w, "share.html", data) +} + +func fileHandler(w http.ResponseWriter, r *http.Request) { + w.Write(read) +} diff --git a/templates/share.html b/templates/share.html new file mode 100644 index 0000000..ce7b99e --- /dev/null +++ b/templates/share.html @@ -0,0 +1,12 @@ + + + + + +Lash v{{.Version}} + + + +

{{.FileName}}

+ + diff --git a/version b/version new file mode 100644 index 0000000..6e8bf73 --- /dev/null +++ b/version @@ -0,0 +1 @@ +0.1.0