diff --git a/go/l19/l1.go b/go/l19/l1.go index 3d7d756..ed70f57 100644 --- a/go/l19/l1.go +++ b/go/l19/l1.go @@ -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) diff --git a/go/l19/l2.go b/go/l19/l2.go index fda68d4..1542ffc 100644 --- a/go/l19/l2.go +++ b/go/l19/l2.go @@ -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)) -} \ No newline at end of file +} diff --git a/go/l19/output/l1 b/go/l19/output/l1 index 9d9acb7..a0c7f95 100755 Binary files a/go/l19/output/l1 and b/go/l19/output/l1 differ diff --git a/go/l19/output/l2 b/go/l19/output/l2 index ef0d76f..90a6ce4 100755 Binary files a/go/l19/output/l2 and b/go/l19/output/l2 differ