2026-06-26 00:33:10 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"net/http"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"time"
|
|
|
|
|
"bytes"
|
|
|
|
|
"io"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type UserStruct struct{
|
|
|
|
|
Age int `json:"age"`
|
|
|
|
|
Name string `json:"name"`
|
|
|
|
|
Email string `json:"email"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-26 00:56:48 +03:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-26 00:33:10 +03:00
|
|
|
func main() {
|
2026-06-26 00:56:48 +03:00
|
|
|
age, name, email := polz()
|
2026-06-26 00:33:10 +03:00
|
|
|
user := UserStruct{
|
2026-06-26 00:56:48 +03:00
|
|
|
Age: age,
|
|
|
|
|
Name: name,
|
|
|
|
|
Email: email,
|
2026-06-26 00:33:10 +03:00
|
|
|
}
|
|
|
|
|
JsonData, err := json.Marshal(user)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
client := &http.Client{
|
|
|
|
|
Timeout: 5 * time.Second,
|
|
|
|
|
}
|
|
|
|
|
req, err := http.NewRequest("POST", "http://127.0.0.1:7777/user", bytes.NewBuffer(JsonData))
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
resp, err := client.Do(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
fmt.Printf("status code %d\n", resp.StatusCode)
|
|
|
|
|
fmt.Println(string(body))
|
2026-06-26 00:56:48 +03:00
|
|
|
}
|