This commit is contained in:
crusader 2018-03-06 12:23:57 +09:00
parent 1639b86706
commit 46cfc967a9
3 changed files with 32 additions and 15 deletions

22
commons/error_response.go Normal file
View 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)
}

View File

@ -11,7 +11,7 @@
"signingKey": "tWB0lUXiCwX4U3qsJZcZ10mKvEH793RHkTJDbDuZVshQTk4uNB6ck59UQ96lhsRi4XNUiEnlIbP8XYQMPabeNtERX3iyHeDcwocgUVAor1nkAajYeq1gNyJszGpMhEOT"
},
"gRPC": {
"addr": "192.168.1.50:50006",
"addr": "127.0.0.1:50006",
"tls": false,
"pool": {
"maxIdle": 1,

View File

@ -6,8 +6,8 @@ import (
"time"
"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/external/grpc"
jwt "github.com/dgrijalva/jwt-go"
@ -16,15 +16,15 @@ import (
func SignIn(ctx *fasthttp.RequestCtx) {
var err error
//signinId := string(ctx.FormValue("signinId"))
//signinPw := string(ctx.FormValue("signinPw"))
var webParams map[string]interface{}
var webParams []interface{}
webBytes := ctx.PostBody()
err = json.Unmarshal(webBytes, &webParams)
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)
@ -33,16 +33,15 @@ func SignIn(ctx *fasthttp.RequestCtx) {
fmt.Println("eeee")
}
jsonMap := webParams[0].(map[string]interface{})
signinId := jsonMap["signinId"].(string)
signinPw := jsonMap["signinPw"].(string)
signinId := webParams["signinId"].(string)
signinPw := webParams["signinPw"].(string)
params := []string{signinId, signinPw}
gRPCCtx := context.Background()
r, err := grpc.Exec(gRPCCtx, "MemberService.signin", params)
if nil != err {
fmt.Fprintf(ctx, "%v", err)
commons.SendRESTError(ctx, fasthttp.StatusBadRequest, err)
return
}
@ -66,9 +65,5 @@ func SignIn(ctx *fasthttp.RequestCtx) {
jwtCookie.SetValue(tokenString)
ctx.Response.Header.SetCookie(&jwtCookie)
//fmt.Fprintf(ctx, "Welcome!!!!: %s\n", r)
ctx.SetContentType("application/javascript")
log.Printf("M:%s", r)
ctx.SetBody([]byte(r))
commons.SendRESTResponse(ctx, r)
}