本文整理汇总了Golang中flag.StringVar函数的典型用法代码示例。如果您正苦于以下问题:Golang StringVar函数的具体用法?Golang StringVar怎么用?Golang StringVar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringVar函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
flag.StringVar(&Package, "p", "atomap", "package name")
flag.StringVar(&Key, "k", "int", "key type")
flag.StringVar(&Value, "v", "int", "value type")
flag.StringVar(&File, "f", "atomap.go", "file name")
flag.Parse()
}
示例2: main
func main() {
var bindAddress string
var port int
flag.IntVar(&port, "port", 9125, "Port to listen on")
flag.IntVar(&port, "p", 9125, "Port to listen on")
flag.StringVar(&bindAddress, "bind", "0.0.0.0", "IP Address to listen on")
flag.StringVar(&bindAddress, "b", "0.0.0.0", "IP Address to listen on")
flag.StringVar(&prefix, "prefix", "statsrelay", "The prefix to use with self generated stats")
flag.BoolVar(&verbose, "verbose", false, "Verbose output")
flag.BoolVar(&verbose, "v", false, "Verbose output")
flag.Parse()
if len(flag.Args()) == 0 {
log.Fatalf("One or most host specifications are needed to locate statsd daemons.\n")
}
hashRing = consistent.New()
hashRing.NumberOfReplicas = 1
for _, v := range flag.Args() {
var addr *net.UDPAddr
var err error
host := strings.Split(v, ":")
switch len(host) {
case 1:
log.Printf("Invalid statsd location: %s\n", v)
log.Fatalf("Must be of the form HOST:PORT or HOST:PORT:INSTANCE\n")
case 2:
addr, err = net.ResolveUDPAddr("udp", v)
if err != nil {
log.Printf("Error parsing HOST:PORT \"%s\"\n", v)
log.Fatalf("%s\n", err.Error())
}
case 3:
addr, err = net.ResolveUDPAddr("udp", host[0]+":"+host[1])
if err != nil {
log.Printf("Error parsing HOST:PORT:INSTANCE \"%s\"\n", v)
log.Fatalf("%s\n", err.Error())
}
default:
log.Fatalf("Unrecongnized host specification: %s\n", v)
}
if addr != nil {
udpAddr[v] = addr
hashRing.Add(v)
}
}
epochTime = time.Now().Unix()
runServer(bindAddress, port)
log.Printf("Normal shutdown.\n")
}
示例3: init
func init() {
flag.IntVar(&N, "N", 100, "Matrix rows/cols.")
// blocking size; 0 is unblocked versions
flag.IntVar(&KB, "KB", 0, "Blocking size for blocked invocations")
// parameters for basic matrix operations
flag.IntVar(&MB, "MB", 68, "Row blocking size.")
flag.IntVar(&NB, "NB", 68, "Column blocking size.")
flag.IntVar(&VPsize, "H", 68, "Viewport size.")
flag.IntVar(&nWorker, "W", 2, "Number of workers for parallel runs")
flag.BoolVar(&singleTest, "s", false, "Run single test run for given matrix size.")
flag.BoolVar(&refTest, "r", false, "Test with lapack reference function.")
flag.StringVar(&sizeList, "L", "", "Comma separated list of matrix sizes.")
flag.IntVar(&testCount, "n", 5, "Number of test runs.")
flag.BoolVar(&noSPD, "-nP", false, "Matrix is not SPD.")
flag.BoolVar(&testUpper, "U", false, "Matrix is UPPER triangular. ")
flag.BoolVar(&check, "C", false, "Check result against lapack reference.")
flag.BoolVar(&verbose, "v", false, "Be verbose.")
flag.BoolVar(&asGflops, "g", false, "Report as Gflops.")
flag.BoolVar(&asEps, "e", false, "Report as result elements per seconds.")
flag.StringVar(&testName, "T", "test", "Test name for reporting")
flag.StringVar(&fileName, "F", "saved.dat", "Filename for source data")
}
示例4: main
func main() {
var url, origin string
flag.StringVar(&url, "url", "ws://127.0.0.1:9999/echo", "websocket URL")
flag.StringVar(&origin, "origin", "http://localhost/", "origin header")
flag.Parse()
if url == "" {
flag.Usage()
os.Exit(1)
}
ws, err := websocket.Dial(url, "", origin)
if err != nil {
log.Fatal(err)
}
go func() {
var msg = make([]byte, 512)
for {
n, err := ws.Read(msg)
if err != nil {
log.Fatal(err)
}
fmt.Printf("R: %s\nS: ", msg[:n])
}
}()
fmt.Print("S: ")
sc := bufio.NewScanner(os.Stdin)
for sc.Scan() {
if _, err := ws.Write(sc.Bytes()); err != nil {
log.Fatal(err)
}
}
}
示例5: main
func main() {
flag.StringVar(&url, "u", "", "URL to load test (required)")
flag.StringVar(&method, "m", "GET", "HTTP method")
flag.UintVar(&concurrency, "c", 10, "number of concurrent requests")
flag.UintVar(&requests, "n", 1000, "number of total requests to make")
flag.UintVar(&timeout, "t", 15, "request timeout in seconds")
flag.StringVar(®ions, "r", "us-east-1,eu-west-1,ap-northeast-1", "AWS regions to run in (comma separated, no spaces)")
flag.Parse()
if url == "" {
flag.Usage()
os.Exit(0)
}
test, testerr := goad.NewTest(&goad.TestConfig{
URL: url,
Concurrency: concurrency,
TotalRequests: requests,
RequestTimeout: time.Duration(timeout) * time.Second,
Regions: strings.Split(regions, ","),
Method: method,
})
if testerr != nil {
fmt.Println(testerr)
os.Exit(1)
}
var finalResult queue.RegionsAggData
defer printSummary(&finalResult)
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) // but interrupts from kbd are blocked by termbox
start(test, &finalResult, sigChan)
}
示例6: main
// Main method.
func main() {
conf := config.New()
help, version := false, false
flag.BoolVar(&help, "help", false, "Prints command line options and exit.")
flag.BoolVar(&version, "version", false, "Prints the etcdsh version and exit.")
flag.StringVar(&conf.Machine, "machine", conf.Machine, "Connect to this etcd server.")
flag.StringVar(&conf.PS1, "ps1", conf.PS1, "First prompt format")
flag.StringVar(&conf.PS2, "ps2", conf.PS2, "Second prompt format")
flag.BoolVar(&conf.Colors, "colors", conf.Colors, "Use colors in display.")
flag.Parse()
if help {
printHelp()
os.Exit(0)
}
if version {
printVersion()
os.Exit(0)
}
fmt.Printf("Connecting to %s\n", conf.Machine)
client := etcd.NewClient([]string{conf.Machine})
controller := handlers.NewController(conf, client, os.Stdout, os.Stderr, os.Stdin)
controller.Add(handlers.NewLsHandler(controller))
controller.Add(handlers.NewSetHandler(controller))
controller.Add(handlers.NewHelpHandler(controller))
controller.Add(handlers.NewCdHandler(controller))
controller.Add(handlers.NewGetHandler(controller))
os.Exit(controller.Start())
}
示例7: New
func New() {
RootDir = findWorkingDir()
flag.StringVar(&ApplicationBind, "bind", "localhost:8090", "Host and port to bind to")
//TODO(kt): handle windows configuration dir
defaultDataDir := fmt.Sprintf(path.Join(os.Getenv("HOME"), ".config", "sufr", "data"))
flag.StringVar(&DataDir, "data-dir", defaultDataDir, "Location to store data in")
defaultTemplateDir := path.Join(RootDir, "templates")
flag.StringVar(&TemplateDir, "template-dir", defaultTemplateDir, "Location where templates are stored")
defaultStaticDir := path.Join(RootDir, "static")
flag.StringVar(&StaticDir, "static-dir", defaultStaticDir, "Location where static assets are stored")
flag.BoolVar(&Debug, "debug", false, "Turn debugging on")
flag.Parse()
if _, err := os.Stat(DataDir); err != nil {
if os.IsNotExist(err) {
err := os.MkdirAll(DataDir, os.ModePerm)
if err != nil {
panic(err)
}
} else {
panic(err)
}
}
DatabaseFile = path.Join(DataDir, DatabaseName)
}
示例8: main
func main() {
// options
var bind, backend, logTo string
var buffer uint
var daemon bool
flag.StringVar(&bind, "bind", ":8002", "locate ip and port")
flag.StringVar(&backend, "backend", "127.0.0.1:8003", "backend server ip and port")
flag.StringVar(&logTo, "logTo", "stdout", "stdout or syslog")
flag.UintVar(&buffer, "buffer", 4096, "buffer size")
flag.BoolVar(&daemon, "daemon", false, "run as daemon process")
flag.Parse()
log.SetOutput(os.Stdout)
if logTo == "syslog" {
w, err := syslog.New(syslog.LOG_INFO, "portproxy")
if err != nil {
log.Fatal(err)
}
log.SetOutput(w)
}
if daemon == true {
godaemon.MakeDaemon(&godaemon.DaemonAttr{})
}
p := New(bind, backend, uint32(buffer))
log.Println("portproxy started.")
go p.Start()
waitSignal()
}
示例9: main
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
var port int
var size int
var criteria string
var index string
var elastic string
flag.IntVar(&port, "p", 8080, "HTTP Port")
flag.IntVar(&size, "s", 10, "LRU Size")
flag.StringVar(&criteria, "c", "all-criteria", "Criteria File")
flag.StringVar(&index, "i", "staging1_hotels_id", "Index")
flag.StringVar(&elastic, "eaddr", "", "Eaddr")
flag.Parse()
var s *Sphere
if elastic == "" {
s = testSphere(criteria, 50000)
} else {
s = loadElastic(index, elastic, criteria)
}
cache = newCache(size, s)
http.HandleFunc("/", httpHander)
httpAddr := fmt.Sprintf(":%d", port)
log.Println("Started on ", port)
log.Fatal(http.ListenAndServe(httpAddr, nil))
}
示例10: init
func init() {
flag.StringVar(&RemoteAddress, "remote", "", "")
flag.StringVar(&RemoteAddress, "r", "", "")
flag.StringVar(&ServerAddress, "server", "", "")
flag.StringVar(&ServerAddress, "s", "", "")
}
示例11: init
func init() {
flag.BoolVar(&mainInstance.flags.verbose, "verbose", false, "Add verbose log to stderr")
flag.StringVar(&mainInstance.flags.verboseFile, "verbosefile", "", "Will verbose log to a filename rather than stderr")
flag.IntVar(&mainInstance.flags.chunkSize, "chunksize", 250, "size to chunk xargs into")
flag.StringVar(&mainInstance.flags.filenamePrefix, "filename_prefix", "", "Prefix to append to all generated files")
flag.BoolVar(&mainInstance.flags.forceAbs, "abs", false, "will force abs paths for ... dirs")
}
示例12: main
func main() {
config := config.Load()
var chainID string
var serverAddr string
var windowSize uint64
flag.StringVar(&serverAddr, "server", fmt.Sprintf("%s:%d", config.General.ListenAddress, config.General.ListenPort), "The RPC server to connect to.")
flag.StringVar(&chainID, "chainID", provisional.TestChainID, "The chain ID to deliver from.")
flag.Uint64Var(&windowSize, "windowSize", 10, "The window size for the deliver.")
flag.Parse()
conn, err := grpc.Dial(serverAddr, grpc.WithInsecure())
if err != nil {
fmt.Println("Error connecting:", err)
return
}
client, err := ab.NewAtomicBroadcastClient(conn).Deliver(context.TODO())
if err != nil {
fmt.Println("Error connecting:", err)
return
}
s := newDeliverClient(client, chainID, windowSize)
s.seekOldest()
s.readUntilClose()
}
示例13: main
// Makes a request for object using CloudFront cookie signing, and outputs
// the contents of the object to stdout.
//
// Usage example:
// signCookies -file <privkey file> -id <keyId> -r <resource pattern> -g <object to get>
func main() {
var keyFile string // Private key PEM file
var keyID string // Key pair ID of CloudFront key pair
var resource string // CloudFront resource pattern
var object string // S3 object frontented by CloudFront
flag.StringVar(&keyFile, "file", "", "private key file")
flag.StringVar(&keyID, "id", "", "key pair id")
flag.StringVar(&resource, "r", "", "resource to request")
flag.StringVar(&object, "g", "", "object to get")
flag.Parse()
// Load the PEM file into memory so it can be used by the signer
privKey, err := sign.LoadPEMPrivKeyFile(keyFile)
if err != nil {
fmt.Println("failed to load key,", err)
return
}
// Create the new CookieSigner to get signed cookies for CloudFront
// resource requests
signer := sign.NewCookieSigner(keyID, privKey)
// Get the cookies for the resource. These will be used
// to make the requests with
cookies, err := signer.Sign(resource, time.Now().Add(1*time.Hour))
if err != nil {
fmt.Println("failed to sign cookies", err)
return
}
// Use the cookies in a http.Client to show how they allow the client
// to request resources from CloudFront.
req, err := http.NewRequest("GET", object, nil)
fmt.Println("Cookies:")
for _, c := range cookies {
fmt.Printf("%s=%s;\n", c.Name, c.Value)
req.AddCookie(c)
}
// Send and handle the response. For a successful response the object's
// content will be written to stdout. The same process could be applied
// to a http service written cookies to the response but using
// http.SetCookie(w, c,) on the ResponseWriter.
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Println("failed to send request", err)
return
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("failed to read requested body", err)
return
}
fmt.Println("Response:", resp.Status)
fmt.Println(string(b))
}
示例14: argParse
func argParse() {
flag.StringVar(&options.expr, "expr", "",
"Specify input file or arithmetic expression string")
flag.StringVar(&options.json, "json", "",
"Specify input file or json string")
flag.Parse()
}
示例15: init
func init() {
flag.IntVar(&port, "port", 5038, "AMI port")
flag.StringVar(&host, "host", "localhost", "AMI host")
flag.StringVar(&user, "user", "admin", "AMI user")
flag.StringVar(&password, "password", "admin", "AMI secret")
flag.Parse()
}