Minimal poc in Go, executing one command and with two HTTP servers.
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
gopoc: kapow.go
|
||||||
|
CGO_ENABLED=0 go build
|
||||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,35 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
go func() {
|
||||||
|
fmt.Println("Listening on port 8080")
|
||||||
|
http.ListenAndServe(":8080", &userServerHandler{})
|
||||||
|
}()
|
||||||
|
|
||||||
|
http.ListenAndServe(":8081", &controlApiHandler{})
|
||||||
|
}
|
||||||
|
|
||||||
|
type userServerHandler struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *userServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
out, err := exec.Command("date").Output()
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
} else {
|
||||||
|
w.Write(out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type controlApiHandler struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *controlApiHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Write([]byte("Welcome to the control API!"))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user