func main() { logger.Info("Starting service ...") slackinvite, err := NewService(opts, logger) if err != nil { logger.Fatalf("Could not create service. (err: %s)", err) } resthandler, err := handlers.NewHttpGrpcHandler(slackinvite, logger, pb.RegisterSlackHandler) if err != nil { logger.Fatalf("Could not create new grpc handler (err: %s)", err) } httphandler := http.NewServeMux() httphandler.HandleFunc("/", IndexHandler) httphandler.Handle("/public/", http.StripPrefix("/public/", http.FileServer(http.Dir("public")))) slackinvite.RESTServer().SetHandler("/", resthandler) slackinvite.HTTPServer().SetHandler("/", httphandler) if err := slackinvite.Start(); err != nil { logger.Fatalf("Failed to start service. (err: %s)", err) } }
// NewService - func NewService(opts options.Options, logger *logging.Entry) (*Service, error) { serv, err := services.New(opts) if err != nil { return nil, err } grpcServer, err := servers.NewGrpcServer(serv, opts, logger) if err != nil { return nil, err } httpServer, err := servers.NewHTTPServer(serv, opts, logger) if err != nil { return nil, err } serviceManager, err := managers.New(serv, opts, logger) if err != nil { return nil, err } // We are about to attach GRPC service now ... if err := serviceManager.Attach("grpc", grpcServer); err != nil { return nil, err } // We are about to attach HTTP service now ... if err := serviceManager.Attach("http", httpServer); err != nil { return nil, err } sc := &Service{ Options: opts, Servicer: serv, Grpc: grpcServer, HTTP: httpServer, Entry: logger, Managerer: serviceManager, } pb.RegisterHelloServer(sc.GrpcServer(), sc) hander, err := handlers.NewHttpGrpcHandler(serv, logger, pb.RegisterHelloHandler) if err != nil { return nil, err } httpServer.Interface().(*servers.HTTP).Handler = hander return sc, nil }