func main() { services := []struct { uri string svc host.Service }{ // Examples { "/core/examples", host.NewFactoryServiceContext(&host.ExampleFactoryService{}), }, // Examples { "/core/ping", host.NewPingService(), }, } var err error flag.Parse() glog.Infof("Started with %s", os.Args[1:]) h := host.NewServiceHost() err = h.Initialize(bindAddress.String()) if err != nil { glog.Fatalf("Error initializing: %s\n", err) } ctx := operation.SetAuthorizationToken(context.Background(), authToken) _, err = host.GetServiceHostManagementState(ctx) if err != nil { glog.Fatalf("Error getting ServiceHostState: %s\n", err) } var ops []*operation.Operation for _, s := range services { op := operation.NewPost(ctx, uri.Extend(uri.Empty(), s.uri), nil) ops = append(ops, op) h.StartService(op, s.svc) } _, err = operation.Join(ops) if err != nil { glog.Fatalf("Error starting services: %s", err) } start(h) }
// StartServiceSync starts the specified service, synchronously. func (h *ServiceHost) StartServiceSync(path string, s Service) error { ctx := context.Background() startOp := operation.NewPost(ctx, uri.Extend(h.selfURI, path), nil) h.StartService(startOp, s) return startOp.Wait() }