oasis/main.go

48 lines
779 B
Go

package main
import (
"fmt"
"io"
"log"
"net/http"
"github.com/javif89/oasis/fastcgi"
)
func handleRequest(w http.ResponseWriter, r *http.Request) {
fmt.Println("Request received")
req := fastcgi.RequestFromHttp(r)
req.Script("/home/javi/projects/oasis/index.php")
req.TypeGet()
fcgiClient, err := fastcgi.Dial("unix", "/var/run/php/php8.3-fpm.sock")
if err != nil {
log.Println("err:", err)
}
resp, err := fcgiClient.Do(req)
if err != nil {
log.Println("err:", err)
}
content, err := io.ReadAll(resp.Body)
if err != nil {
log.Println("err:", err)
}
w.Write(content)
}
func main() {
// Server
http.HandleFunc("/", handleRequest)
fmt.Println("Starting server")
err := http.ListenAndServe(":8000", nil)
if err != nil {
log.Fatal(err)
}
}