diff --git a/Makefile b/Makefile index 30783b6..0da6588 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,6 @@ mock: mockgen -package mockdb -destination db/mock/store.go github.com/cukhoaimon/SimpleBank/db/sqlc Store proto: - rm -f pb/*.go # remove all previous files protoc --proto_path=proto --go_out=pb --go_opt=paths=source_relative \ --go-grpc_out=pb --go-grpc_opt=paths=source_relative \ proto/*.proto @@ -43,4 +42,4 @@ proto: tidy: go mod tidy -.PHONY: postgres createdb dropdb migrate-up migrate-down sqlc test server mock dbdocs proto tidymake \ No newline at end of file +.PHONY: postgres createdb dropdb migrate-up migrate-down sqlc test server mock dbdocs proto tidy \ No newline at end of file diff --git a/app.env b/app.env index beb4e27..e6d3447 100644 --- a/app.env +++ b/app.env @@ -1,6 +1,7 @@ DB_DRIVER=postgres DB_SOURCE=postgresql://root:secret@localhost:5432/simple_bank?sslmode=disable -SERVER_ADDRESS=0.0.0.0:8080 +HTTP_SERVER_ADDRESS=0.0.0.0:8080 +GRPC_SERVER_ADDRESS=0.0.0.0:50051 TOKEN_SYMMETRIC_KEY=12345678901234567890123456789012 TOKEN_DURATION=15m REFRESH_TOKEN_DURATION=24h \ No newline at end of file diff --git a/gapi/converter.go b/gapi/converter.go new file mode 100644 index 0000000..27ae5cd --- /dev/null +++ b/gapi/converter.go @@ -0,0 +1,17 @@ +package gapi + +import ( + db "github.com/cukhoaimon/SimpleBank/db/sqlc" + "github.com/cukhoaimon/SimpleBank/pb" + "google.golang.org/protobuf/types/known/timestamppb" +) + +func convertUser(user db.User) *pb.User { + return &pb.User{ + Username: user.Username, + FullName: user.FullName, + Email: user.Email, + PasswordChangedAt: timestamppb.New(user.PasswordChangedAt), + CreatedAt: timestamppb.New(user.CreatedAt), + } +} diff --git a/gapi/rpc_create_user.go b/gapi/rpc_create_user.go new file mode 100644 index 0000000..a7cc304 --- /dev/null +++ b/gapi/rpc_create_user.go @@ -0,0 +1,44 @@ +package gapi + +import ( + "context" + "errors" + db "github.com/cukhoaimon/SimpleBank/db/sqlc" + "github.com/cukhoaimon/SimpleBank/pb" + "github.com/cukhoaimon/SimpleBank/utils" + "github.com/lib/pq" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (server *Server) CreateUser(ctx context.Context, req *pb.CreateUserRequest) (*pb.CreateUserResponse, error) { + hashedPassword, err := utils.HashPassword(req.GetPassword()) + if err != nil { + return nil, status.Errorf(codes.Internal, "fail to hash password: %s", err) + } + + arg := db.CreateUserParams{ + Username: req.GetUsername(), + HashedPassword: hashedPassword, + FullName: req.GetFullName(), + Email: req.GetEmail(), + } + + user, err := server.store.CreateUser(ctx, arg) + if err != nil { + var pqErr *pq.Error + if errors.As(err, &pqErr) { + switch pqErr.Code.Name() { + case "unique_violation": + return nil, status.Errorf(codes.AlreadyExists, "username already exists: %s", err) + } + } + + return nil, status.Errorf(codes.Internal, "fail to create user: %s", err) + } + + rsp := &pb.CreateUserResponse{ + User: convertUser(user), + } + return rsp, nil +} diff --git a/gapi/rpc_login_user.go b/gapi/rpc_login_user.go new file mode 100644 index 0000000..e704427 --- /dev/null +++ b/gapi/rpc_login_user.go @@ -0,0 +1,66 @@ +package gapi + +import ( + "context" + "database/sql" + "errors" + db "github.com/cukhoaimon/SimpleBank/db/sqlc" + "github.com/cukhoaimon/SimpleBank/pb" + "github.com/cukhoaimon/SimpleBank/utils" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/types/known/timestamppb" +) + +func (server *Server) LoginUser(ctx context.Context, req *pb.LoginUserRequest) (*pb.LoginUserResponse, error) { + user, err := server.store.GetUser(ctx, req.GetUsername()) + if err != nil { + if errors.Is(err, sql.ErrNoRows) { + return nil, status.Errorf(codes.NotFound, "user [%s] is not found in database", req.GetUsername()) + } + + return nil, status.Errorf(codes.Internal, "fail to get user [%s] from database", req.GetUsername()) + } + + err = utils.CheckPassword(req.Password, user.HashedPassword) + if err != nil { + return nil, status.Error(codes.Unauthenticated, "wrong password") + + } + + token, accessTokenPayload, err := server.tokenMaker.CreateToken(req.Username, server.config.TokenDuration) + if err != nil { + return nil, status.Error(codes.Internal, "fail to create access token") + } + + refreshToken, refreshTokenPayload, err := server.tokenMaker.CreateToken(req.Username, server.config.RefreshTokenDuration) + if err != nil { + return nil, status.Error(codes.Internal, "fail to create refresh access token") + } + + arg := db.CreateSessionParams{ + ID: accessTokenPayload.Id, + Username: accessTokenPayload.Username, + RefreshToken: refreshToken, + UserAgent: "", + ClientIp: "", + IsBlocked: false, + ExpiresAt: refreshTokenPayload.ExpiredAt, + } + + session, err := server.store.CreateSession(ctx, arg) + if err != nil { + return nil, status.Error(codes.Internal, "fail to create session") + } + + res := &pb.LoginUserResponse{ + SessionId: session.ID.String(), + AccessToken: token, + AccessTokenExpiresAt: timestamppb.New(accessTokenPayload.ExpiredAt), + RefreshToken: refreshToken, + RefreshTokenExpiresAt: timestamppb.New(refreshTokenPayload.ExpiredAt), + User: convertUser(user), + } + + return res, nil +} diff --git a/gapi/server.go b/gapi/server.go new file mode 100644 index 0000000..f53f619 --- /dev/null +++ b/gapi/server.go @@ -0,0 +1,32 @@ +package gapi + +import ( + db "github.com/cukhoaimon/SimpleBank/db/sqlc" + "github.com/cukhoaimon/SimpleBank/pb" + "github.com/cukhoaimon/SimpleBank/token" + "github.com/cukhoaimon/SimpleBank/utils" +) + +// Server serves gRPC request +type Server struct { + pb.UnimplementedSimpleBankServer + config utils.Config + tokenMaker token.Maker + store db.Store +} + +// NewServer will return new gRPC server +func NewServer(store db.Store, config utils.Config) (*Server, error) { + maker, err := token.NewPasetoMaker(config.TokenSymmetricKey) + if err != nil { + return nil, err + } + + server := &Server{ + store: store, + tokenMaker: maker, + config: config, + } + + return server, nil +} diff --git a/main.go b/main.go index 5f177aa..7e806f1 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,12 @@ package main import ( "database/sql" + "github.com/cukhoaimon/SimpleBank/gapi" + "github.com/cukhoaimon/SimpleBank/pb" + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" "log" + "net" "github.com/cukhoaimon/SimpleBank/api" db "github.com/cukhoaimon/SimpleBank/db/sqlc" @@ -24,12 +29,38 @@ func main() { } store := db.NewStore(conn) + runGRPCServer(store, config) +} + +func runGinServer(store db.Store, config utils.Config) { server, err := api.NewServer(store, config) if err != nil { log.Fatal("Cannot create server") } - if err = server.Start(config.ServerAddress); err != nil { + if err = server.Start(config.HttpServerAddress); err != nil { log.Fatal("Cannot start server") } } + +func runGRPCServer(store db.Store, config utils.Config) { + server, err := gapi.NewServer(store, config) + if err != nil { + log.Fatal("Cannot create gRPC server") + } + + gRPCServer := grpc.NewServer() + pb.RegisterSimpleBankServer(gRPCServer, server) + // allow client to know what RPCs currently available in server + reflection.Register(gRPCServer) + + listener, err := net.Listen("tcp", config.GrpcServerAddress) + if err != nil { + log.Fatal("Cannot create tcp-listener for gRPC server") + } + + log.Printf("start gRPC server at: %s", listener.Addr().String()) + if err = gRPCServer.Serve(listener); err != nil { + log.Fatal("Cannot serve gRPC server") + } +} diff --git a/pb/rpc_create_user.pb.go b/pb/rpc_create_user.pb.go index 7f4a713..11723f2 100644 --- a/pb/rpc_create_user.pb.go +++ b/pb/rpc_create_user.pb.go @@ -142,7 +142,7 @@ var File_rpc_create_user_proto protoreflect.FileDescriptor var file_rpc_create_user_proto_rawDesc = []byte{ 0x0a, 0x15, 0x72, 0x70, 0x63, 0x5f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x75, 0x73, 0x65, - 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x64, 0x62, 0x1a, 0x0a, 0x75, 0x73, 0x65, + 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62, 0x1a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x7e, 0x0a, 0x11, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, @@ -153,7 +153,7 @@ var file_rpc_create_user_proto_rawDesc = []byte{ 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x22, 0x32, 0x0a, 0x12, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, - 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x64, 0x62, + 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x42, 0x25, 0x5a, 0x23, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x75, 0x6b, 0x68, 0x6f, 0x61, 0x69, 0x6d, 0x6f, 0x6e, 0x2f, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x42, 0x61, 0x6e, 0x6b, 0x2f, @@ -174,12 +174,12 @@ func file_rpc_create_user_proto_rawDescGZIP() []byte { var file_rpc_create_user_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_rpc_create_user_proto_goTypes = []interface{}{ - (*CreateUserRequest)(nil), // 0: db.CreateUserRequest - (*CreateUserResponse)(nil), // 1: db.CreateUserResponse - (*User)(nil), // 2: db.User + (*CreateUserRequest)(nil), // 0: pb.CreateUserRequest + (*CreateUserResponse)(nil), // 1: pb.CreateUserResponse + (*User)(nil), // 2: pb.User } var file_rpc_create_user_proto_depIdxs = []int32{ - 2, // 0: db.CreateUserResponse.user:type_name -> db.User + 2, // 0: pb.CreateUserResponse.user:type_name -> pb.User 1, // [1:1] is the sub-list for method output_type 1, // [1:1] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name diff --git a/pb/rpc_login_user.pb.go b/pb/rpc_login_user.pb.go index 5b4760b..7208cbc 100644 --- a/pb/rpc_login_user.pb.go +++ b/pb/rpc_login_user.pb.go @@ -27,7 +27,7 @@ type LoginUserRequest struct { unknownFields protoimpl.UnknownFields Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` - FullName string `protobuf:"bytes,2,opt,name=full_name,json=fullName,proto3" json:"full_name,omitempty"` + Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"` } func (x *LoginUserRequest) Reset() { @@ -69,9 +69,9 @@ func (x *LoginUserRequest) GetUsername() string { return "" } -func (x *LoginUserRequest) GetFullName() string { +func (x *LoginUserRequest) GetPassword() string { if x != nil { - return x.FullName + return x.Password } return "" } @@ -82,11 +82,11 @@ type LoginUserResponse struct { unknownFields protoimpl.UnknownFields User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` - SessionID string `protobuf:"bytes,2,opt,name=SessionID,proto3" json:"SessionID,omitempty"` - AccessToken string `protobuf:"bytes,3,opt,name=AccessToken,proto3" json:"AccessToken,omitempty"` - RefreshToken string `protobuf:"bytes,4,opt,name=RefreshToken,proto3" json:"RefreshToken,omitempty"` - AccessTokenExpiresAt *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=AccessTokenExpiresAt,proto3" json:"AccessTokenExpiresAt,omitempty"` - RefreshTokenExpiresAt *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=RefreshTokenExpiresAt,proto3" json:"RefreshTokenExpiresAt,omitempty"` + SessionId string `protobuf:"bytes,2,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"` + AccessToken string `protobuf:"bytes,3,opt,name=access_token,json=accessToken,proto3" json:"access_token,omitempty"` + RefreshToken string `protobuf:"bytes,4,opt,name=refresh_token,json=refreshToken,proto3" json:"refresh_token,omitempty"` + AccessTokenExpiresAt *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=access_token_expires_at,json=accessTokenExpiresAt,proto3" json:"access_token_expires_at,omitempty"` + RefreshTokenExpiresAt *timestamppb.Timestamp `protobuf:"bytes,6,opt,name=refresh_token_expires_at,json=refreshTokenExpiresAt,proto3" json:"refresh_token_expires_at,omitempty"` } func (x *LoginUserResponse) Reset() { @@ -128,9 +128,9 @@ func (x *LoginUserResponse) GetUser() *User { return nil } -func (x *LoginUserResponse) GetSessionID() string { +func (x *LoginUserResponse) GetSessionId() string { if x != nil { - return x.SessionID + return x.SessionId } return "" } @@ -167,37 +167,38 @@ var File_rpc_login_user_proto protoreflect.FileDescriptor var file_rpc_login_user_proto_rawDesc = []byte{ 0x0a, 0x14, 0x72, 0x70, 0x63, 0x5f, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x5f, 0x75, 0x73, 0x65, 0x72, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x64, 0x62, 0x1a, 0x0a, 0x75, 0x73, 0x65, 0x72, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62, 0x1a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, - 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x4b, 0x0a, 0x10, 0x4c, 0x6f, 0x67, 0x69, 0x6e, + 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x4a, 0x0a, 0x10, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, - 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x66, 0x75, 0x6c, 0x6c, 0x5f, - 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x75, 0x6c, 0x6c, - 0x4e, 0x61, 0x6d, 0x65, 0x22, 0xb7, 0x02, 0x0a, 0x11, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x55, 0x73, - 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x04, 0x75, 0x73, - 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x64, 0x62, 0x2e, 0x55, 0x73, - 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x1c, 0x0a, 0x09, 0x53, 0x65, 0x73, 0x73, - 0x69, 0x6f, 0x6e, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x53, 0x65, 0x73, - 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x44, 0x12, 0x20, 0x0a, 0x0b, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, - 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x41, 0x63, 0x63, - 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x22, 0x0a, 0x0c, 0x52, 0x65, 0x66, 0x72, - 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, - 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x4e, 0x0a, 0x14, - 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x45, 0x78, 0x70, 0x69, 0x72, - 0x65, 0x73, 0x41, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, - 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x14, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, - 0x6b, 0x65, 0x6e, 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x41, 0x74, 0x12, 0x50, 0x0a, 0x15, - 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x45, 0x78, 0x70, 0x69, - 0x72, 0x65, 0x73, 0x41, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, - 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x15, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, - 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x41, 0x74, 0x42, 0x25, - 0x5a, 0x23, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x75, 0x6b, - 0x68, 0x6f, 0x61, 0x69, 0x6d, 0x6f, 0x6e, 0x2f, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x42, 0x61, - 0x6e, 0x6b, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, + 0x6f, 0x72, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x61, 0x73, 0x73, 0x77, + 0x6f, 0x72, 0x64, 0x22, 0xc0, 0x02, 0x0a, 0x11, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x55, 0x73, 0x65, + 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x04, 0x75, 0x73, 0x65, + 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, + 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x65, 0x73, 0x73, 0x69, + 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x65, 0x73, + 0x73, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, + 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x63, + 0x63, 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x66, + 0x72, 0x65, 0x73, 0x68, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0c, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x12, 0x51, + 0x0a, 0x17, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x5f, 0x65, + 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x5f, 0x61, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x14, 0x61, 0x63, 0x63, + 0x65, 0x73, 0x73, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x45, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x41, + 0x74, 0x12, 0x53, 0x0a, 0x18, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x5f, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x5f, 0x65, 0x78, 0x70, 0x69, 0x72, 0x65, 0x73, 0x5f, 0x61, 0x74, 0x18, 0x06, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, + 0x15, 0x72, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x45, 0x78, 0x70, + 0x69, 0x72, 0x65, 0x73, 0x41, 0x74, 0x42, 0x25, 0x5a, 0x23, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x75, 0x6b, 0x68, 0x6f, 0x61, 0x69, 0x6d, 0x6f, 0x6e, 0x2f, + 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x42, 0x61, 0x6e, 0x6b, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -214,15 +215,15 @@ func file_rpc_login_user_proto_rawDescGZIP() []byte { var file_rpc_login_user_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_rpc_login_user_proto_goTypes = []interface{}{ - (*LoginUserRequest)(nil), // 0: db.LoginUserRequest - (*LoginUserResponse)(nil), // 1: db.LoginUserResponse - (*User)(nil), // 2: db.User + (*LoginUserRequest)(nil), // 0: pb.LoginUserRequest + (*LoginUserResponse)(nil), // 1: pb.LoginUserResponse + (*User)(nil), // 2: pb.User (*timestamppb.Timestamp)(nil), // 3: google.protobuf.Timestamp } var file_rpc_login_user_proto_depIdxs = []int32{ - 2, // 0: db.LoginUserResponse.user:type_name -> db.User - 3, // 1: db.LoginUserResponse.AccessTokenExpiresAt:type_name -> google.protobuf.Timestamp - 3, // 2: db.LoginUserResponse.RefreshTokenExpiresAt:type_name -> google.protobuf.Timestamp + 2, // 0: pb.LoginUserResponse.user:type_name -> pb.User + 3, // 1: pb.LoginUserResponse.access_token_expires_at:type_name -> google.protobuf.Timestamp + 3, // 2: pb.LoginUserResponse.refresh_token_expires_at:type_name -> google.protobuf.Timestamp 3, // [3:3] is the sub-list for method output_type 3, // [3:3] is the sub-list for method input_type 3, // [3:3] is the sub-list for extension type_name diff --git a/pb/service_simple_bank.pb.go b/pb/service_simple_bank.pb.go index fe4d46d..5bef963 100644 --- a/pb/service_simple_bank.pb.go +++ b/pb/service_simple_bank.pb.go @@ -23,18 +23,18 @@ var File_service_simple_bank_proto protoreflect.FileDescriptor var file_service_simple_bank_proto_rawDesc = []byte{ 0x0a, 0x19, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x5f, 0x73, 0x69, 0x6d, 0x70, 0x6c, 0x65, - 0x5f, 0x62, 0x61, 0x6e, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x64, 0x62, 0x1a, + 0x5f, 0x62, 0x61, 0x6e, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62, 0x1a, 0x15, 0x72, 0x70, 0x63, 0x5f, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x14, 0x72, 0x70, 0x63, 0x5f, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x5f, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0x87, 0x01, 0x0a, 0x0a, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x42, 0x61, 0x6e, 0x6b, 0x12, 0x3d, 0x0a, 0x0a, 0x43, - 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x15, 0x2e, 0x64, 0x62, 0x2e, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x15, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x16, 0x2e, 0x64, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, + 0x1a, 0x16, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3a, 0x0a, 0x09, 0x4c, 0x6f, - 0x67, 0x69, 0x6e, 0x55, 0x73, 0x65, 0x72, 0x12, 0x14, 0x2e, 0x64, 0x62, 0x2e, 0x4c, 0x6f, 0x67, + 0x67, 0x69, 0x6e, 0x55, 0x73, 0x65, 0x72, 0x12, 0x14, 0x2e, 0x70, 0x62, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, - 0x64, 0x62, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, + 0x70, 0x62, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x25, 0x5a, 0x23, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x75, 0x6b, 0x68, 0x6f, 0x61, 0x69, 0x6d, 0x6f, 0x6e, 0x2f, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x42, 0x61, 0x6e, 0x6b, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, @@ -42,16 +42,16 @@ var file_service_simple_bank_proto_rawDesc = []byte{ } var file_service_simple_bank_proto_goTypes = []interface{}{ - (*CreateUserRequest)(nil), // 0: db.CreateUserRequest - (*LoginUserRequest)(nil), // 1: db.LoginUserRequest - (*CreateUserResponse)(nil), // 2: db.CreateUserResponse - (*LoginUserResponse)(nil), // 3: db.LoginUserResponse + (*CreateUserRequest)(nil), // 0: pb.CreateUserRequest + (*LoginUserRequest)(nil), // 1: pb.LoginUserRequest + (*CreateUserResponse)(nil), // 2: pb.CreateUserResponse + (*LoginUserResponse)(nil), // 3: pb.LoginUserResponse } var file_service_simple_bank_proto_depIdxs = []int32{ - 0, // 0: db.SimpleBank.CreateUser:input_type -> db.CreateUserRequest - 1, // 1: db.SimpleBank.LoginUser:input_type -> db.LoginUserRequest - 2, // 2: db.SimpleBank.CreateUser:output_type -> db.CreateUserResponse - 3, // 3: db.SimpleBank.LoginUser:output_type -> db.LoginUserResponse + 0, // 0: pb.SimpleBank.CreateUser:input_type -> pb.CreateUserRequest + 1, // 1: pb.SimpleBank.LoginUser:input_type -> pb.LoginUserRequest + 2, // 2: pb.SimpleBank.CreateUser:output_type -> pb.CreateUserResponse + 3, // 3: pb.SimpleBank.LoginUser:output_type -> pb.LoginUserResponse 2, // [2:4] is the sub-list for method output_type 0, // [0:2] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name diff --git a/pb/service_simple_bank_grpc.pb.go b/pb/service_simple_bank_grpc.pb.go index dffdb33..bcd5758 100644 --- a/pb/service_simple_bank_grpc.pb.go +++ b/pb/service_simple_bank_grpc.pb.go @@ -36,7 +36,7 @@ func NewSimpleBankClient(cc grpc.ClientConnInterface) SimpleBankClient { func (c *simpleBankClient) CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*CreateUserResponse, error) { out := new(CreateUserResponse) - err := c.cc.Invoke(ctx, "/db.SimpleBank/CreateUser", in, out, opts...) + err := c.cc.Invoke(ctx, "/pb.SimpleBank/CreateUser", in, out, opts...) if err != nil { return nil, err } @@ -45,7 +45,7 @@ func (c *simpleBankClient) CreateUser(ctx context.Context, in *CreateUserRequest func (c *simpleBankClient) LoginUser(ctx context.Context, in *LoginUserRequest, opts ...grpc.CallOption) (*LoginUserResponse, error) { out := new(LoginUserResponse) - err := c.cc.Invoke(ctx, "/db.SimpleBank/LoginUser", in, out, opts...) + err := c.cc.Invoke(ctx, "/pb.SimpleBank/LoginUser", in, out, opts...) if err != nil { return nil, err } @@ -94,7 +94,7 @@ func _SimpleBank_CreateUser_Handler(srv interface{}, ctx context.Context, dec fu } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/db.SimpleBank/CreateUser", + FullMethod: "/pb.SimpleBank/CreateUser", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(SimpleBankServer).CreateUser(ctx, req.(*CreateUserRequest)) @@ -112,7 +112,7 @@ func _SimpleBank_LoginUser_Handler(srv interface{}, ctx context.Context, dec fun } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/db.SimpleBank/LoginUser", + FullMethod: "/pb.SimpleBank/LoginUser", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { return srv.(SimpleBankServer).LoginUser(ctx, req.(*LoginUserRequest)) @@ -124,7 +124,7 @@ func _SimpleBank_LoginUser_Handler(srv interface{}, ctx context.Context, dec fun // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) var SimpleBank_ServiceDesc = grpc.ServiceDesc{ - ServiceName: "db.SimpleBank", + ServiceName: "pb.SimpleBank", HandlerType: (*SimpleBankServer)(nil), Methods: []grpc.MethodDesc{ { diff --git a/pb/user.pb.go b/pb/user.pb.go index d0aac59..3d1ff2a 100644 --- a/pb/user.pb.go +++ b/pb/user.pb.go @@ -29,7 +29,7 @@ type User struct { Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"` FullName string `protobuf:"bytes,2,opt,name=full_name,json=fullName,proto3" json:"full_name,omitempty"` Email string `protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"` - PassWordChangedAt *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=pass_word_changed_at,json=passWordChangedAt,proto3" json:"pass_word_changed_at,omitempty"` + PasswordChangedAt *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=password_changed_at,json=passwordChangedAt,proto3" json:"password_changed_at,omitempty"` CreatedAt *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"` } @@ -86,9 +86,9 @@ func (x *User) GetEmail() string { return "" } -func (x *User) GetPassWordChangedAt() *timestamppb.Timestamp { +func (x *User) GetPasswordChangedAt() *timestamppb.Timestamp { if x != nil { - return x.PassWordChangedAt + return x.PasswordChangedAt } return nil } @@ -103,26 +103,26 @@ func (x *User) GetCreatedAt() *timestamppb.Timestamp { var File_user_proto protoreflect.FileDescriptor var file_user_proto_rawDesc = []byte{ - 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x64, 0x62, + 0x0a, 0x0a, 0x75, 0x73, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70, 0x62, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x22, 0xdd, 0x01, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, + 0x6f, 0x22, 0xdc, 0x01, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x1a, 0x0a, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x66, 0x75, 0x6c, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x75, 0x6c, 0x6c, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x4b, 0x0a, 0x14, 0x70, 0x61, 0x73, - 0x73, 0x5f, 0x77, 0x6f, 0x72, 0x64, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x5f, 0x61, - 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, - 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, - 0x61, 0x6d, 0x70, 0x52, 0x11, 0x70, 0x61, 0x73, 0x73, 0x57, 0x6f, 0x72, 0x64, 0x43, 0x68, 0x61, - 0x6e, 0x67, 0x65, 0x64, 0x41, 0x74, 0x12, 0x39, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, - 0x64, 0x5f, 0x61, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, - 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, - 0x74, 0x42, 0x25, 0x5a, 0x23, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, - 0x63, 0x75, 0x6b, 0x68, 0x6f, 0x61, 0x69, 0x6d, 0x6f, 0x6e, 0x2f, 0x53, 0x69, 0x6d, 0x70, 0x6c, - 0x65, 0x42, 0x61, 0x6e, 0x6b, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x4a, 0x0a, 0x13, 0x70, 0x61, 0x73, + 0x73, 0x77, 0x6f, 0x72, 0x64, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x5f, 0x61, 0x74, + 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, + 0x6d, 0x70, 0x52, 0x11, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x43, 0x68, 0x61, 0x6e, + 0x67, 0x65, 0x64, 0x41, 0x74, 0x12, 0x39, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, + 0x5f, 0x61, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, + 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, + 0x42, 0x25, 0x5a, 0x23, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, + 0x75, 0x6b, 0x68, 0x6f, 0x61, 0x69, 0x6d, 0x6f, 0x6e, 0x2f, 0x53, 0x69, 0x6d, 0x70, 0x6c, 0x65, + 0x42, 0x61, 0x6e, 0x6b, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -139,12 +139,12 @@ func file_user_proto_rawDescGZIP() []byte { var file_user_proto_msgTypes = make([]protoimpl.MessageInfo, 1) var file_user_proto_goTypes = []interface{}{ - (*User)(nil), // 0: db.User + (*User)(nil), // 0: pb.User (*timestamppb.Timestamp)(nil), // 1: google.protobuf.Timestamp } var file_user_proto_depIdxs = []int32{ - 1, // 0: db.User.pass_word_changed_at:type_name -> google.protobuf.Timestamp - 1, // 1: db.User.created_at:type_name -> google.protobuf.Timestamp + 1, // 0: pb.User.password_changed_at:type_name -> google.protobuf.Timestamp + 1, // 1: pb.User.created_at:type_name -> google.protobuf.Timestamp 2, // [2:2] is the sub-list for method output_type 2, // [2:2] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name diff --git a/proto/rpc_create_user.proto b/proto/rpc_create_user.proto index acfc02d..969c3ec 100644 --- a/proto/rpc_create_user.proto +++ b/proto/rpc_create_user.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package db; +package pb; import "user.proto"; diff --git a/proto/rpc_login_user.proto b/proto/rpc_login_user.proto index 37d6926..eec0bf8 100644 --- a/proto/rpc_login_user.proto +++ b/proto/rpc_login_user.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package db; +package pb; import "user.proto"; import "google/protobuf/timestamp.proto"; @@ -9,14 +9,14 @@ option go_package = "github.com/cukhoaimon/SimpleBank/pb"; message LoginUserRequest { string username = 1; - string full_name = 2; + string password = 2; } message LoginUserResponse { User user = 1; - string SessionID = 2; - string AccessToken = 3; - string RefreshToken = 4; - google.protobuf.Timestamp AccessTokenExpiresAt = 5; - google.protobuf.Timestamp RefreshTokenExpiresAt = 6; + string session_id = 2; + string access_token = 3; + string refresh_token = 4; + google.protobuf.Timestamp access_token_expires_at = 5; + google.protobuf.Timestamp refresh_token_expires_at = 6; } \ No newline at end of file diff --git a/proto/service_simple_bank.proto b/proto/service_simple_bank.proto index e66c034..22e61b4 100644 --- a/proto/service_simple_bank.proto +++ b/proto/service_simple_bank.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package db; +package pb; import "rpc_create_user.proto"; import "rpc_login_user.proto"; @@ -10,4 +10,5 @@ option go_package = "github.com/cukhoaimon/SimpleBank/pb"; service SimpleBank { rpc CreateUser (CreateUserRequest) returns (CreateUserResponse) {} rpc LoginUser (LoginUserRequest) returns (LoginUserResponse) {} -} \ No newline at end of file +} + diff --git a/proto/user.proto b/proto/user.proto index 4b7936b..1fa69c4 100644 --- a/proto/user.proto +++ b/proto/user.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package db; +package pb; import "google/protobuf/timestamp.proto"; @@ -10,6 +10,6 @@ message User { string username = 1; string full_name = 2; string email = 3; - google.protobuf.Timestamp pass_word_changed_at = 4; + google.protobuf.Timestamp password_changed_at = 4; google.protobuf.Timestamp created_at = 5; } diff --git a/utils/config.go b/utils/config.go index a1633ae..0018bca 100644 --- a/utils/config.go +++ b/utils/config.go @@ -8,7 +8,8 @@ import ( type Config struct { DBDriver string `mapstructure:"DB_DRIVER"` DBSource string `mapstructure:"DB_SOURCE"` - ServerAddress string `mapstructure:"SERVER_ADDRESS"` + HttpServerAddress string `mapstructure:"HTTP_SERVER_ADDRESS"` + GrpcServerAddress string `mapstructure:"GRPC_SERVER_ADDRESS"` TokenDuration time.Duration `mapstructure:"TOKEN_DURATION"` RefreshTokenDuration time.Duration `mapstructure:"REFRESH_TOKEN_DURATION"` TokenSymmetricKey string `mapstructure:"TOKEN_SYMMETRIC_KEY"`