ing
This commit is contained in:
parent
1639b86706
commit
46cfc967a9
22
commons/error_response.go
Normal file
22
commons/error_response.go
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package commons
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"github.com/valyala/fasthttp"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SendRESTResponse(ctx *fasthttp.RequestCtx, response interface{}) {
|
||||||
|
ctx.SetContentType("application/javascript")
|
||||||
|
|
||||||
|
jRes, _ := json.Marshal(response)
|
||||||
|
ctx.SetBody(jRes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func SendRESTError(ctx *fasthttp.RequestCtx, statusCode int, err error) {
|
||||||
|
ctx.SetContentType("application/javascript")
|
||||||
|
ctx.SetStatusCode(statusCode)
|
||||||
|
|
||||||
|
jRes, _ := json.Marshal(err)
|
||||||
|
ctx.SetBody(jRes)
|
||||||
|
}
|
|
@ -11,7 +11,7 @@
|
||||||
"signingKey": "tWB0lUXiCwX4U3qsJZcZ10mKvEH793RHkTJDbDuZVshQTk4uNB6ck59UQ96lhsRi4XNUiEnlIbP8XYQMPabeNtERX3iyHeDcwocgUVAor1nkAajYeq1gNyJszGpMhEOT"
|
"signingKey": "tWB0lUXiCwX4U3qsJZcZ10mKvEH793RHkTJDbDuZVshQTk4uNB6ck59UQ96lhsRi4XNUiEnlIbP8XYQMPabeNtERX3iyHeDcwocgUVAor1nkAajYeq1gNyJszGpMhEOT"
|
||||||
},
|
},
|
||||||
"gRPC": {
|
"gRPC": {
|
||||||
"addr": "192.168.1.50:50006",
|
"addr": "127.0.0.1:50006",
|
||||||
"tls": false,
|
"tls": false,
|
||||||
"pool": {
|
"pool": {
|
||||||
"maxIdle": 1,
|
"maxIdle": 1,
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
|
||||||
|
|
||||||
|
"git.loafle.net/overflow/overflow_server_app/commons"
|
||||||
"git.loafle.net/overflow/overflow_server_app/config"
|
"git.loafle.net/overflow/overflow_server_app/config"
|
||||||
"git.loafle.net/overflow/overflow_server_app/external/grpc"
|
"git.loafle.net/overflow/overflow_server_app/external/grpc"
|
||||||
jwt "github.com/dgrijalva/jwt-go"
|
jwt "github.com/dgrijalva/jwt-go"
|
||||||
|
@ -16,15 +16,15 @@ import (
|
||||||
|
|
||||||
func SignIn(ctx *fasthttp.RequestCtx) {
|
func SignIn(ctx *fasthttp.RequestCtx) {
|
||||||
var err error
|
var err error
|
||||||
//signinId := string(ctx.FormValue("signinId"))
|
var webParams map[string]interface{}
|
||||||
//signinPw := string(ctx.FormValue("signinPw"))
|
|
||||||
|
|
||||||
var webParams []interface{}
|
|
||||||
webBytes := ctx.PostBody()
|
webBytes := ctx.PostBody()
|
||||||
err = json.Unmarshal(webBytes, &webParams)
|
err = json.Unmarshal(webBytes, &webParams)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(ctx, "Err!!!!: %s\n", err)
|
commons.SendRESTError(ctx, fasthttp.StatusBadRequest, err)
|
||||||
|
// fmt.Fprintf(ctx, "Err!!!!: %s\n", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
length := len(webParams)
|
length := len(webParams)
|
||||||
|
@ -33,16 +33,15 @@ func SignIn(ctx *fasthttp.RequestCtx) {
|
||||||
fmt.Println("eeee")
|
fmt.Println("eeee")
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonMap := webParams[0].(map[string]interface{})
|
signinId := webParams["signinId"].(string)
|
||||||
signinId := jsonMap["signinId"].(string)
|
signinPw := webParams["signinPw"].(string)
|
||||||
signinPw := jsonMap["signinPw"].(string)
|
|
||||||
|
|
||||||
params := []string{signinId, signinPw}
|
params := []string{signinId, signinPw}
|
||||||
|
|
||||||
gRPCCtx := context.Background()
|
gRPCCtx := context.Background()
|
||||||
r, err := grpc.Exec(gRPCCtx, "MemberService.signin", params)
|
r, err := grpc.Exec(gRPCCtx, "MemberService.signin", params)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
fmt.Fprintf(ctx, "%v", err)
|
commons.SendRESTError(ctx, fasthttp.StatusBadRequest, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,9 +65,5 @@ func SignIn(ctx *fasthttp.RequestCtx) {
|
||||||
jwtCookie.SetValue(tokenString)
|
jwtCookie.SetValue(tokenString)
|
||||||
ctx.Response.Header.SetCookie(&jwtCookie)
|
ctx.Response.Header.SetCookie(&jwtCookie)
|
||||||
|
|
||||||
//fmt.Fprintf(ctx, "Welcome!!!!: %s\n", r)
|
commons.SendRESTResponse(ctx, r)
|
||||||
ctx.SetContentType("application/javascript")
|
|
||||||
log.Printf("M:%s", r)
|
|
||||||
ctx.SetBody([]byte(r))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user