You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.2 KiB
65 lines
1.2 KiB
package grpc
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"sync"
|
|
api "test3k/authDB/pkg/api"
|
|
|
|
kafka "github.com/segmentio/kafka-go"
|
|
)
|
|
|
|
type user struct {
|
|
Code string
|
|
Login string
|
|
Password string
|
|
}
|
|
|
|
type GRPCServer struct {
|
|
mu sync.Mutex
|
|
users map[string]user
|
|
api.UnimplementedAuthDBServer
|
|
}
|
|
|
|
func NewGRPCServer() *GRPCServer {
|
|
return &GRPCServer{
|
|
mu: sync.Mutex{},
|
|
users: make(map[string]user),
|
|
}
|
|
}
|
|
|
|
func (s *GRPCServer) Login(context.Context, *api.LoginRequest) (*api.LoginResponse, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (s *GRPCServer) Registration(context.Context, *api.RegistrationRequest) (*api.RegistrationResponse, error) {
|
|
ctx := context.Background()
|
|
consumer := kafka.NewReader(kafka.ReaderConfig{
|
|
Brokers: []string{"localhost:9092"},
|
|
Topic: "topic-A",
|
|
Partition: 0,
|
|
MinBytes: 10e3, // 10KB
|
|
MaxBytes: 10e6, // 10MB
|
|
})
|
|
defer consumer.Close()
|
|
|
|
//
|
|
// consumer.SetOffset(42)
|
|
|
|
//
|
|
for {
|
|
m, err := consumer.ReadMessage(ctx)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
fmt.Printf("message at offset %d: %s = %s\n", m.Offset, string(m.Key), string(m.Value))
|
|
}
|
|
|
|
return nil, nil
|
|
}
|
|
|
|
func (s *GRPCServer) Confirmation(context.Context, *api.ConfirmationRequest) (*api.ConfirmationResponse, error) {
|
|
return nil, nil
|
|
}
|
|
|