You've already forked orderservice
chore: project refactoring
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
# Change all vars before going to production and remove all comments (!)
|
||||||
|
# Below all environment variables and default values
|
||||||
|
|
||||||
|
GRPC_PORT=50051
|
||||||
|
LOG_LEVEL=info
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
syntax = "proto3";
|
syntax = "proto3";
|
||||||
|
package order;
|
||||||
|
|
||||||
option go_package = "pkg/api/test";
|
option go_package = "pkg/api/order";
|
||||||
|
|
||||||
|
|
||||||
package api;
|
|
||||||
|
|
||||||
service OrderService {
|
service OrderService {
|
||||||
rpc CreateOrder(CreateOrderRequest) returns (CreateOrderResponse);
|
rpc CreateOrder(CreateOrderRequest) returns (CreateOrderResponse);
|
||||||
@@ -23,7 +21,6 @@ message CreateOrderRequest {
|
|||||||
string item = 1;
|
string item = 1;
|
||||||
int32 quantity = 2;
|
int32 quantity = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreateOrderResponse {
|
message CreateOrderResponse {
|
||||||
string id = 1;
|
string id = 1;
|
||||||
}
|
}
|
||||||
@@ -31,7 +28,6 @@ message CreateOrderResponse {
|
|||||||
message GetOrderRequest {
|
message GetOrderRequest {
|
||||||
string id = 1;
|
string id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message GetOrderResponse {
|
message GetOrderResponse {
|
||||||
Order order = 1;
|
Order order = 1;
|
||||||
}
|
}
|
||||||
@@ -41,7 +37,6 @@ message UpdateOrderRequest {
|
|||||||
string item = 2;
|
string item = 2;
|
||||||
int32 quantity = 3;
|
int32 quantity = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message UpdateOrderResponse {
|
message UpdateOrderResponse {
|
||||||
Order order = 1;
|
Order order = 1;
|
||||||
}
|
}
|
||||||
@@ -49,13 +44,11 @@ message UpdateOrderResponse {
|
|||||||
message DeleteOrderRequest {
|
message DeleteOrderRequest {
|
||||||
string id = 1;
|
string id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message DeleteOrderResponse {
|
message DeleteOrderResponse {
|
||||||
bool success = 1;
|
bool success = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListOrdersRequest {}
|
message ListOrdersRequest {}
|
||||||
|
|
||||||
message ListOrdersResponse {
|
message ListOrdersResponse {
|
||||||
repeated Order orders = 1;
|
repeated Order orders = 1;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"orderservice/internal/config"
|
||||||
|
"orderservice/internal/server"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
cfg, err := config.Load()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to load config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
srv := server.New(cfg)
|
||||||
|
srv.RegisterServices()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
if err := srv.Start(); err != nil {
|
||||||
|
log.Fatalf("Failed to start server: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
log.Printf("Server is running on port %d", cfg.GRPCPort)
|
||||||
|
|
||||||
|
select {}
|
||||||
|
}
|
||||||
@@ -6,8 +6,8 @@ toolchain go1.24.9
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
|
github.com/joho/godotenv v1.5.1
|
||||||
google.golang.org/grpc v1.76.0
|
google.golang.org/grpc v1.76.0
|
||||||
google.golang.org/protobuf v1.36.10
|
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@@ -15,4 +15,5 @@ require (
|
|||||||
golang.org/x/sys v0.34.0 // indirect
|
golang.org/x/sys v0.34.0 // indirect
|
||||||
golang.org/x/text v0.27.0 // indirect
|
golang.org/x/text v0.27.0 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250804133106-a7a43d27e69b // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20250804133106-a7a43d27e69b // indirect
|
||||||
|
google.golang.org/protobuf v1.36.10 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
|||||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
||||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
||||||
go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ=
|
go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ=
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/joho/godotenv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
GRPCPort int
|
||||||
|
LogLevel string
|
||||||
|
}
|
||||||
|
|
||||||
|
func Load() (*Config, error) {
|
||||||
|
if err := godotenv.Load(); err != nil {
|
||||||
|
log.Printf("Warning: .env file not found: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
config := &Config{}
|
||||||
|
|
||||||
|
portStr := getEnv("GRPC_PORT", "50051")
|
||||||
|
port, err := strconv.Atoi(portStr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.GRPCPort = port
|
||||||
|
|
||||||
|
config.LogLevel = getEnv("LOG_LEVEL", "info")
|
||||||
|
|
||||||
|
return config, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getEnv(key, defaultValue string) string {
|
||||||
|
if value := os.Getenv(key); value != "" {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
return defaultValue
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package interceptor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LoggerInterceptor struct{}
|
||||||
|
|
||||||
|
func NewLoggerInterceptor() *LoggerInterceptor {
|
||||||
|
return &LoggerInterceptor{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *LoggerInterceptor) Unary() grpc.UnaryServerInterceptor {
|
||||||
|
return func(
|
||||||
|
ctx context.Context,
|
||||||
|
req any,
|
||||||
|
info *grpc.UnaryServerInfo,
|
||||||
|
handler grpc.UnaryHandler,
|
||||||
|
) (any, error) {
|
||||||
|
start := time.Now()
|
||||||
|
|
||||||
|
log.Printf("gRPC method %s called", info.FullMethod)
|
||||||
|
log.Printf("Request: %+v", req)
|
||||||
|
|
||||||
|
resp, err := handler(ctx, req)
|
||||||
|
|
||||||
|
duration := time.Since(start)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if st, ok := status.FromError(err); ok {
|
||||||
|
log.Printf("Error: %s, Code: %s, Duration: %v",
|
||||||
|
st.Message(), st.Code(), duration)
|
||||||
|
} else {
|
||||||
|
log.Printf("Error: %v, Duration: %v", err, duration)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Printf("Response: %+v", resp)
|
||||||
|
log.Printf("Method %s completed in %v", info.FullMethod, duration)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *LoggerInterceptor) Stream() grpc.StreamServerInterceptor {
|
||||||
|
return func(
|
||||||
|
srv any,
|
||||||
|
stream grpc.ServerStream,
|
||||||
|
info *grpc.StreamServerInfo,
|
||||||
|
handler grpc.StreamHandler,
|
||||||
|
) error {
|
||||||
|
start := time.Now()
|
||||||
|
|
||||||
|
log.Printf("gRPC stream method %s started", info.FullMethod)
|
||||||
|
|
||||||
|
err := handler(srv, stream)
|
||||||
|
|
||||||
|
duration := time.Since(start)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Stream method %s failed: %v, Duration: %v",
|
||||||
|
info.FullMethod, err, duration)
|
||||||
|
} else {
|
||||||
|
log.Printf("Stream method %s completed in %v",
|
||||||
|
info.FullMethod, duration)
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"orderservice/internal/config"
|
||||||
|
"orderservice/internal/interceptor"
|
||||||
|
"orderservice/internal/service"
|
||||||
|
|
||||||
|
pb "orderservice/pkg/api/order"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Server struct {
|
||||||
|
grpcServer *grpc.Server
|
||||||
|
config *config.Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(cfg *config.Config) *Server {
|
||||||
|
loggerInterceptor := interceptor.NewLoggerInterceptor()
|
||||||
|
|
||||||
|
grpcServer := grpc.NewServer(
|
||||||
|
grpc.UnaryInterceptor(loggerInterceptor.Unary()),
|
||||||
|
grpc.StreamInterceptor(loggerInterceptor.Stream()),
|
||||||
|
)
|
||||||
|
|
||||||
|
return &Server{
|
||||||
|
grpcServer: grpcServer,
|
||||||
|
config: cfg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) RegisterServices() {
|
||||||
|
orderService := service.NewOrderServiceServer()
|
||||||
|
pb.RegisterOrderServiceServer(s.grpcServer, orderService)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) Start() error {
|
||||||
|
addr := fmt.Sprintf(":%d", s.config.GRPCPort)
|
||||||
|
lis, err := net.Listen("tcp", addr) //nolint:noctx // no need to use context here
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to listen: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Starting gRPC server on port %d", s.config.GRPCPort)
|
||||||
|
|
||||||
|
if err := s.grpcServer.Serve(lis); err != nil {
|
||||||
|
return fmt.Errorf("failed to serve: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) Stop() {
|
||||||
|
s.grpcServer.GracefulStop()
|
||||||
|
log.Println("gRPC server stopped gracefully")
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
pb "orderservice/pkg/api/order"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ErrOrderNotFound = errors.New("order not found")
|
||||||
|
|
||||||
|
func generateOrderID() string {
|
||||||
|
return uuid.NewString()
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrderServiceServer struct {
|
||||||
|
pb.UnimplementedOrderServiceServer
|
||||||
|
|
||||||
|
mu sync.RWMutex
|
||||||
|
orders map[string]*pb.Order
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewOrderServiceServer() *OrderServiceServer {
|
||||||
|
return &OrderServiceServer{
|
||||||
|
orders: make(map[string]*pb.Order),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *OrderServiceServer) CreateOrder(
|
||||||
|
_ context.Context,
|
||||||
|
req *pb.CreateOrderRequest,
|
||||||
|
) (*pb.CreateOrderResponse, error) {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
id := generateOrderID()
|
||||||
|
order := &pb.Order{
|
||||||
|
Id: id,
|
||||||
|
Item: req.GetItem(),
|
||||||
|
Quantity: req.GetQuantity(),
|
||||||
|
}
|
||||||
|
s.orders[id] = order
|
||||||
|
|
||||||
|
return &pb.CreateOrderResponse{Id: id}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *OrderServiceServer) GetOrder(_ context.Context, req *pb.GetOrderRequest) (*pb.GetOrderResponse, error) {
|
||||||
|
s.mu.RLock()
|
||||||
|
defer s.mu.RUnlock()
|
||||||
|
|
||||||
|
order, ok := s.orders[req.GetId()]
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrOrderNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.GetOrderResponse{Order: order}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *OrderServiceServer) UpdateOrder(
|
||||||
|
_ context.Context,
|
||||||
|
req *pb.UpdateOrderRequest,
|
||||||
|
) (*pb.UpdateOrderResponse, error) {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
order, ok := s.orders[req.GetId()]
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrOrderNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
order.Item = req.GetItem()
|
||||||
|
order.Quantity = req.GetQuantity()
|
||||||
|
|
||||||
|
return &pb.UpdateOrderResponse{Order: order}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *OrderServiceServer) DeleteOrder(
|
||||||
|
_ context.Context,
|
||||||
|
req *pb.DeleteOrderRequest,
|
||||||
|
) (*pb.DeleteOrderResponse, error) {
|
||||||
|
s.mu.Lock()
|
||||||
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
|
_, ok := s.orders[req.GetId()]
|
||||||
|
if !ok {
|
||||||
|
return nil, ErrOrderNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(s.orders, req.GetId())
|
||||||
|
|
||||||
|
return &pb.DeleteOrderResponse{Success: true}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *OrderServiceServer) ListOrders(
|
||||||
|
_ context.Context,
|
||||||
|
_ *pb.ListOrdersRequest,
|
||||||
|
) (*pb.ListOrdersResponse, error) {
|
||||||
|
s.mu.RLock()
|
||||||
|
defer s.mu.RUnlock()
|
||||||
|
|
||||||
|
orders := make([]*pb.Order, 0, len(s.orders))
|
||||||
|
for _, o := range s.orders {
|
||||||
|
orders = append(orders, o)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.ListOrdersResponse{Orders: orders}, nil
|
||||||
|
}
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
pb "orderservice/pkg/api/test"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"google.golang.org/grpc"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrOrderNotFound = errors.New("order not found")
|
|
||||||
)
|
|
||||||
|
|
||||||
type OrderServiceServer struct {
|
|
||||||
pb.UnimplementedOrderServiceServer
|
|
||||||
mu sync.RWMutex
|
|
||||||
orders map[string]*pb.Order
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewOrderServiceServer() *OrderServiceServer {
|
|
||||||
return &OrderServiceServer{
|
|
||||||
orders: make(map[string]*pb.Order),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *OrderServiceServer) CreateOrder(ctx context.Context, req *pb.CreateOrderRequest) (*pb.CreateOrderResponse, error) {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
|
|
||||||
id := uuid.New().String()
|
|
||||||
order := &pb.Order{
|
|
||||||
Id: id,
|
|
||||||
Item: req.Item,
|
|
||||||
Quantity: req.Quantity,
|
|
||||||
}
|
|
||||||
s.orders[id] = order
|
|
||||||
|
|
||||||
return &pb.CreateOrderResponse{Id: id}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *OrderServiceServer) GetOrder(ctx context.Context, req *pb.GetOrderRequest) (*pb.GetOrderResponse, error) {
|
|
||||||
s.mu.RLock()
|
|
||||||
defer s.mu.RUnlock()
|
|
||||||
|
|
||||||
order, ok := s.orders[req.Id]
|
|
||||||
if !ok {
|
|
||||||
return nil, ErrOrderNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return &pb.GetOrderResponse{Order: order}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *OrderServiceServer) UpdateOrder(ctx context.Context, req *pb.UpdateOrderRequest) (*pb.UpdateOrderResponse, error) {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
|
|
||||||
order, ok := s.orders[req.Id]
|
|
||||||
if !ok {
|
|
||||||
return nil, ErrOrderNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
order.Item = req.Item
|
|
||||||
order.Quantity = req.Quantity
|
|
||||||
|
|
||||||
return &pb.UpdateOrderResponse{Order: order}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *OrderServiceServer) DeleteOrder(ctx context.Context, req *pb.DeleteOrderRequest) (*pb.DeleteOrderResponse, error) {
|
|
||||||
s.mu.Lock()
|
|
||||||
defer s.mu.Unlock()
|
|
||||||
|
|
||||||
_, ok := s.orders[req.Id]
|
|
||||||
if !ok {
|
|
||||||
return nil, ErrOrderNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
delete(s.orders, req.Id)
|
|
||||||
|
|
||||||
return &pb.DeleteOrderResponse{Success: true}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *OrderServiceServer) ListOrders(ctx context.Context, req *pb.ListOrdersRequest) (*pb.ListOrdersResponse, error) {
|
|
||||||
s.mu.RLock()
|
|
||||||
defer s.mu.RUnlock()
|
|
||||||
|
|
||||||
orders := make([]*pb.Order, 0, len(s.orders))
|
|
||||||
for _, o := range s.orders {
|
|
||||||
orders = append(orders, o)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &pb.ListOrdersResponse{Orders: orders}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
port := flag.Int("port", 50051, "port to run grpc error on")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("failed to listen: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
s := grpc.NewServer()
|
|
||||||
pb.RegisterOrderServiceServer(s, NewOrderServiceServer())
|
|
||||||
|
|
||||||
log.Printf("server listening at %v", lis.Addr())
|
|
||||||
if err := s.Serve(lis); err != nil {
|
|
||||||
log.Fatalf("failed to serve: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,15 +4,14 @@
|
|||||||
// protoc v3.19.6
|
// protoc v3.19.6
|
||||||
// source: api/proto/order.proto
|
// source: api/proto/order.proto
|
||||||
|
|
||||||
package test
|
package order
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||||
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
sync "sync"
|
sync "sync"
|
||||||
unsafe "unsafe"
|
unsafe "unsafe"
|
||||||
|
|
||||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
|
||||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -542,7 +541,7 @@ var File_api_proto_order_proto protoreflect.FileDescriptor
|
|||||||
|
|
||||||
const file_api_proto_order_proto_rawDesc = "" +
|
const file_api_proto_order_proto_rawDesc = "" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"\x15api/proto/order.proto\x12\x03api\"G\n" +
|
"\x15api/proto/order.proto\x12\x05order\"G\n" +
|
||||||
"\x05Order\x12\x0e\n" +
|
"\x05Order\x12\x0e\n" +
|
||||||
"\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" +
|
"\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" +
|
||||||
"\x04item\x18\x02 \x01(\tR\x04item\x12\x1a\n" +
|
"\x04item\x18\x02 \x01(\tR\x04item\x12\x1a\n" +
|
||||||
@@ -553,32 +552,29 @@ const file_api_proto_order_proto_rawDesc = "" +
|
|||||||
"\x13CreateOrderResponse\x12\x0e\n" +
|
"\x13CreateOrderResponse\x12\x0e\n" +
|
||||||
"\x02id\x18\x01 \x01(\tR\x02id\"!\n" +
|
"\x02id\x18\x01 \x01(\tR\x02id\"!\n" +
|
||||||
"\x0fGetOrderRequest\x12\x0e\n" +
|
"\x0fGetOrderRequest\x12\x0e\n" +
|
||||||
"\x02id\x18\x01 \x01(\tR\x02id\"4\n" +
|
"\x02id\x18\x01 \x01(\tR\x02id\"6\n" +
|
||||||
"\x10GetOrderResponse\x12 \n" +
|
"\x10GetOrderResponse\x12\"\n" +
|
||||||
"\x05order\x18\x01 \x01(\v2\n" +
|
"\x05order\x18\x01 \x01(\v2\f.order.OrderR\x05order\"T\n" +
|
||||||
".api.OrderR\x05order\"T\n" +
|
|
||||||
"\x12UpdateOrderRequest\x12\x0e\n" +
|
"\x12UpdateOrderRequest\x12\x0e\n" +
|
||||||
"\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" +
|
"\x02id\x18\x01 \x01(\tR\x02id\x12\x12\n" +
|
||||||
"\x04item\x18\x02 \x01(\tR\x04item\x12\x1a\n" +
|
"\x04item\x18\x02 \x01(\tR\x04item\x12\x1a\n" +
|
||||||
"\bquantity\x18\x03 \x01(\x05R\bquantity\"7\n" +
|
"\bquantity\x18\x03 \x01(\x05R\bquantity\"9\n" +
|
||||||
"\x13UpdateOrderResponse\x12 \n" +
|
"\x13UpdateOrderResponse\x12\"\n" +
|
||||||
"\x05order\x18\x01 \x01(\v2\n" +
|
"\x05order\x18\x01 \x01(\v2\f.order.OrderR\x05order\"$\n" +
|
||||||
".api.OrderR\x05order\"$\n" +
|
|
||||||
"\x12DeleteOrderRequest\x12\x0e\n" +
|
"\x12DeleteOrderRequest\x12\x0e\n" +
|
||||||
"\x02id\x18\x01 \x01(\tR\x02id\"/\n" +
|
"\x02id\x18\x01 \x01(\tR\x02id\"/\n" +
|
||||||
"\x13DeleteOrderResponse\x12\x18\n" +
|
"\x13DeleteOrderResponse\x12\x18\n" +
|
||||||
"\asuccess\x18\x01 \x01(\bR\asuccess\"\x13\n" +
|
"\asuccess\x18\x01 \x01(\bR\asuccess\"\x13\n" +
|
||||||
"\x11ListOrdersRequest\"8\n" +
|
"\x11ListOrdersRequest\":\n" +
|
||||||
"\x12ListOrdersResponse\x12\"\n" +
|
"\x12ListOrdersResponse\x12$\n" +
|
||||||
"\x06orders\x18\x01 \x03(\v2\n" +
|
"\x06orders\x18\x01 \x03(\v2\f.order.OrderR\x06orders2\xe0\x02\n" +
|
||||||
".api.OrderR\x06orders2\xcc\x02\n" +
|
"\fOrderService\x12D\n" +
|
||||||
"\fOrderService\x12@\n" +
|
"\vCreateOrder\x12\x19.order.CreateOrderRequest\x1a\x1a.order.CreateOrderResponse\x12;\n" +
|
||||||
"\vCreateOrder\x12\x17.api.CreateOrderRequest\x1a\x18.api.CreateOrderResponse\x127\n" +
|
"\bGetOrder\x12\x16.order.GetOrderRequest\x1a\x17.order.GetOrderResponse\x12D\n" +
|
||||||
"\bGetOrder\x12\x14.api.GetOrderRequest\x1a\x15.api.GetOrderResponse\x12@\n" +
|
"\vUpdateOrder\x12\x19.order.UpdateOrderRequest\x1a\x1a.order.UpdateOrderResponse\x12D\n" +
|
||||||
"\vUpdateOrder\x12\x17.api.UpdateOrderRequest\x1a\x18.api.UpdateOrderResponse\x12@\n" +
|
"\vDeleteOrder\x12\x19.order.DeleteOrderRequest\x1a\x1a.order.DeleteOrderResponse\x12A\n" +
|
||||||
"\vDeleteOrder\x12\x17.api.DeleteOrderRequest\x1a\x18.api.DeleteOrderResponse\x12=\n" +
|
|
||||||
"\n" +
|
"\n" +
|
||||||
"ListOrders\x12\x16.api.ListOrdersRequest\x1a\x17.api.ListOrdersResponseB\x0eZ\fpkg/api/testb\x06proto3"
|
"ListOrders\x12\x18.order.ListOrdersRequest\x1a\x19.order.ListOrdersResponseB\x0fZ\rpkg/api/orderb\x06proto3"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
file_api_proto_order_proto_rawDescOnce sync.Once
|
file_api_proto_order_proto_rawDescOnce sync.Once
|
||||||
@@ -594,32 +590,32 @@ func file_api_proto_order_proto_rawDescGZIP() []byte {
|
|||||||
|
|
||||||
var file_api_proto_order_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
|
var file_api_proto_order_proto_msgTypes = make([]protoimpl.MessageInfo, 11)
|
||||||
var file_api_proto_order_proto_goTypes = []any{
|
var file_api_proto_order_proto_goTypes = []any{
|
||||||
(*Order)(nil), // 0: api.Order
|
(*Order)(nil), // 0: order.Order
|
||||||
(*CreateOrderRequest)(nil), // 1: api.CreateOrderRequest
|
(*CreateOrderRequest)(nil), // 1: order.CreateOrderRequest
|
||||||
(*CreateOrderResponse)(nil), // 2: api.CreateOrderResponse
|
(*CreateOrderResponse)(nil), // 2: order.CreateOrderResponse
|
||||||
(*GetOrderRequest)(nil), // 3: api.GetOrderRequest
|
(*GetOrderRequest)(nil), // 3: order.GetOrderRequest
|
||||||
(*GetOrderResponse)(nil), // 4: api.GetOrderResponse
|
(*GetOrderResponse)(nil), // 4: order.GetOrderResponse
|
||||||
(*UpdateOrderRequest)(nil), // 5: api.UpdateOrderRequest
|
(*UpdateOrderRequest)(nil), // 5: order.UpdateOrderRequest
|
||||||
(*UpdateOrderResponse)(nil), // 6: api.UpdateOrderResponse
|
(*UpdateOrderResponse)(nil), // 6: order.UpdateOrderResponse
|
||||||
(*DeleteOrderRequest)(nil), // 7: api.DeleteOrderRequest
|
(*DeleteOrderRequest)(nil), // 7: order.DeleteOrderRequest
|
||||||
(*DeleteOrderResponse)(nil), // 8: api.DeleteOrderResponse
|
(*DeleteOrderResponse)(nil), // 8: order.DeleteOrderResponse
|
||||||
(*ListOrdersRequest)(nil), // 9: api.ListOrdersRequest
|
(*ListOrdersRequest)(nil), // 9: order.ListOrdersRequest
|
||||||
(*ListOrdersResponse)(nil), // 10: api.ListOrdersResponse
|
(*ListOrdersResponse)(nil), // 10: order.ListOrdersResponse
|
||||||
}
|
}
|
||||||
var file_api_proto_order_proto_depIdxs = []int32{
|
var file_api_proto_order_proto_depIdxs = []int32{
|
||||||
0, // 0: api.GetOrderResponse.order:type_name -> api.Order
|
0, // 0: order.GetOrderResponse.order:type_name -> order.Order
|
||||||
0, // 1: api.UpdateOrderResponse.order:type_name -> api.Order
|
0, // 1: order.UpdateOrderResponse.order:type_name -> order.Order
|
||||||
0, // 2: api.ListOrdersResponse.orders:type_name -> api.Order
|
0, // 2: order.ListOrdersResponse.orders:type_name -> order.Order
|
||||||
1, // 3: api.OrderService.CreateOrder:input_type -> api.CreateOrderRequest
|
1, // 3: order.OrderService.CreateOrder:input_type -> order.CreateOrderRequest
|
||||||
3, // 4: api.OrderService.GetOrder:input_type -> api.GetOrderRequest
|
3, // 4: order.OrderService.GetOrder:input_type -> order.GetOrderRequest
|
||||||
5, // 5: api.OrderService.UpdateOrder:input_type -> api.UpdateOrderRequest
|
5, // 5: order.OrderService.UpdateOrder:input_type -> order.UpdateOrderRequest
|
||||||
7, // 6: api.OrderService.DeleteOrder:input_type -> api.DeleteOrderRequest
|
7, // 6: order.OrderService.DeleteOrder:input_type -> order.DeleteOrderRequest
|
||||||
9, // 7: api.OrderService.ListOrders:input_type -> api.ListOrdersRequest
|
9, // 7: order.OrderService.ListOrders:input_type -> order.ListOrdersRequest
|
||||||
2, // 8: api.OrderService.CreateOrder:output_type -> api.CreateOrderResponse
|
2, // 8: order.OrderService.CreateOrder:output_type -> order.CreateOrderResponse
|
||||||
4, // 9: api.OrderService.GetOrder:output_type -> api.GetOrderResponse
|
4, // 9: order.OrderService.GetOrder:output_type -> order.GetOrderResponse
|
||||||
6, // 10: api.OrderService.UpdateOrder:output_type -> api.UpdateOrderResponse
|
6, // 10: order.OrderService.UpdateOrder:output_type -> order.UpdateOrderResponse
|
||||||
8, // 11: api.OrderService.DeleteOrder:output_type -> api.DeleteOrderResponse
|
8, // 11: order.OrderService.DeleteOrder:output_type -> order.DeleteOrderResponse
|
||||||
10, // 12: api.OrderService.ListOrders:output_type -> api.ListOrdersResponse
|
10, // 12: order.OrderService.ListOrders:output_type -> order.ListOrdersResponse
|
||||||
8, // [8:13] is the sub-list for method output_type
|
8, // [8:13] is the sub-list for method output_type
|
||||||
3, // [3:8] is the sub-list for method input_type
|
3, // [3:8] is the sub-list for method input_type
|
||||||
3, // [3:3] is the sub-list for extension type_name
|
3, // [3:3] is the sub-list for extension type_name
|
||||||
@@ -4,11 +4,10 @@
|
|||||||
// - protoc v3.19.6
|
// - protoc v3.19.6
|
||||||
// source: api/proto/order.proto
|
// source: api/proto/order.proto
|
||||||
|
|
||||||
package test
|
package order
|
||||||
|
|
||||||
import (
|
import (
|
||||||
context "context"
|
context "context"
|
||||||
|
|
||||||
grpc "google.golang.org/grpc"
|
grpc "google.golang.org/grpc"
|
||||||
codes "google.golang.org/grpc/codes"
|
codes "google.golang.org/grpc/codes"
|
||||||
status "google.golang.org/grpc/status"
|
status "google.golang.org/grpc/status"
|
||||||
@@ -20,11 +19,11 @@ import (
|
|||||||
const _ = grpc.SupportPackageIsVersion9
|
const _ = grpc.SupportPackageIsVersion9
|
||||||
|
|
||||||
const (
|
const (
|
||||||
OrderService_CreateOrder_FullMethodName = "/api.OrderService/CreateOrder"
|
OrderService_CreateOrder_FullMethodName = "/order.OrderService/CreateOrder"
|
||||||
OrderService_GetOrder_FullMethodName = "/api.OrderService/GetOrder"
|
OrderService_GetOrder_FullMethodName = "/order.OrderService/GetOrder"
|
||||||
OrderService_UpdateOrder_FullMethodName = "/api.OrderService/UpdateOrder"
|
OrderService_UpdateOrder_FullMethodName = "/order.OrderService/UpdateOrder"
|
||||||
OrderService_DeleteOrder_FullMethodName = "/api.OrderService/DeleteOrder"
|
OrderService_DeleteOrder_FullMethodName = "/order.OrderService/DeleteOrder"
|
||||||
OrderService_ListOrders_FullMethodName = "/api.OrderService/ListOrders"
|
OrderService_ListOrders_FullMethodName = "/order.OrderService/ListOrders"
|
||||||
)
|
)
|
||||||
|
|
||||||
// OrderServiceClient is the client API for OrderService service.
|
// OrderServiceClient is the client API for OrderService service.
|
||||||
@@ -245,7 +244,7 @@ func _OrderService_ListOrders_Handler(srv interface{}, ctx context.Context, dec
|
|||||||
// It's only intended for direct use with grpc.RegisterService,
|
// It's only intended for direct use with grpc.RegisterService,
|
||||||
// and not to be introspected or modified (even as a copy)
|
// and not to be introspected or modified (even as a copy)
|
||||||
var OrderService_ServiceDesc = grpc.ServiceDesc{
|
var OrderService_ServiceDesc = grpc.ServiceDesc{
|
||||||
ServiceName: "api.OrderService",
|
ServiceName: "order.OrderService",
|
||||||
HandlerType: (*OrderServiceServer)(nil),
|
HandlerType: (*OrderServiceServer)(nil),
|
||||||
Methods: []grpc.MethodDesc{
|
Methods: []grpc.MethodDesc{
|
||||||
{
|
{
|
||||||
Reference in New Issue
Block a user