Implement remaining code review suggestions
- Add graceful shutdown with SIGTERM/SIGINT handling\n- Make model list configurable via config.yaml\n- Remove sensitive data from debug logs (log sizes instead of full bodies)\n- Handle array format in system messages (both string and []interface{})\n- Update config.yaml with new models structure
This commit is contained in:
parent
f65ad6b189
commit
cea246da83
5 changed files with 60 additions and 12 deletions
27
main.go
27
main.go
|
|
@ -6,6 +6,9 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
|
@ -38,10 +41,28 @@ func main() {
|
|||
})
|
||||
|
||||
addr := fmt.Sprintf(":%d", config.Port)
|
||||
log.Printf("Starting proxx on %s, upstream: %s", addr, config.UpstreamURL)
|
||||
if err := http.ListenAndServe(addr, nil); err != nil {
|
||||
log.Fatalf("Server failed: %v", err)
|
||||
|
||||
server := &http.Server{Addr: addr}
|
||||
|
||||
go func() {
|
||||
log.Printf("Starting proxx on %s, upstream: %s", addr, config.UpstreamURL)
|
||||
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
log.Fatalf("Server failed: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Wait for interrupt signal
|
||||
sigChan := make(chan os.Signal, 1)
|
||||
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-sigChan
|
||||
|
||||
log.Println("Shutting down server...")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
if err := server.Shutdown(ctx); err != nil {
|
||||
log.Printf("Server shutdown error: %v", err)
|
||||
}
|
||||
log.Println("Server stopped")
|
||||
}
|
||||
|
||||
// contextKey is a custom type for context keys
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue