Fixes, readme

This commit is contained in:
Alexander
2026-04-09 23:06:17 +02:00
parent 909c8b1894
commit f22765d8f0
5 changed files with 170 additions and 23 deletions
+30 -2
View File
@@ -4,7 +4,11 @@ import (
"context"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/fujin/anthropic-proxy/internal/auth"
"github.com/fujin/anthropic-proxy/internal/config"
@@ -33,8 +37,11 @@ func run() error {
pool := auth.NewPool(creds)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
pool.RefreshExpiring(context.Background())
auth.StartBackgroundRefresh(pool)
auth.StartBackgroundRefresh(ctx, pool)
var profile *proxy.SniffedProfile
if cfg.ClaudeBinary != "" {
@@ -47,7 +54,28 @@ func run() error {
log.Printf("starting server on port %d", cfg.Port)
srv := server.New(cfg, pool, profile)
return srv.Start()
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-quit
log.Printf("shutting down...")
cancel()
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 10*time.Second)
defer shutdownCancel()
if err := srv.Shutdown(shutdownCtx); err != nil {
log.Printf("shutdown error: %v", err)
}
}()
if err := srv.Start(); err != nil && err != http.ErrServerClosed {
return err
}
return nil
}
func main() {