Compare commits

...

3 commits

Author SHA1 Message Date
a046f3e0da add logging 2026-08-21 23:36:41 +02:00
7260d99d9e Keep curl in runtime image for Coolify
Coolify requires curl to be present in the container.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-28 16:06:39 +02:00
cc8974d6b7 Add health check endpoint at /ok
- Returns {"status": "ok"} as JSON
- No authentication required
- Useful for Kubernetes liveness/readiness probes

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2026-06-28 15:54:58 +02:00
4 changed files with 31 additions and 4 deletions

View file

@ -42,7 +42,6 @@ RUN apt-get update && \
RUN curl -sL -o /app/model.onnx https://huggingface.co/onnx-community/all-MiniLM-L6-v2-ONNX/resolve/main/onnx/model.onnx && \
curl -sL -o /app/model.onnx_data https://huggingface.co/onnx-community/all-MiniLM-L6-v2-ONNX/resolve/main/onnx/model.onnx_data && \
curl -sL -o /app/tokenizer.json https://huggingface.co/onnx-community/all-MiniLM-L6-v2-ONNX/resolve/main/tokenizer.json && \
apt-get remove -y curl 2>/dev/null || true && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

2
go.mod
View file

@ -1,6 +1,6 @@
module vector
go 1.23
go 1.23.0
require (
github.com/sugarme/tokenizer v0.3.0

29
main.go
View file

@ -6,6 +6,7 @@ import (
"log"
"net/http"
"os"
"time"
"github.com/sugarme/tokenizer"
"github.com/sugarme/tokenizer/pretrained"
@ -193,6 +194,30 @@ func vectorHandler(w http.ResponseWriter, r *http.Request) {
})
}
type statusRecorder struct {
http.ResponseWriter
status int
}
func (r *statusRecorder) WriteHeader(code int) {
r.status = code
r.ResponseWriter.WriteHeader(code)
}
func loggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
rec := &statusRecorder{ResponseWriter: w, status: http.StatusOK}
next.ServeHTTP(rec, r)
log.Printf("%s %s %s %d %s", r.RemoteAddr, r.Method, r.URL.Path, rec.status, time.Since(start))
})
}
func healthHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"status": "ok"})
}
func main() {
port := os.Getenv("PORT")
if port == "" {
@ -200,6 +225,8 @@ func main() {
}
http.HandleFunc("/vector", vectorHandler)
http.HandleFunc("/ok", healthHandler)
log.SetOutput(os.Stdout)
log.Printf("Starting server on port %s...\n", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
log.Fatal(http.ListenAndServe(":"+port, loggingMiddleware(http.DefaultServeMux)))
}

View file

@ -95,6 +95,7 @@ class VectorHandler(BaseHTTPRequestHandler):
except Exception as e:
self.send_error(500, str(e))
def log_message(self, format, *args):
pass # Suppress logs
sys.stdout.write("%s - - [%s] %s\n" % (self.address_string(), self.log_date_time_string(), format % args))
sys.stdout.flush()
HTTPServer(("0.0.0.0", int(os.getenv("PORT", 8080))), VectorHandler).serve_forever()