客户端cmd flag

This commit is contained in:
奶爸
2019-12-08 23:49:38 +08:00
parent 1b18e7103e
commit 986dc6114a
3 changed files with 40 additions and 2 deletions

View File

@@ -4,8 +4,10 @@ import (
"context"
"fmt"
"log"
"os"
"time"
"github.com/spf13/cobra"
"google.golang.org/grpc"
pb "github.com/p14yground/nezha/proto"
@@ -13,10 +15,33 @@ import (
"github.com/p14yground/nezha/service/rpc"
)
var (
rootCmd = &cobra.Command{
Use: "nezha-agent",
Short: "「哪吒面板」监控、备份、站点管理一站式服务",
Long: `哪吒面板
================================
监控、备份、站点管理一站式服务
啦啦啦,啦啦啦,我是 mjj 小行家`,
Run: run,
}
appKey string
appSecret string
)
func main() {
rootCmd.PersistentFlags().StringVarP(&appKey, "id", "i", "", "客户端ID")
rootCmd.PersistentFlags().StringVarP(&appSecret, "secret", "p", "", "客户端Secret")
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func run(cmd *cobra.Command, args []string) {
auth := rpc.AuthHandler{
AppKey: "naiba",
AppSecret: "123456",
AppKey: appKey,
AppSecret: appSecret,
}
conn, err := grpc.Dial(":5555", grpc.WithInsecure(), grpc.WithPerRPCCredentials(&auth))
if err != nil {