-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from markgenuine/hw3
feat: hw3
- Loading branch information
Showing
40 changed files
with
1,393 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/markgenuine/auth/internal/converter" | ||
desc "github.com/markgenuine/auth/pkg/auth_v1" | ||
) | ||
|
||
// Create user in auth-service | ||
func (s *Implementation) Create(ctx context.Context, request *desc.CreateRequest) (*desc.CreateResponse, error) { | ||
id, err := s.authService.Create(ctx, converter.CreateUserToServiceFromUser(request)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return converter.CreateUserToUserFromService(id), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/golang/protobuf/ptypes/empty" | ||
desc "github.com/markgenuine/auth/pkg/auth_v1" | ||
) | ||
|
||
// Delete user from auth-service | ||
func (s *Implementation) Delete(ctx context.Context, request *desc.DeleteRequest) (*empty.Empty, error) { | ||
err := s.authService.Delete(ctx, request.GetId()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &empty.Empty{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/markgenuine/auth/internal/converter" | ||
desc "github.com/markgenuine/auth/pkg/auth_v1" | ||
) | ||
|
||
// Get user of ID | ||
func (s *Implementation) Get(ctx context.Context, request *desc.GetRequest) (*desc.GetResponse, error) { | ||
user, err := s.authService.Get(ctx, request.GetId()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return converter.GetToUserFromService(user), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package auth | ||
|
||
import ( | ||
"github.com/markgenuine/auth/internal/service" | ||
desc "github.com/markgenuine/auth/pkg/auth_v1" | ||
) | ||
|
||
// Implementation - type for proto implementation | ||
type Implementation struct { | ||
desc.UnimplementedUserV1Server | ||
authService service.AuthService | ||
} | ||
|
||
// NewImplementation create proto interface implementation | ||
func NewImplementation(authService service.AuthService) *Implementation { | ||
return &Implementation{ | ||
authService: authService, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/golang/protobuf/ptypes/empty" | ||
"github.com/markgenuine/auth/internal/converter" | ||
desc "github.com/markgenuine/auth/pkg/auth_v1" | ||
) | ||
|
||
// Update user of ID | ||
func (s *Implementation) Update(ctx context.Context, request *desc.UpdateRequest) (*empty.Empty, error) { | ||
err := s.authService.Update(ctx, converter.UpdateToServiceFromUser(request)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &empty.Empty{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"log" | ||
"net" | ||
|
||
"github.com/markgenuine/auth/internal/closer" | ||
"github.com/markgenuine/auth/internal/config" | ||
desc "github.com/markgenuine/auth/pkg/auth_v1" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
"google.golang.org/grpc/reflection" | ||
) | ||
|
||
// App ... | ||
type App struct { | ||
serviceProvider *serviceProvider | ||
grpcServer *grpc.Server | ||
} | ||
|
||
var configPath string | ||
|
||
func init() { | ||
flag.StringVar(&configPath, "config-path", ".env", "path to config file") | ||
} | ||
|
||
// NewApp ... | ||
func NewApp(ctx context.Context) (*App, error) { | ||
a := &App{} | ||
|
||
err := a.initDeps(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return a, nil | ||
} | ||
|
||
// Run ... | ||
func (a *App) Run() error { | ||
defer func() { | ||
closer.CloseAll() | ||
closer.Wait() | ||
}() | ||
|
||
return a.runGRPCServer() | ||
} | ||
|
||
func (a *App) initDeps(ctx context.Context) error { | ||
inits := []func(context.Context) error{ | ||
a.initConfig, | ||
a.initServiceProvider, | ||
a.initGRPCServer, | ||
} | ||
|
||
for _, f := range inits { | ||
err := f(ctx) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (a *App) initConfig(_ context.Context) error { | ||
flag.Parse() | ||
err := config.Load(configPath) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (a *App) initServiceProvider(_ context.Context) error { | ||
a.serviceProvider = newServiceProvider() | ||
|
||
return nil | ||
} | ||
|
||
func (a *App) initGRPCServer(ctx context.Context) error { | ||
a.grpcServer = grpc.NewServer(grpc.Creds(insecure.NewCredentials())) | ||
|
||
reflection.Register(a.grpcServer) | ||
desc.RegisterUserV1Server(a.grpcServer, a.serviceProvider.UserImpl(ctx)) | ||
|
||
return nil | ||
} | ||
|
||
func (a *App) runGRPCServer() error { | ||
log.Printf("GRPC server start: %s", a.serviceProvider.GRPCConfig().Address()) | ||
|
||
list, err := net.Listen("tcp", a.serviceProvider.GRPCConfig().Address()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err = a.grpcServer.Serve(list); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.