12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package main
- import (
- "context"
- "log"
- gw "git.alfi.li/gamelang/proto_gorm/proto/gen/go" // Update
- _ "github.com/jinzhu/gorm/dialects/sqlite"
- "google.golang.org/grpc/codes"
- "google.golang.org/grpc/status"
- )
- type IntPointServiceServer struct {
- gw.UnimplementedIntPointServiceServer
- DBServer *gw.IntPointServiceDefaultServer
- }
- // NewIntPointServiceServer returns a gRPC server instance
- func NewIntPointServiceServer(db *gw.IntPointServiceDefaultServer) *IntPointServiceServer {
- IPS := IntPointServiceServer{DBServer: db}
- db.DB.AutoMigrate(&gw.IntPoint{})
- return &IPS
- }
- func (IPS IntPointServiceServer) Create(ctx context.Context, request *gw.CreateIntPointRequest) (*gw.CreateIntPointResponse, error) {
- response, err := IPS.DBServer.Create(ctx, request)
- if err != nil {
- log.Println(err.Error())
- return nil, status.Errorf(codes.Internal, err.Error())
- }
- return response, nil
- }
- func (IPS IntPointServiceServer) Read(ctx context.Context, request *gw.ReadIntPointRequest) (*gw.ReadIntPointResponse, error) {
- response, err := IPS.DBServer.Read(ctx, request)
- if err != nil {
- log.Println(err.Error())
- return nil, status.Errorf(codes.Internal, err.Error())
- }
- return response, nil
- }
- func (IPS IntPointServiceServer) Update(ctx context.Context, request *gw.UpdateIntPointRequest) (*gw.UpdateIntPointResponse, error) {
- response, err := IPS.DBServer.Update(ctx, request)
- if err != nil {
- log.Println(err.Error())
- return nil, status.Errorf(codes.Internal, err.Error())
- }
- return response, nil
- }
- func (IPS IntPointServiceServer) Delete(ctx context.Context, request *gw.DeleteIntPointRequest) (*gw.DeleteIntPointResponse, error) {
- response, err := IPS.DBServer.Delete(ctx, request)
- if err != nil {
- log.Println(err.Error())
- return nil, status.Errorf(codes.Internal, err.Error())
- }
- return response, nil
- }
|