IntPointgRPCServer.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package main
  2. import (
  3. "context"
  4. "log"
  5. gw "git.alfi.li/gamelang/proto_gorm/proto/gen/go" // Update
  6. _ "github.com/jinzhu/gorm/dialects/sqlite"
  7. "google.golang.org/grpc/codes"
  8. "google.golang.org/grpc/status"
  9. )
  10. type IntPointServiceServer struct {
  11. gw.UnimplementedIntPointServiceServer
  12. DBServer *gw.IntPointServiceDefaultServer
  13. }
  14. // NewIntPointServiceServer returns a gRPC server instance
  15. func NewIntPointServiceServer(db *gw.IntPointServiceDefaultServer) *IntPointServiceServer {
  16. IPS := IntPointServiceServer{DBServer: db}
  17. db.DB.AutoMigrate(&gw.IntPoint{})
  18. return &IPS
  19. }
  20. func (IPS IntPointServiceServer) Create(ctx context.Context, request *gw.CreateIntPointRequest) (*gw.CreateIntPointResponse, error) {
  21. response, err := IPS.DBServer.Create(ctx, request)
  22. if err != nil {
  23. log.Println(err.Error())
  24. return nil, status.Errorf(codes.Internal, err.Error())
  25. }
  26. return response, nil
  27. }
  28. func (IPS IntPointServiceServer) Read(ctx context.Context, request *gw.ReadIntPointRequest) (*gw.ReadIntPointResponse, error) {
  29. response, err := IPS.DBServer.Read(ctx, request)
  30. if err != nil {
  31. log.Println(err.Error())
  32. return nil, status.Errorf(codes.Internal, err.Error())
  33. }
  34. return response, nil
  35. }
  36. func (IPS IntPointServiceServer) Update(ctx context.Context, request *gw.UpdateIntPointRequest) (*gw.UpdateIntPointResponse, error) {
  37. response, err := IPS.DBServer.Update(ctx, request)
  38. if err != nil {
  39. log.Println(err.Error())
  40. return nil, status.Errorf(codes.Internal, err.Error())
  41. }
  42. return response, nil
  43. }
  44. func (IPS IntPointServiceServer) Delete(ctx context.Context, request *gw.DeleteIntPointRequest) (*gw.DeleteIntPointResponse, error) {
  45. response, err := IPS.DBServer.Delete(ctx, request)
  46. if err != nil {
  47. log.Println(err.Error())
  48. return nil, status.Errorf(codes.Internal, err.Error())
  49. }
  50. return response, nil
  51. }