Inital version

This commit is contained in:
vxclutch
2026-05-21 10:59:14 -04:00
commit 86f7cd4ecf
8 changed files with 101 additions and 0 deletions

15
LICENSE Normal file
View File

@@ -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.

1
README.md Normal file
View File

@@ -0,0 +1 @@
# LASH (Local Area Share HTTP)

5
go.mod Normal file
View File

@@ -0,0 +1,5 @@
module lash
go 1.26.3
require github.com/google/uuid v1.6.0 // indirect

2
go.sum Normal file
View File

@@ -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=

BIN
lash Executable file

Binary file not shown.

65
main.go Normal file
View File

@@ -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)
}

12
templates/share.html Normal file
View File

@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lash v{{.Version}}</title>
</head>
<body>
<h1><a href="/{{.UUID}}" download>{{.FileName}}</a></h1>
</body>
</html>

1
version Normal file
View File

@@ -0,0 +1 @@
0.1.0