-
Notifications
You must be signed in to change notification settings - Fork 1
/
grpc.test.go
63 lines (48 loc) · 1.56 KB
/
grpc.test.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
package main
import (
"context"
"fmt"
"log"
"time"
"google.golang.org/grpc"
// Import the generated gRPC client code from your .proto file
pb "github.com/relumini/shortdl/protos" // Replace with the actual path
)
const (
// Server address (replace with your server's address and port)
serverAddr = "localhost:50051"
)
var dc pb.DownloadShortClient
func initDc() {
conn, err := grpc.NewClient(serverAddr, grpc.WithInsecure())
if err != nil {
log.Fatalf("Failed to dial server: %v", err)
}
defer conn.Close() // Close the connection on exit
// Create a gRPC client for the DownloadShort service
dc = pb.NewDownloadShortClient(conn)
}
func test() {
initDc()
// Create a connection to the server
// conn, err := grpc.NewClient(serverAddress, grpc.WithInsecure())
// if err != nil {
// log.Fatalf("Failed to dial server: %v", err)
// }
// defer conn.Close() // Close the connection on exit
// // Create a gRPC client for the DownloadShort service
// client := pb.NewDownloadShortClient(conn)
// Example call to DownTiktok
url := "https://www.tiktok.com/@pt.memeindo/video/7360948743601999109" // Replace with the actual TikTok URL
request := &pb.ParamsRequest{
Url: url,
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) // Set a timeout for the request
defer cancel()
response, err := dc.DownTiktok(ctx, request)
if err != nil {
log.Fatalf("Failed to call DownTiktok: %v", err)
}
fmt.Println("DownloadTiktok response:", response.Status)
// You can similarly call DownYoutube with appropriate URL and request message
}