diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e6dc150 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM golang:1.23 + +WORKDIR /app + +# COPY go.mod go.sum ./ +COPY go.mod ./ + +RUN go mod download + +COPY *.go ./ + +RUN CGO_ENABLED=0 GOOS=linux go build -o /abyss + +CMD ["/abyss"] diff --git a/README.md b/README.md index d34f8df..5160f30 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,27 @@ abyss is a basic http server made for uploading files (logs, images) and then sh note: this is a project made for learning purposes, you should use other more mature projects if running in production -## running: -- edit consts in `main.go` to match your needs. (for example, on server, change `$url` so that the response will be nicely formatted) +## table of contents +- [running abyss](#running) + - [installing with docker](#docker) + - [installing manually](#manual) +- [todo list](#todo) -- to run it, either build with `go build -o abyss && ./abyss` or run it directly with: +## running: +- change URL env variable in to your domain. example: `URL=paste.abyss.dev` +### docker +- to run with docker, you can use either docker compose or just straight docker. +- then run the docker compose command: ```bash -go run ./main.go +docker compose up -d # might be docker-compose depending on distro +``` +- dont change inside port of 8080 unless you know what you're doing + +### manual + +- to run it, either build with `go build -o abyss` or run it directly with: +```bash +URL="your-domain" go run ./main.go ``` - then, simply upload your files with curl: @@ -17,6 +32,6 @@ curl -X POST -F "file=@/path/to/file" http://localhost:8080/upload # default url ``` ## todo: - [x] add upload of logs funcionality (like 0x0.st) -- [ ] add docker easy setup +- [x] add docker easy setup - [ ] add db for tracking of file names - [ ] add file browser (like file://) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..aa72940 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,7 @@ +services: + paste: + environment: + URL: "localhost:58080" + build: . + ports: + - "58080:8080" diff --git a/main.go b/main.go index a8750ce..8ce2095 100644 --- a/main.go +++ b/main.go @@ -10,11 +10,12 @@ import ( ) const ( - url = "localhost" port = ":8080" filesDir = "./files" ) +var url string = os.Getenv("URL") + func main() { http.HandleFunc("/upload", uploadHandler) http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir(filesDir)))) @@ -54,5 +55,9 @@ func uploadHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, "Error copying the file", http.StatusInternalServerError) } - fmt.Fprintf(w, "http://%s%s/%d\n", url, port, time) + if url == "" { + fmt.Fprintf(w, "http://localhost%s/%d\n", port, time) + } else { + fmt.Fprintf(w, "http://%s/%d\n", url, time) + } }