-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extension/cmd: test extension server before integrating witih savvy r…
…ecord and savvy record history Signed-off-by: Shantanu <[email protected]>
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/getsavvyinc/savvy-cli/extension" | ||
) | ||
|
||
func main() { | ||
// Create a context that we'll cancel on signal | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
// Set up signal handling | ||
sigChan := make(chan os.Signal, 1) | ||
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
// Create and start the server | ||
processor := func(items []extension.HistoryItem) error { | ||
for _, item := range items { | ||
fmt.Printf("Processing item: %s\n", item.URL) | ||
} | ||
return nil | ||
} | ||
|
||
server := extension.New(processor) | ||
if err := server.Start(ctx); err != nil { | ||
fmt.Printf("Error starting server: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Wait for signal | ||
sig := <-sigChan | ||
fmt.Printf("\nReceived signal: %v\n", sig) | ||
fmt.Println("Shutting down server...") | ||
|
||
// Cancel context to trigger graceful shutdown | ||
cancel() | ||
|
||
// Wait for server to close | ||
if err := server.Close(); err != nil { | ||
fmt.Printf("Error during shutdown: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println("Server shutdown complete") | ||
} |