本文整理汇总了Golang中flag.FlagSet.NFlag方法的典型用法代码示例。如果您正苦于以下问题:Golang FlagSet.NFlag方法的具体用法?Golang FlagSet.NFlag怎么用?Golang FlagSet.NFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flag.FlagSet
的用法示例。
在下文中一共展示了FlagSet.NFlag方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
var flagSet *flag.FlagSet
gHostLabel, err := os.Hostname()
if err != nil {
log.Fatalf("Failed to fetch hostname. Error: %s", err)
}
flagSet = flag.NewFlagSet("pslibnet", flag.ExitOnError)
flagSet.StringVar(&gcliOpts.hostLabel,
"host-label",
gHostLabel,
"label used to identify endpoints homed for this host, default is host name")
flagSet.StringVar(&gcliOpts.etcdURL,
"etcd-url",
"http://127.0.0.1:4001",
"Etcd cluster url")
err = flagSet.Parse(os.Args[1:])
if err != nil {
log.Fatalf("Failed to parse command. Error: %s", err)
}
if flagSet.NFlag() < 1 {
log.Infof("host-label not specified, using default (%s)", gcliOpts.hostLabel)
}
driver := &LibNetDriver{}
err = driver.Config(nil)
if err != nil {
log.Fatalf("libnet driver init failed. Error: %s", err)
}
adapter := &PwrStrpAdptr{}
err = adapter.Init(driver)
if err != nil {
log.Fatalf("powerstrip adaper init failed. Error: %s", err)
}
// start serving the API requests
http.HandleFunc("/adapter/", adapter.CallHook)
err = http.ListenAndServe(":80", nil)
if err != nil {
log.Fatalf("Error listening for http requests. Error: %s", err)
}
os.Exit(0)
}
示例2: main
func main() {
var opts cliOpts
var flagSet *flag.FlagSet
defHostLabel, err := os.Hostname()
if err != nil {
log.Fatalf("Failed to fetch hostname. Error: %s", err)
}
// parse rest of the args that require creating state
flagSet = flag.NewFlagSet("netd", flag.ExitOnError)
flagSet.BoolVar(&opts.debug,
"debug",
false,
"Show debugging information generated by netplugin")
flagSet.StringVar(&opts.syslog,
"syslog",
"",
"Log to syslog at proto://ip:port -- use 'kernel' to log via kernel syslog")
flagSet.BoolVar(&opts.jsonLog,
"json-log",
false,
"Format logs as JSON")
flagSet.StringVar(&opts.hostLabel,
"host-label",
defHostLabel,
"label used to identify endpoints homed for this host, default is host name. If -config flag is used then host-label must be specified in the the configuration passed.")
flagSet.StringVar(&opts.pluginMode,
"plugin-mode",
"docker",
"plugin mode docker|kubernetes")
flagSet.StringVar(&opts.cfgFile,
"config",
"",
"plugin configuration. Use '-' to read configuration from stdin")
flagSet.StringVar(&opts.vtepIP,
"vtep-ip",
"",
"My VTEP ip address")
flagSet.StringVar(&opts.ctrlIP,
"ctrl-ip",
"",
"Local ip address to be used for control communication")
flagSet.StringVar(&opts.vlanIntf,
"vlan-if",
"",
"My VTEP ip address")
flagSet.BoolVar(&opts.version,
"version",
false,
"Show version")
flagSet.StringVar(&opts.fwdMode,
"fwd-mode",
"bridge",
"Forwarding Mode")
flagSet.StringVar(&opts.dbURL,
"cluster-store",
"etcd://127.0.0.1:2379",
"state store url")
err = flagSet.Parse(os.Args[1:])
if err != nil {
log.Fatalf("Failed to parse command. Error: %s", err)
}
if opts.version {
fmt.Printf(version.String())
os.Exit(0)
}
// Make sure we are running as root
usr, err := user.Current()
if (err != nil) || (usr.Username != "root") {
log.Fatalf("This process can only be run as root")
}
if opts.debug {
log.SetLevel(log.DebugLevel)
os.Setenv("CONTIV_TRACE", "1")
}
if opts.jsonLog {
log.SetFormatter(&log.JSONFormatter{})
} else {
log.SetFormatter(&log.TextFormatter{FullTimestamp: true, TimestampFormat: time.StampNano})
}
if opts.syslog != "" {
configureSyslog(opts.syslog)
}
if opts.fwdMode != "bridge" && opts.fwdMode != "routing" && opts.fwdMode != "mpls" {
log.Fatalf("Invalid forwarding mode. Allowed modes are bridge,routing ")
}
if flagSet.NFlag() < 1 {
log.Infof("host-label not specified, using default (%s)", opts.hostLabel)
}
// default to using local IP addr
//.........这里部分代码省略.........
示例3: main
func main() {
var opts cliOpts
var flagSet *flag.FlagSet
defHostLabel, err := os.Hostname()
if err != nil {
log.Fatalf("Failed to fetch hostname. Error: %s", err)
}
// default to using eth1's IP addr
defVtepIP, _ := netutils.GetInterfaceIP("eth1")
defVlanIntf := "eth2"
flagSet = flag.NewFlagSet("netd", flag.ExitOnError)
flagSet.StringVar(&opts.syslog,
"syslog",
"",
"Log to syslog at proto://ip:port -- use 'kernel' to log via kernel syslog")
flagSet.BoolVar(&opts.debug,
"debug",
false,
"Show debugging information generated by netplugin")
flagSet.BoolVar(&opts.forceDeleteEp,
"force-delete-ep",
false,
"force ep deletion upon container deletion")
flagSet.BoolVar(&opts.jsonLog,
"json-log",
false,
"Format logs as JSON")
flagSet.StringVar(&opts.hostLabel,
"host-label",
defHostLabel,
"label used to identify endpoints homed for this host, default is host name. If -config flag is used then host-label must be specified in the the configuration passed.")
flagSet.BoolVar(&opts.nativeInteg,
"native-integration",
false,
"do not listen to container runtime events, because the events are natively integrated into their call sequence and external integration is not required")
flagSet.StringVar(&opts.cfgFile,
"config",
"",
"plugin configuration. Use '-' to read configuration from stdin")
flagSet.StringVar(&opts.vtepIP,
"vtep-ip",
defVtepIP,
"My VTEP ip address")
flagSet.StringVar(&opts.vlanIntf,
"vlan-if",
defVlanIntf,
"My VTEP ip address")
err = flagSet.Parse(os.Args[1:])
if err != nil {
log.Fatalf("Failed to parse command. Error: %s", err)
}
if opts.debug {
log.SetLevel(log.DebugLevel)
os.Setenv("CONTIV_TRACE", "1")
}
if opts.jsonLog {
log.SetFormatter(&log.JSONFormatter{})
}
if opts.syslog != "" {
configureSyslog(opts.syslog)
}
if flagSet.NFlag() < 1 {
log.Infof("host-label not specified, using default (%s)", opts.hostLabel)
}
if utils.FetchSysAttrs() != nil {
log.Fatalf("Error reading system attributes \n")
} else {
if utils.SysAttrs.OsType == "centos" {
opts.forceDeleteEp = true
}
}
defConfigStr := fmt.Sprintf(`{
"drivers" : {
"network": %q,
"state": "etcd"
},
"plugin-instance": {
"host-label": %q,
"vtep-ip": %q,
"vlan-if": %q
},
%q : {
"dbip": "127.0.0.1",
"dbport": 6640
},
"etcd" : {
"machines": ["http://127.0.0.1:4001"]
},
"crt" : {
"type": "docker"
},
//.........这里部分代码省略.........
示例4: main
func main() {
var opts cliOpts
var flagSet *flag.FlagSet
defHostLabel, err := os.Hostname()
// parse rest of the args that require creating state
flagSet = flag.NewFlagSet("netplugin", flag.ExitOnError)
flagSet.BoolVar(&opts.debug,
"debug",
false,
"Show debugging information generated by netplugin")
flagSet.StringVar(&opts.syslog,
"syslog",
"",
"Log to syslog at proto://ip:port -- use 'kernel' to log via kernel syslog")
flagSet.BoolVar(&opts.jsonLog,
"json-log",
false,
"Format logs as JSON")
flagSet.StringVar(&opts.hostLabel,
"host-label",
defHostLabel,
"label used to identify endpoints homed for this host, default is host name. If -config flag is used then host-label must be specified in the the configuration passed.")
flagSet.StringVar(&opts.pluginMode,
"plugin-mode",
"docker",
"plugin mode docker|kubernetes")
flagSet.StringVar(&opts.cfgFile,
"config",
"",
"plugin configuration. Use '-' to read configuration from stdin")
flagSet.StringVar(&opts.vtepIP,
"vtep-ip",
"",
"My VTEP ip address")
flagSet.StringVar(&opts.ctrlIP,
"ctrl-ip",
"",
"Local ip address to be used for control communication")
flagSet.StringVar(&opts.vlanIntf,
"vlan-if",
"",
"VLAN uplink interface")
flagSet.BoolVar(&opts.version,
"version",
false,
"Show version")
flagSet.StringVar(&opts.dbURL,
"cluster-store",
"etcd://127.0.0.1:2379",
"state store url")
err = flagSet.Parse(os.Args[1:])
if err != nil {
log.Fatalf("Failed to parse command. Error: %s", err)
}
if opts.version {
fmt.Printf(version.String())
os.Exit(0)
}
// Make sure we are running as root
usr, err := user.Current()
if (err != nil) || (usr.Username != "root") {
log.Fatalf("This process can only be run as root")
}
if opts.debug {
log.SetLevel(log.DebugLevel)
os.Setenv("CONTIV_TRACE", "1")
}
if opts.jsonLog {
log.SetFormatter(&log.JSONFormatter{})
} else {
log.SetFormatter(&log.TextFormatter{FullTimestamp: true, TimestampFormat: time.StampNano})
}
if opts.syslog != "" {
configureSyslog(opts.syslog)
}
if flagSet.NFlag() < 1 {
log.Infof("host-label not specified, using default (%s)", opts.hostLabel)
}
// default to using local IP addr
localIP, err := cluster.GetLocalAddr()
if err != nil {
log.Fatalf("Error getting local address. Err: %v", err)
}
if opts.ctrlIP == "" {
opts.ctrlIP = localIP
}
if opts.vtepIP == "" {
opts.vtepIP = opts.ctrlIP
}
//.........这里部分代码省略.........
示例5: main
func main() {
var opts cliOpts
var flagSet *flag.FlagSet
defHostLabel, err := os.Hostname()
if err != nil {
log.Fatalf("Failed to fetch hostname. Error: %s", err)
}
// parse rest of the args that require creating state
flagSet = flag.NewFlagSet("netd", flag.ExitOnError)
flagSet.BoolVar(&opts.debug,
"debug",
false,
"Show debugging information generated by netplugin")
flagSet.StringVar(&opts.syslog,
"syslog",
"",
"Log to syslog at proto://ip:port -- use 'kernel' to log via kernel syslog")
flagSet.BoolVar(&opts.jsonLog,
"json-log",
false,
"Format logs as JSON")
flagSet.StringVar(&opts.hostLabel,
"host-label",
defHostLabel,
"label used to identify endpoints homed for this host, default is host name. If -config flag is used then host-label must be specified in the the configuration passed.")
flagSet.StringVar(&opts.pluginMode,
"plugin-mode",
"docker",
"plugin mode docker|kubernetes")
flagSet.StringVar(&opts.cfgFile,
"config",
"",
"plugin configuration. Use '-' to read configuration from stdin")
flagSet.StringVar(&opts.vtepIP,
"vtep-ip",
"",
"My VTEP ip address")
flagSet.StringVar(&opts.ctrlIP,
"ctrl-ip",
"",
"Local ip address to be used for control communication")
flagSet.StringVar(&opts.vlanIntf,
"vlan-if",
"",
"My VTEP ip address")
flagSet.BoolVar(&opts.version,
"version",
false,
"Show version")
flagSet.StringVar(&opts.routerIP,
"router-ip",
"",
"My Router ip address")
flagSet.StringVar(&opts.fwdMode,
"fwd-mode",
"bridge",
"Forwarding Mode")
err = flagSet.Parse(os.Args[1:])
if err != nil {
log.Fatalf("Failed to parse command. Error: %s", err)
}
if opts.version {
fmt.Printf(version.String())
os.Exit(0)
}
// Make sure we are running as root
usr, err := user.Current()
if (err != nil) || (usr.Username != "root") {
log.Fatalf("This process can only be run as root")
}
if opts.debug {
log.SetLevel(log.DebugLevel)
os.Setenv("CONTIV_TRACE", "1")
}
if opts.jsonLog {
log.SetFormatter(&log.JSONFormatter{})
} else {
log.SetFormatter(&log.TextFormatter{FullTimestamp: true, TimestampFormat: time.StampNano})
}
if opts.syslog != "" {
configureSyslog(opts.syslog)
}
if opts.fwdMode != "bridge" && opts.fwdMode != "routing" {
log.Infof("Invalid forwarding mode. Setting the mode to bridge ")
opts.fwdMode = "bridge"
}
if flagSet.NFlag() < 1 {
log.Infof("host-label not specified, using default (%s)", opts.hostLabel)
}
//.........这里部分代码省略.........