Clear History

This commit is contained in:
2023-05-11 17:44:13 +02:00
commit 4acb9b9ae8
77 changed files with 5363 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
FROM golang:1.20 as builder
WORKDIR /app
COPY . .
RUN go build
FROM ubuntu
RUN apt-get update && apt-get install -y dnsutils
WORKDIR /app
COPY --from=builder /app .
EXPOSE 42069
CMD /app/sidecar

View File

@@ -0,0 +1,3 @@
module iluzio.nicco.io/sidecar
go 1.20

View File

@@ -0,0 +1,44 @@
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"os/exec"
"strings"
)
var SERVICE = os.Getenv("SERVICE")
func getIPs() []string {
out, err := exec.Command("dig", "+short", "+search", SERVICE).Output()
if err != nil {
log.Fatal(err)
return []string{}
}
trimmed := strings.TrimSpace(fmt.Sprintf("%s", out))
if trimmed == "" {
return []string{}
} else {
return strings.Split(trimmed, "\n")
}
}
func main() {
http.HandleFunc("/discoverable", func(w http.ResponseWriter, r *http.Request) {
ips := getIPs()
plain := r.URL.Query().Get("format") == "plain"
if plain {
fmt.Fprintf(w, "%s\n", strings.Join(ips, "\n"))
} else {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(ips)
}
})
log.Fatal(http.ListenAndServe(":42069", nil))
}