pull/14/head
Andrey Ivanov 2020-10-07 16:14:13 +03:00 committed by tiburon
parent 9502e665e2
commit 7cfe6eca89
7 changed files with 61 additions and 37 deletions

View File

@ -5,6 +5,7 @@ import (
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/grpc"
googrpc "google.golang.org/grpc"
oslog "log"
"net"
"os"
"os/signal"
@ -12,7 +13,6 @@ import (
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/app"
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/config"
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/logger"
internalgrpc "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/server/grpc"
internalhttp "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/server/http"
store "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage"
)
@ -46,8 +46,14 @@ func main() {
calendar := app.New(log, st)
serverHTTP := internalhttp.NewServer(calendar, conf.Server.Address, conf.Server.Port)
listnGrpc, err := net.Listen("tcp", net.JoinHostPort(conf.Grpc.Address, conf.Grpc.Port))
if err != nil {
log.Fatalf("failed to listen %v", err)
}
serverGRPC := googrpc.NewServer()
grpc.RegisterGrpcServer(serverGRPC, internalgrpc.Service{})
grpc.RegisterGrpcServer(serverGRPC, grpc.Service{*calendar})
serverGRPC.Serve(listnGrpc)
go func() {
signals := make(chan os.Signal, 1)

View File

@ -2,6 +2,10 @@
Address = "localhost"
Port = "8080"
[Grpc]
Address = "localhost"
Port = "50051"
[Logger]
File = "./calendar.log"
Level = "INFO"

View File

@ -5,12 +5,13 @@ go 1.14
require (
github.com/BurntSushi/toml v0.3.1
github.com/amitrai48/logger v0.0.0-20190214092904-448001c055ec
github.com/daixiang0/gci v0.2.4 // indirect
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/protobuf v1.4.2
github.com/grpc-ecosystem/grpc-gateway v1.15.0
github.com/stretchr/testify v1.4.0
go.uber.org/zap v1.15.0 // indirect
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0
golang.org/x/net v0.0.0-20200625001655-4c5254603344
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
google.golang.org/grpc v1.32.0
google.golang.org/protobuf v1.25.0 // indirect

View File

@ -12,6 +12,10 @@ type Config struct {
Address string
Port string
}
Grpc struct {
Address string
Port string
}
Logger struct {
File string
Level string

View File

@ -0,0 +1,41 @@
package grpc
import (
"context"
"github.com/golang/protobuf/ptypes/empty"
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/app"
)
type Service struct {
App app.App
}
func (s Service) Create(ctx context.Context, e *Event) (*EventID, error) {
var res EventID
//var tmp = event.Event{e.Title, e.Date.(time.Time), e.Latency, e.Note, e.UserID, e.NotifyTime}
//t, err := s.App.Storage.Create(tmp)
//if err != nil { return nil, err }
//res.ID = string(t)
return &res, nil
}
func (s Service) Update(ctx context.Context, e *EventWthID) (*empty.Empty, error) {
return nil, nil
}
func (s Service) Delete(ctx context.Context, e *EventID) (*empty.Empty, error) {
return nil, nil
}
func (s Service) List(ctx context.Context, e *empty.Empty) (*EventList, error) {
return nil, nil
}
func (s Service) GetByID(ctx context.Context, e *EventID) (*EventList, error) {
return nil, nil
}
func (s Service) GetByDate(ctx context.Context, e *Date) (*EventList, error) {
return nil, nil
}

View File

@ -1,33 +0,0 @@
package grpc
import (
"context"
"github.com/golang/protobuf/ptypes/empty"
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/grpc"
)
type Service struct{}
func (s Service) Create(context.Context, *grpc.Event) (*grpc.EventID, error) {
return nil, nil
}
func (s Service) Update(context.Context, *grpc.EventWthID) (*empty.Empty, error) {
return nil, nil
}
func (s Service) Delete(context.Context, *grpc.EventID) (*empty.Empty, error) {
return nil, nil
}
func (s Service) List(context.Context, *empty.Empty) (*grpc.EventList, error) {
return nil, nil
}
func (s Service) GetByID(context.Context, *grpc.EventID) (*grpc.EventList, error) {
return nil, nil
}
func (s Service) GetByDate(context.Context, *grpc.Date) (*grpc.EventList, error) {
return nil, nil
}

View File

@ -1,10 +1,11 @@
package store
import (
"time"
"github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage/event"
memorystorage "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage/memory"
sqlstorage "github.com/tiburon-777/HW_OTUS/hw12_13_14_15_calendar/internal/storage/sql"
"time"
)
type Config struct {