/
main.go
75 lines (62 loc) 路 1.53 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"context"
"fmt"
"net/http"
"os"
"time"
"github.com/HotPotatoC/twitter-clone/user/rpc/user"
_ "github.com/joho/godotenv/autoload"
"google.golang.org/protobuf/types/known/timestamppb"
)
var (
client = user.NewUserServiceProtobufClient("http://localhost:"+os.Getenv("PORT"), &http.Client{})
ctx = context.Background()
)
func getUserByID(id string) {
user, err := client.FindUserByID(ctx, &user.FindUserByIDRequest{UserId: id})
if err != nil {
panic(err)
}
fmt.Printf("%+v", user)
}
func getUserByEmail(email string) {
user, err := client.FindUserByEmail(ctx, &user.FindUserByEmailRequest{Email: email})
if err != nil {
panic(err)
}
fmt.Printf("%+v", user)
}
func createUser() *user.User {
now := time.Now().String()
req := &user.CreateUserRequest{
Name: now,
ScreenName: "user_" + now,
Password: "123123",
Email: "user_" + now + "@mail.com",
Bio: "lorem ipsum",
Location: "Saint. " + now,
Website: "user_" + now + ".com",
ProfileImageUrl: "",
ProfileBannerUrl: "",
BirthDate: timestamppb.Now(),
}
response, err := client.CreateUser(ctx, req)
if err != nil {
panic(err)
}
return response.User
}
func deleteUser(id string) bool {
response, err := client.DeleteUser(ctx, &user.DeleteUserRequest{UserId: id})
if err != nil {
panic(err)
}
return response.GetSuccess()
}
func main() {
user := createUser()
getUserByEmail(user.GetEmail())
deleteUser(user.GetUserId())
getUserByID(user.GetUserId())
}