package archied import ( "google.golang.org/grpc" "github.com/samcharles93/archie-core/internal/app/servicekit" "github.com/samcharles93/archie-core/internal/config" "github.com/samcharles93/archie-core/internal/domain/presence" "github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc" "github.com/samcharles93/archie-core/internal/infrastructure/messagingrpc" ) // composeChatContract dials the standalone archie-gateway, the sole owner of // ChatContract, from the daemon's own configuration key. func composeChatContract(cfg config.Config, options ...grpc.DialOption) (*gatewayrpc.Client, func(), error) { target, err := cfg.Services.RequireTarget(config.ServiceNameGateway) if err != nil { return nil, nil, err } id, err := servicekit.Identity(cfg.TLS, presence.Daemon) if err != nil { return nil, nil, err } return gatewayrpc.Dial(target, id, options...) } // composeMessaging builds the Messaging Service client. The connection is // lazy, so an absent Messaging Service fails each delivery, not the daemon. func composeMessaging(cfg config.Config) (*messagingrpc.Client, func(), error) { target, err := cfg.Services.RequireTarget(config.ServiceNameMessaging) if err != nil { return nil, nil, err } id, err := servicekit.Identity(cfg.TLS, presence.Daemon) if err != nil { return nil, nil, err } return messagingrpc.Dial(target, id) }