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" "fmt"
"net/http" "net/http"
"encoding/json" "encoding/json"
"strings"
) )
type User struct{ type User struct{
Age int `json:"age"` Age int `json:"age"`
Name string `json:"name"` Name string `json:"name"`
Email string `json:"email"` Email string `json:"email"`
Alive bool `json:"alive"`
} }
var setChan = make(chan User) var setChan = make(chan User)
@ -27,6 +29,22 @@ func handle(w http.ResponseWriter, r *http.Request) {
return return
} }
defer r.Body.Close() 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 setChan <- data
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)

View file

@ -7,19 +7,46 @@ import (
"time" "time"
"bytes" "bytes"
"io" "io"
"strings"
) )
type UserStruct struct{ type UserStruct struct{
Age int `json:"age"` Age int `json:"age"`
Name string `json:"name"` Name string `json:"name"`
Email string `json:"email"` 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() { func main() {
age, name, email, alive := polz()
user := UserStruct{ user := UserStruct{
Age: 66, Age: age,
Name: "Sergey", Name: name,
Email: "Likhodeev.60@mail.ru", Email: email,
Alive: alive,
} }
JsonData, err := json.Marshal(user) JsonData, err := json.Marshal(user)
if err != nil { if err != nil {

Binary file not shown.

Binary file not shown.