MCPcopy Index your code
hub / github.com/ContainerSSH/ContainerSSH / ExampleNewServer

Function ExampleNewServer

config/webhook/server_test.go:22–69  ·  view source on GitHub ↗

ExampleNewServer demonstrates how to set up a configuration webhook server.

()

Source from the content-addressed store, hash-verified

20
21// ExampleNewServer demonstrates how to set up a configuration webhook server.
22func ExampleNewServer() {
23 // Set up a logger
24 logger := log.MustNewLogger(config.LogConfig{
25 Level: config.LogLevelWarning,
26 Format: config.LogFormatText,
27 Destination: config.LogDestinationStdout,
28 Stdout: os.Stdout,
29 })
30
31 // Create a new config webhook server.
32 srv, err := webhook.NewServer(
33 config.HTTPServerConfiguration{
34 Listen: "0.0.0.0:0",
35 },
36 &myConfigReqHandler{},
37 logger,
38 )
39 if err != nil {
40 // Handle error
41 panic(err)
42 }
43
44 // Set up and run the web server service.
45 lifecycle := service.NewLifecycle(srv)
46
47 go func() {
48 //Ignore error, handled later.
49 _ = lifecycle.Run()
50 }()
51
52 // Sleep for 30 seconds as a test
53 time.Sleep(30 * time.Second)
54
55 // Set up a shutdown context to give a deadline for graceful shutdown.
56 shutdownContext, cancel := context.WithTimeout(context.Background(), 30*time.Second)
57 defer cancel()
58 // Stop the server.
59 lifecycle.Stop(shutdownContext)
60
61 // Wait for the server to stop.
62 lastError := lifecycle.Wait()
63 if lastError != nil {
64 // Server stopped abnormally.
65 panic(lastError)
66 }
67
68 // Output:
69}

Callers

nothing calls this directly

Calls 6

RunMethod · 0.95
StopMethod · 0.95
WaitMethod · 0.95
MustNewLoggerFunction · 0.92
NewServerFunction · 0.92
NewLifecycleFunction · 0.92

Tested by

no test coverage detected