minorr changes

This commit is contained in:
hhu67 2026-06-26 19:56:18 +03:00
parent 5be2d2fd7a
commit cfd280a4b0
4 changed files with 49 additions and 4 deletions

View file

@ -4,12 +4,14 @@ import (
"fmt"
"net/http"
"encoding/json"
"strings"
)
type User struct{
Age int `json:"age"`
Name string `json:"name"`
Email string `json:"email"`
Alive bool `json:"alive"`
}
var setChan = make(chan User)
@ -27,6 +29,22 @@ func handle(w http.ResponseWriter, r *http.Request) {
return
}
defer r.Body.Close()
i := 0
if data.Age > 150 {
i++
}
CheckEmail := strings.ContainsAny(data.Email, "@.")
if CheckEmail != true {
i++
}
if data.Alive != true {
i++
}
if i != 0 {
msg := fmt.Sprintf("Error: %d", i)
http.Error(w, msg, http.StatusBadRequest)
return
}
setChan <- data
w.WriteHeader(http.StatusOK)

View file

@ -7,19 +7,46 @@ import (
"time"
"bytes"
"io"
"strings"
)
type UserStruct struct{
Age int `json:"age"`
Name string `json:"name"`
Email string `json:"email"`
Alive bool `json:"alive"`
}
func polz() (int, string, string, bool) {
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)
fmt.Printf("Your alive?(y/n) ")
var live string
fmt.Scan(&live)
LowerLive := strings.ToLower(live)
var alive bool
if LowerLive == "y" {
alive = true
} else if LowerLive == "n" {
alive = false
}
return age, name, email, alive
}
func main() {
age, name, email, alive := polz()
user := UserStruct{
Age: 66,
Name: "Sergey",
Email: "Likhodeev.60@mail.ru",
Age: age,
Name: name,
Email: email,
Alive: alive,
}
JsonData, err := json.Marshal(user)
if err != nil {
@ -42,4 +69,4 @@ func main() {
}
fmt.Printf("status code %d\n", resp.StatusCode)
fmt.Println(string(body))
}
}

Binary file not shown.

Binary file not shown.