MCPcopy Create free account
hub / github.com/CPChain/chain / ExampleService

Function ExampleService

node/node_example_test.go:30–61  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28func (s *SampleService) Stop() error { fmt.Println("Service stopping..."); return nil }
29
30func ExampleService() {
31 // Create a network node to run protocols with the default values.
32 stack, err := node.New(&node.Config{})
33 if err != nil {
34 log.Fatalf("Failed to create network node: %v", err)
35 }
36 // Create and register a simple network service. This is done through the definition
37 // of a node.ServiceConstructor that will instantiate a node.Service. The reason for
38 // the factory method approach is to support service restarts without relying on the
39 // individual implementations' support for such operations.
40 constructor := func(context *node.ServiceContext) (node.Service, error) {
41 return new(SampleService), nil
42 }
43 if err := stack.Register(constructor); err != nil {
44 log.Fatalf("Failed to register service: %v", err)
45 }
46 // Boot up the entire protocol stack, do a restart and terminate
47 if err := stack.Start(); err != nil {
48 log.Fatalf("Failed to start the protocol stack: %v", err)
49 }
50 if err := stack.Restart(); err != nil {
51 log.Fatalf("Failed to restart the protocol stack: %v", err)
52 }
53 if err := stack.Stop(); err != nil {
54 log.Fatalf("Failed to stop the protocol stack: %v", err)
55 }
56 // Output:
57 // Service starting...
58 // Service stopping...
59 // Service starting...
60 // Service stopping...
61}

Callers

nothing calls this directly

Calls 4

RestartMethod · 0.80
StartMethod · 0.65
StopMethod · 0.65
RegisterMethod · 0.45

Tested by

no test coverage detected