29 lines
647 B
Go
29 lines
647 B
Go
|
|
package server
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"myschools.me/wyh/grpcservice/model"
|
||
|
|
"myschools.me/wyh/grpcservice/pb"
|
||
|
|
)
|
||
|
|
|
||
|
|
type ProductService struct {
|
||
|
|
pb.UnimplementedProductServiceServer
|
||
|
|
}
|
||
|
|
|
||
|
|
func (server *ProductService) GetProductStock(ctx context.Context, request *pb.ProductRequest) (*pb.ProductResponse, error) {
|
||
|
|
tokenany := ctx.Value("token")
|
||
|
|
token, ok := tokenany.(*model.Token)
|
||
|
|
if !ok {
|
||
|
|
return &pb.ProductResponse{ProdStock: 60}, nil
|
||
|
|
}
|
||
|
|
stcok := server.GetStockByID(request.ProdId)
|
||
|
|
fmt.Println(token)
|
||
|
|
return &pb.ProductResponse{ProdStock: stcok}, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (server *ProductService) GetStockByID(prodid int32) int32 {
|
||
|
|
return 100
|
||
|
|
}
|