feat: implement license platform business flows and delivery tooling
Add admin and customer interfaces, orders, signed activation and leases, protected package delivery, keyring verification, migrations, security controls, tests and deployment documentation. Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
42
backend/internal/httpapi/server.go
Normal file
42
backend/internal/httpapi/server.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Serve(ctx context.Context, server *http.Server, shutdownTimeout time.Duration) error {
|
||||
listener, err := net.Listen("tcp", server.Addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return serveListener(ctx, server, listener, shutdownTimeout)
|
||||
}
|
||||
|
||||
func serveListener(ctx context.Context, server *http.Server, listener net.Listener, timeout time.Duration) error {
|
||||
result := make(chan error, 1)
|
||||
go func() { result <- server.Serve(listener) }()
|
||||
select {
|
||||
case err := <-result:
|
||||
if errors.Is(err, http.ErrServerClosed) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
case <-ctx.Done():
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
if err := server.Shutdown(shutdownCtx); err != nil {
|
||||
_ = server.Close()
|
||||
<-result
|
||||
return err
|
||||
}
|
||||
err := <-result
|
||||
if errors.Is(err, http.ErrServerClosed) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user