mirror of
https://github.com/hanzozt/sdk-golang.git
synced 2026-10-30 14:46:37 +00:00
- Repo names: ziti-* → zt-* - Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt - Docker images: hanzozt/ziti-* → hanzozt/zt-* - C/Java/JS symbols: ziti_* → zt_* - File and directory names updated
68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"github.com/michaelquigley/pfxlog"
|
|
"github.com/hanzozt/sdk-golang/example/reflect/cmd"
|
|
"github.com/hanzozt/sdk-golang/zt"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var log = pfxlog.Logger()
|
|
var verbose bool
|
|
|
|
var rootCmd = &cobra.Command{Use: "app"}
|
|
|
|
func main() {
|
|
logrus.SetFormatter(&logrus.TextFormatter{
|
|
ForceColors: true,
|
|
DisableTimestamp: true,
|
|
TimestampFormat: "",
|
|
PadLevelText: true,
|
|
})
|
|
logrus.SetReportCaller(false)
|
|
|
|
rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
|
|
if verbose {
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
}
|
|
}
|
|
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging")
|
|
rootCmd.PersistentFlags().StringP("identity", "i", "", "REQUIRED: Path to JSON file that contains an enrolled identity")
|
|
rootCmd.PersistentFlags().StringP("serviceName", "s", "", "REQUIRED: The service to host")
|
|
|
|
_ = cobra.MarkFlagRequired(rootCmd.PersistentFlags(), "identity")
|
|
_ = cobra.MarkFlagRequired(rootCmd.PersistentFlags(), "serviceName")
|
|
|
|
var serverCmd = &cobra.Command{
|
|
Use: "server",
|
|
Short: "run the process as a server",
|
|
Run: func(subcmd *cobra.Command, args []string) {
|
|
cmd.Server(getConfig(), rootCmd.Flag("serviceName").Value.String())
|
|
},
|
|
}
|
|
|
|
var clientCmd = &cobra.Command{
|
|
Use: "client",
|
|
Short: "run the process as a client",
|
|
Run: func(subcmd *cobra.Command, args []string) {
|
|
cmd.Client(getConfig(), rootCmd.Flag("serviceName").Value.String())
|
|
},
|
|
}
|
|
|
|
rootCmd.AddCommand(clientCmd, serverCmd)
|
|
_ = rootCmd.Execute()
|
|
}
|
|
|
|
func getConfig() (ztCfg *zt.Config) {
|
|
identityJson := rootCmd.Flag("identity").Value.String()
|
|
ztCfg, err := zt.NewConfigFromFile(identityJson)
|
|
if err != nil {
|
|
log.Fatalf("failed to load zt configuration file: %v", err)
|
|
}
|
|
ztCfg.ConfigTypes = []string{
|
|
"zt-tunneler-client.v1",
|
|
}
|
|
return ztCfg
|
|
}
|