This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: complete getting my user and users with token
- Loading branch information
mohammadne
committed
Aug 29, 2021
1 parent
511b3f3
commit 9568ba5
Showing
16 changed files
with
179 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ USER_DATABASE_SCHEMA= | |
USER_REST_URL= | ||
|
||
USER_GRPC_URL= | ||
|
||
AUTH_GRPC_URL= |
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,61 @@ | ||
package grpc_clients | ||
|
||
import ( | ||
context "context" | ||
|
||
"github.com/mohammadne/bookman/user/internal/network/grpc/contracts" | ||
|
||
"github.com/mohammadne/bookman/user/internal/network/grpc" | ||
"github.com/mohammadne/go-pkgs/failures" | ||
"github.com/mohammadne/go-pkgs/logger" | ||
grpcPkg "google.golang.org/grpc" | ||
) | ||
|
||
type Auth interface { | ||
GetTokenMetadata(string) (uint64, failures.Failure) | ||
} | ||
|
||
type authClient struct { | ||
logger logger.Logger | ||
config *grpc.Config | ||
|
||
client contracts.AuthClient | ||
} | ||
|
||
func NewUser(cfg *grpc.Config, log logger.Logger) *authClient { | ||
return &authClient{config: cfg, logger: log} | ||
} | ||
|
||
func (g *authClient) Setup() { | ||
authConnection, err := grpcPkg.Dial(g.config.Url, grpcPkg.WithInsecure()) | ||
if err != nil { | ||
g.logger.Fatal( | ||
"error getting auth grpc connection", | ||
logger.String("address", g.config.Url), | ||
logger.Error(err), | ||
) | ||
} | ||
|
||
g.client = contracts.NewAuthClient(authConnection) | ||
} | ||
|
||
var ( | ||
errGettingToken = failures.Rest{}.NewInternalServer("error getting token metadata") | ||
invalidToken = failures.Rest{}.NewInternalServer("invalid token") | ||
) | ||
|
||
func (g *authClient) GetTokenMetadata(token string) (uint64, failures.Failure) { | ||
contract := &contracts.TokenContract{Token: token} | ||
response, err := g.client.TokenMetadata(context.Background(), contract) | ||
if err != nil { | ||
g.logger.Error("grpc get token metadata", logger.Error(err)) | ||
return 0, errGettingToken | ||
} | ||
|
||
if !response.IsValid { | ||
g.logger.Error("not valid token metadata", logger.Error(err)) | ||
return 0, invalidToken | ||
} | ||
|
||
return response.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,5 @@ | ||
package grpc | ||
|
||
type Config struct { | ||
Url string | ||
} |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.