Compare commits

...

No commits in common. "5be2d2fd7a47a4a11658c5e6f708bb8577270592" and "b860e1acb675f150969c5ffd90816e604e09a6f2" have entirely different histories.

4 changed files with 28 additions and 4 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"encoding/json"
"strings"
)
type User struct{
@ -26,6 +27,15 @@ func handle(w http.ResponseWriter, r *http.Request) {
http.Error(w,"no", http.StatusBadRequest)
return
}
CheckEmail := strings.ContainsAny(data.Email, "@.")
if CheckEmail != true {
http.Error(w, "incorrect email", http.StatusBadRequest)
return
}
if data.Age > 150 {
http.Error(w, "old", http.StatusBadRequest)
return
}
defer r.Body.Close()
setChan <- data

View file

@ -15,11 +15,25 @@ type UserStruct struct{
Email string `json:"email"`
}
func polz() (int, string, string) {
fmt.Printf("Your age? ")
var age int
fmt.Scan(&age)
fmt.Printf("Your name? ")
var name string
fmt.Scan(&name)
fmt.Printf("Your email? ")
var email string
fmt.Scan(&email)
return age, name, email
}
func main() {
age, name, email := polz()
user := UserStruct{
Age: 66,
Name: "Sergey",
Email: "Likhodeev.60@mail.ru",
Age: age,
Name: name,
Email: email,
}
JsonData, err := json.Marshal(user)
if err != nil {
@ -42,4 +56,4 @@ func main() {
}
fmt.Printf("status code %d\n", resp.StatusCode)
fmt.Println(string(body))
}
}

Binary file not shown.

Binary file not shown.