refactor: replace deprecated grpc.Dial with grpc.NewClient in code and docs

This commit is contained in:
2026-07-17 17:00:21 +09:00
parent 78d29b033e
commit cfefef5478
3 changed files with 7 additions and 9 deletions
+1 -1
View File
@@ -229,7 +229,7 @@ protoc --go_out=. --go-grpc_out=. protoapi.proto
* **원격 서비스 클라이언트 기동 (`NewIoTServiceClient`)**: * **원격 서비스 클라이언트 기동 (`NewIoTServiceClient`)**:
```go ```go
conn, _ := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) conn, _ := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
client := protoapi.NewIoTServiceClient(conn) client := protoapi.NewIoTServiceClient(conn)
``` ```
서버와의 TCP 채널(`conn`)을 평문 전송(insecure) 기반으로 바인딩한 뒤, 해당 채널을 통해 원격 서비스를 호출할 수 있는 전송용 클라이언트 인스턴스를 확보합니다. 서버와의 TCP 채널(`conn`)을 평문 전송(insecure) 기반으로 바인딩한 뒤, 해당 채널을 통해 원격 서비스를 호출할 수 있는 전송용 클라이언트 인스턴스를 확보합니다.
+2 -4
View File
@@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"grpccanary/examples/grpcentity/protoapi" "grpccanary/examples/grpcentity/protoapi"
"math/rand" "math/rand"
"time"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/credentials/insecure"
@@ -39,9 +38,9 @@ func AskUpdateSensingData(ctx context.Context, m protoapi.IoTServiceClient, devi
} }
func ClientRun(addr string) { func ClientRun(addr string) {
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) conn, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil { if err != nil {
fmt.Println("Dial:", err) fmt.Println("NewClient error:", err)
return return
} }
@@ -53,7 +52,6 @@ func ClientRun(addr string) {
} }
fmt.Println("Server Date and Time:", r.Value) fmt.Println("Server Date and Time:", r.Value)
rand.Seed(time.Now().Unix())
length := int64(rand.Intn(20)) length := int64(rand.Intn(20))
p, err := AskPass(context.Background(), client, 100, length+1) p, err := AskPass(context.Background(), client, 100, length+1)
if err != nil { if err != nil {
+4 -4
View File
@@ -33,13 +33,13 @@ func random(min, max int, src rand.Source) int {
// return min + int(v.Uint64()) // return min + int(v.Uint64())
// } // }
func getString(len int64) string { func getString(len int64, src rand.Source) string {
temp := "" temp := ""
startChar := "!" startChar := "!"
var i int64 = 1 var i int64 = 1
for { for {
// For getting valid ASCII characters // For getting valid ASCII characters
myRand := random(0, 94, rand.NewSource(time.Now().UnixNano())) myRand := random(0, 94, src)
newChar := string(startChar[0] + byte(myRand)) newChar := string(startChar[0] + byte(myRand))
temp = temp + newChar temp = temp + newChar
if i == len { if i == len {
@@ -75,8 +75,8 @@ func (IoTServer) UpdateSensingData(ctx context.Context, r *protoapi.SensingData)
} }
func (IoTServer) GetRandomPass(ctx context.Context, r *protoapi.RequestPass) (*protoapi.RandomPass, error) { func (IoTServer) GetRandomPass(ctx context.Context, r *protoapi.RequestPass) (*protoapi.RandomPass, error) {
rand.Seed(r.GetSeed()) src := rand.NewSource(r.GetSeed())
temp := getString(r.GetLength()) temp := getString(r.GetLength(), src)
response := &protoapi.RandomPass{ response := &protoapi.RandomPass{
Password: temp, Password: temp,