41 lines
890 B
Go
41 lines
890 B
Go
|
|
package authReg
|
||
|
|
|
||
|
|
import (
|
||
|
|
log "github.com/sirupsen/logrus"
|
||
|
|
"google.golang.org/grpc"
|
||
|
|
"google.golang.org/grpc/credentials/insecure"
|
||
|
|
er "merch-api/pkg/externalRegistration/v1"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
const pkgLogHeader string = "External service registration |"
|
||
|
|
|
||
|
|
type Handler struct {
|
||
|
|
client er.ExternalRegistrationClient
|
||
|
|
*service
|
||
|
|
}
|
||
|
|
|
||
|
|
type Deps struct {
|
||
|
|
Addr string
|
||
|
|
Timeout time.Duration
|
||
|
|
}
|
||
|
|
|
||
|
|
func New(deps Deps) *Handler {
|
||
|
|
var opts []grpc.DialOption
|
||
|
|
insec := grpc.WithTransportCredentials(insecure.NewCredentials())
|
||
|
|
opts = append(opts, insec)
|
||
|
|
|
||
|
|
conn, err := grpc.NewClient(deps.Addr, opts...)
|
||
|
|
if err != nil {
|
||
|
|
log.WithError(err).Fatalf("%v grpc connection failed", pkgLogHeader)
|
||
|
|
}
|
||
|
|
|
||
|
|
client := er.NewExternalRegistrationClient(conn)
|
||
|
|
log.WithField("address", deps.Addr).Debugf("%v client", pkgLogHeader)
|
||
|
|
|
||
|
|
return &Handler{
|
||
|
|
client: client,
|
||
|
|
service: newService(client, deps.Timeout),
|
||
|
|
}
|
||
|
|
}
|