Beispiel #1
0
// 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
}
Beispiel #2
0
// NewService -
func NewService(opts options.Options, logger *logging.Entry) (*Service, error) {

	serv, err := services.New(opts)

	if err != nil {
		return nil, err
	}

	_, ok := opts.Get("slack-team-name")

	if !ok {
		return nil, errors.New("You need to provide `slack-team-name` in order to start service...")
	}

	slackToken, ok := opts.Get("slack-token")

	if !ok {
		return nil, errors.New("You need to provide `slack-token` in order to start service...")
	}

	slackDebug, ok := opts.Get("slack-api-debug")

	if !ok {
		return nil, errors.New("You need to provide `slack-api-debug` in order to start service...")
	}

	grpcServer, err := servers.NewGrpcServer(serv, opts, logger)

	if err != nil {
		return nil, err
	}

	restServer, err := servers.NewGrpcRestServer(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("rest", restServer); 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,
		REST:      restServer,
		Entry:     logger,
		Managerer: serviceManager,
		Slack:     NewSlack(slackToken.String(), slackDebug.Bool()),
	}

	pb.RegisterSlackServer(sc.GrpcServer(), sc)

	return sc, nil
}