package created
This commit is contained in:
parent
e249e23410
commit
ca36d84a03
4 changed files with 144 additions and 0 deletions
40
internal/taskAgent/handler.go
Normal file
40
internal/taskAgent/handler.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package taskAgent
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
tt "task-processor/pkg/taskTransport/v1"
|
||||
"time"
|
||||
)
|
||||
|
||||
const pkgLogHeader string = "Task agent |"
|
||||
|
||||
type Handler struct {
|
||||
client tt.TaskProcessorClient
|
||||
*service
|
||||
}
|
||||
|
||||
type Deps struct {
|
||||
Addr string
|
||||
Timeout time.Duration
|
||||
}
|
||||
|
||||
func NewHandler(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 := tt.NewTaskProcessorClient(conn)
|
||||
log.WithField("address", deps.Addr).Debugf("%v client", pkgLogHeader)
|
||||
|
||||
return &Handler{
|
||||
client: client,
|
||||
service: newService(client, deps.Timeout),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue