-
Notifications
You must be signed in to change notification settings - Fork 4
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 #13 from jinziguan123/main
合并idl文件
- Loading branch information
Showing
38 changed files
with
975 additions
and
1,179 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,98 @@ | ||
package web | ||
|
||
import ( | ||
"github.com/BigNoseCattyHome/aorb/backend/go-services/auth/models" | ||
"github.com/BigNoseCattyHome/aorb/backend/rpc/auth" | ||
"github.com/BigNoseCattyHome/aorb/backend/utils/constants/config" | ||
"github.com/BigNoseCattyHome/aorb/backend/utils/constants/strings" | ||
"github.com/BigNoseCattyHome/aorb/backend/utils/extra/tracing" | ||
grpc2 "github.com/BigNoseCattyHome/aorb/backend/utils/grpc" | ||
"github.com/BigNoseCattyHome/aorb/backend/utils/json" | ||
"github.com/BigNoseCattyHome/aorb/backend/utils/logging" | ||
"github.com/gin-gonic/gin" | ||
"github.com/sirupsen/logrus" | ||
"net/http" | ||
) | ||
|
||
var Client auth.AuthServiceClient | ||
|
||
func LoginHandler(c *gin.Context) { | ||
var req models.LoginRequest | ||
_, span := tracing.Tracer.Start(c.Request.Context(), "LoginHandler") | ||
defer span.End() | ||
logging.SetSpanWithHostname(span) | ||
logger := logging.LogService("GateWay.Login").WithContext(c.Request.Context()) | ||
|
||
if err := c.ShouldBindQuery(&req); err != nil { | ||
c.JSON(http.StatusOK, models.LoginResponse{ | ||
StatusCode: strings.GateWayParamsErrorCode, | ||
StatusMsg: strings.GateWayParamsError, | ||
UserId: 0, | ||
Token: "", | ||
}) | ||
return | ||
} | ||
|
||
res, err := Client.Login(c.Request.Context(), &auth.LoginRequest{ | ||
Username: req.UserName, | ||
Password: req.Password, | ||
}) | ||
if err != nil { | ||
logger.WithFields(logrus.Fields{ | ||
"Username": req.UserName, | ||
}).Warnf("Error when trying to connect with AuthService") | ||
c.Render(http.StatusOK, json.CustomJSON{Data: res, Context: c}) | ||
return | ||
} | ||
|
||
logger.WithFields(logrus.Fields{ | ||
"Username": req.UserName, | ||
"Token": res.Token, | ||
"UserId": res.UserId, | ||
}).Infof("User log in") | ||
|
||
c.Render(http.StatusOK, json.CustomJSON{Data: res, Context: c}) | ||
} | ||
|
||
func RegisterHandle(c *gin.Context) { | ||
var req models.RegisterRequ | ||
_, span := tracing.Tracer.Start(c.Request.Context(), "RegisterHandler") | ||
defer span.End() | ||
logger := logging.LogService("GateWay.Register").WithContext(c.Request.Context()) | ||
|
||
if err := c.ShouldBindQuery(&req); err != nil { | ||
c.JSON(http.StatusOK, models.RegisterRes{ | ||
StatusCode: strings.GateWayParamsErrorCode, | ||
StatusMsg: strings.GateWayParamsError, | ||
UserId: 0, | ||
Token: "", | ||
}) | ||
return | ||
} | ||
|
||
res, err := Client.Register(c.Request.Context(), &auth.RegisterRequest{ | ||
Username: req.UserName, | ||
Password: req.Password, | ||
}) | ||
|
||
if err != nil { | ||
logger.WithFields(logrus.Fields{ | ||
"Username": req.UserName, | ||
}).Warnf("Error when trying to connect with AuthService") | ||
c.Render(http.StatusOK, json.CustomJSON{Data: res, Context: c}) | ||
return | ||
} | ||
|
||
logger.WithFields(logrus.Fields{ | ||
"Username": req.UserName, | ||
"Token": res.Token, | ||
"UserId": res.UserId, | ||
}).Infof("User register in") | ||
|
||
c.Render(http.StatusOK, json.CustomJSON{Data: res, Context: c}) | ||
} | ||
|
||
func init() { | ||
conn := grpc2.Connect(config.AuthRpcServerName) | ||
Client = auth.NewAuthServiceClient(conn) | ||
} |
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
Oops, something went wrong.