This commit is contained in:
2022-05-17 01:56:44 +03:00
commit 3a9b8c8468
117 changed files with 7175 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
module xseld
go 1.17
+44
View File
@@ -0,0 +1,44 @@
package main
import (
"io"
"log"
"net/http"
"os/exec"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
cmd := exec.Command("xsel", "-b")
switch r.Method {
case http.MethodGet:
cmd.Args = append(cmd.Args, "-o")
stdout, err := cmd.StdoutPipe()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
go io.Copy(w, stdout)
case http.MethodPost:
cmd.Args = append(cmd.Args, "-i")
stdin, err := cmd.StdinPipe()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
go func() {
defer stdin.Close()
io.Copy(stdin, r.Body)
}()
default:
http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
return
}
err := cmd.Run()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
})
log.Fatal(http.ListenAndServe(":9090", nil))
}