minorr changes
This commit is contained in:
parent
5be2d2fd7a
commit
cfd280a4b0
4 changed files with 49 additions and 4 deletions
18
go/l19/l1.go
18
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)
|
||||
|
|
|
|||
33
go/l19/l2.go
33
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 {
|
||||
|
|
|
|||
BIN
go/l19/output/l1
BIN
go/l19/output/l1
Binary file not shown.
BIN
go/l19/output/l2
BIN
go/l19/output/l2
Binary file not shown.
Loading…
Reference in a new issue