Skip to content

Commit

Permalink
Better modularization for gnoi_client.go
Browse files Browse the repository at this point in the history
Better modularization for gnoi_client.go: Untangle gnoi_client.go into separate modules such as config, util, system, file and sonic.
  • Loading branch information
hdwhdw authored Jan 10, 2025
2 parents aa547ad + 6059b18 commit 3afc927
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 308 deletions.
18 changes: 18 additions & 0 deletions gnoi_client/config/flag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package config

import (
"flag"
)

var (
Module = flag.String("module", "System", "gNOI Module")
Rpc = flag.String("rpc", "Time", "rpc call in specified module to call")
Target = flag.String("target", "localhost:8080", "Address:port of gNOI Server")
Args = flag.String("jsonin", "", "RPC Arguments in json format")
JwtToken = flag.String("jwt_token", "", "JWT Token if required")
TargetName = flag.String("target_name", "hostname.com", "The target name use to verify the hostname returned by TLS handshake")
)

func ParseFlag() {
flag.Parse()
}
31 changes: 31 additions & 0 deletions gnoi_client/file/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package file

import (
"context"
"fmt"
"encoding/json"
pb "github.com/openconfig/gnoi/file"
"github.com/sonic-net/sonic-gnmi/gnoi_client/utils"
"github.com/sonic-net/sonic-gnmi/gnoi_client/config"
"google.golang.org/grpc"
)

func Stat(conn *grpc.ClientConn, ctx context.Context) {
fmt.Println("File Stat")
ctx = utils.SetUserCreds(ctx)
fc := pb.NewFileClient(conn)
req := &pb.StatRequest{}
err := json.Unmarshal([]byte(*config.Args), req)
if err != nil {
panic(err.Error())
}
resp, err := fc.Stat(ctx, req)
if err != nil {
panic(err.Error())
}
respstr, err := json.Marshal(resp)
if err != nil {
panic(err.Error())
}
fmt.Println(string(respstr))
}
Loading

0 comments on commit 3afc927

Please sign in to comment.