Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better modularization for gnoi_client.go #338

Merged
merged 5 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading