-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
40 lines (31 loc) · 847 Bytes
/
main.go
File metadata and controls
40 lines (31 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"io"
"log"
"net/http"
)
func HandleProcess(w http.ResponseWriter, r *http.Request) {
resp, err := http.Post("http://localhost:8081/thisJob", "application/json", nil)
if err != nil {
log.Fatal("Failed to send request: ", err)
}
defer resp.Body.Close()
respBody, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatal("Failed to read response: ", err)
}
respString := fmt.Sprintf("Response: %s", respBody)
w.Header().Set("Content-Type", "text/html")
w.Header().Set("HX-Reswap", "afterend")
w.Write([]byte(respString))
}
func main() {
http.Handle("/", http.FileServer(http.Dir("./static")))
http.HandleFunc("/createJobRun", HandleProcess)
log.Println("Starting server on :8080")
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}