func checkIsErr(r *http.Request) bool { //とりあえず正規表現チェック //check id that is match policy mErrList.Id = valid.SetError(r.Form.Get(loginId), valid.Nonzero, valid.Min4, valid.Max12, valid.Ran) //check Password that is match policy mErrList.Password = valid.SetError(r.Form.Get(loginPassword), valid.Nonzero, valid.Min4, valid.Max12, valid.Ran) //とりあえず正規表現エラーチェック if mErrList.IsErr = isErrorcheckErrlist(); mErrList.IsErr { mErrList.ErrDescription = "something wrong" return mErrList.IsErr } //存在チェック var md5Pass string = D.GetMd5Hash(r.Form.Get(loginPassword)) checkDuplicate := fmt.Sprintf("SELECT user.id FROM user where idUser=\"%s\", password=\"%s\"", r.Form.Get(loginId), md5Pass) if mErrList.IsErr = !connectdb.IsDuplicate(checkDuplicate); mErrList.IsErr { log.Println("err %v", mErrList.IsErr) mErrList.ErrDescription = "something wrong" } return mErrList.IsErr }
func Server(w http.ResponseWriter, r *http.Request) { //データのセット getData(r) //エラーが有るかどうか is_err := checkIsError() //えらーあったらjson 形式でエラーを返す if is_err { jsonReturn, err := json.Marshal(&errList) if err != nil { fmt.Print("Can not make json data") return } fmt.Println("Json data") fmt.Println(string(jsonReturn)) fmt.Fprintf(w, string(jsonReturn)) } else { var md5Pass string = D.GetMd5Hash(password1) insertSentence := fmt.Sprintf("insert into user (idUser,password,name,gender,age) values(\"%s\",\"%s\",\"%s\",\"%s\",\"%s\")", id, md5Pass, name, gender, age) connectdb.RowInsert(insertSentence) } }