当前位置: 首页>>代码示例>>Golang>>正文


Golang goopt.String函数代码示例

本文整理汇总了Golang中github.com/droundy/goopt.String函数的典型用法代码示例。如果您正苦于以下问题:Golang String函数的具体用法?Golang String怎么用?Golang String使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了String函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {

	if len(os.Args) < 2 {
		fmt.Fprintf(os.Stderr, "Usage: %s -h for help\n", os.Args[0])
		os.Exit(1)
	}

	config_file := goopt.String([]string{"-c", "--config"}, "nrpe.cfg",
		"config file to use")
	//the first option, will be the default, if the -m isnt given
	run_mode := goopt.Alternatives([]string{"-m", "--mode"},
		[]string{"foreground", "daemon", "systemd"}, "operating mode")
	goopt.Parse(nil)

	//implement different run modes..
	fmt.Println(*run_mode)
	config_obj := new(read_config.ReadConfig)
	config_obj.Init(*config_file)
	err := config_obj.ReadConfigFile()
	common.CheckError(err)
	//extract the commands command[cmd_name] = "/bin/foobar"
	config_obj.ReadCommands()
	config_obj.ReadPrivileges()
	//TODO check for errors
	//what we gonna do with the group?
	pwd := drop_privilege.Getpwnam(config_obj.Nrpe_user)
	drop_privilege.DropPrivileges(int(pwd.Uid), int(pwd.Gid))
	//we have to read it from config
	service := ":5666"
	err = setupSocket(4, service, config_obj)
	common.CheckError(err)
}
开发者ID:vpereira,项目名称:nrped,代码行数:32,代码来源:main.go

示例2: main

func main() {
	hostEnv := os.Getenv("HOST")
	portEnv := os.Getenv("PORT")

	// default to environment variable values (changes the help string :( )
	if hostEnv == "" {
		hostEnv = "*"
	}

	p := 8080
	if portEnv != "" {
		p, _ = strconv.Atoi(portEnv)
	}

	goopt.Usage = usage

	// server mode options
	host := goopt.String([]string{"-h", "--host"}, hostEnv, "host ip address to bind to")
	port := goopt.Int([]string{"-p", "--port"}, p, "port to listen on")

	// cli mode
	vendor := goopt.String([]string{"-v", "--vendor"}, "", "vendor for cli generation")
	status := goopt.String([]string{"-s", "--status"}, "", "status for cli generation")
	color := goopt.String([]string{"-c", "--color", "--colour"}, "", "color for cli generation")
	goopt.Parse(nil)

	args := goopt.Args

	// if any of the cli args are given, or positional args remain, assume cli
	// mode.
	if len(args) > 0 || *vendor != "" || *status != "" || *color != "" {
		cliMode(*vendor, *status, *color, args)
		return
	}
	// normalize for http serving
	if *host == "*" {
		*host = ""
	}

	http.HandleFunc("/v1/", buckle)
	http.HandleFunc("/favicon.png", favicon)
	http.HandleFunc("/", index)

	log.Println("Listening on port", *port)
	http.ListenAndServe(*host+":"+strconv.Itoa(*port), nil)
}
开发者ID:jorik041,项目名称:buckler,代码行数:46,代码来源:main.go

示例3: init

func init() {
	goopt.Description = func() string {
		return "conchk v" + goopt.Version
	}
	goopt.Author = "Bruce Fitzsimons <[email protected]>"
	goopt.Version = "0.3"
	goopt.Summary = "conchk is an IP connectivity test tool designed to validate that all configured IP connectivity actually works\n " +
		"It reads a list of tests and executes them, in a parallel manner, based on the contents of each line" +
		"conchk supports tcp and udp based tests (IPv4 and IPv6), at this time.\n\n" +
		"==Notes==\n" +
		"* The incuded Excel sheet is a useful way to create and maintain the tests\n" +
		"* testing a range of supports is supported. In this case the rules for a successful test are somewhat different\n" +
		"** If one of the ports gets a successful connect, and the rest are refused (connection refused) as nothing is listening\n" +
		"\tthen this is considered to be a successful test of the range. This is the most common scenario in our experience;\n" +
		"\tthe firewalls and routing are demonstrably working, and at least one destination service is ok. If you need all ports to work\n" +
		"\tthen consider using individual tests\n" +
		"* If all tests for this host pass, then conchk will exit(0). Otherwise it will exit(1)\n" +
		"* conchk will use the current hostname, or the commandline parameter, to find the tests approprate to execute - matches on field 3.\n" +
		"\tThis means all the tests for a system, or project can be placed in one file\n" +
		"* The .csv output option will write a file much like the input file, but with two additional columns and without any comments\n" +
		"\t This file can be fed back into conchk without error.\n\n" +
		"See http://bwooce.github.io/conchk/ for more information.\n\n(c)2013 Bruce Fitzsimons.\n\n"

	Hostname, _ := os.Hostname()

	params.Debug = goopt.Flag([]string{"-d", "--debug"}, []string{}, "additional debugging output", "")
	params.TestsFile = goopt.String([]string{"-T", "--tests"}, "./tests.conchk", "test file to load")
	params.OutputFile = goopt.String([]string{"-O", "--outputcsv"}, "", "name of results .csv file to write to. A pre-existing file will be overwritten.")
	params.MyHost = goopt.String([]string{"-H", "--host"}, Hostname, "Hostname to use for config lookup")
	params.MaxStreams = goopt.Int([]string{"--maxstreams"}, 8, "Maximum simultaneous checks")
	params.Timeout = goopt.String([]string{"--timeout"}, "5s", "TCP connectivity timeout, UDP delay for ICMP responses")

	semStreams = make(semaphore, *params.MaxStreams)
	runtime.GOMAXPROCS(runtime.NumCPU())

}
开发者ID:Bwooce,项目名称:conchk,代码行数:36,代码来源:conchk.go

示例4: main

func main() {
	configFile := goopt.String([]string{"--config"}, "./config.json", "Configuration File")
	var action = goopt.String([]string{"--action"}, "", "Action to run")
	var file = goopt.String([]string{"--file"}, "", "File to classify")
	goopt.Description = func() string {
		return "Perceptron 2.0"
	}
	goopt.Version = "2.0"
	goopt.Summary = "Perceptron"
	goopt.Parse(nil)

	json := perceptron.ReadConfig(*configFile)
	if *action == "preprocess" {
		perceptron.RunPreprocessor(&json)
	} else if *action == "train" {
		perceptron.TrainPerceptron(&json)
	} else if *action == "test" {
		perceptron.TestPerceptron(&json)
	} else {
		perceptron.Preprocess(&json, *file, func(vector []string) {
			fmt.Println(perceptron.RunPerceptron(&json, vector))
		})
	}
}
开发者ID:ncb000gt,项目名称:learning,代码行数:24,代码来源:runner.go

示例5: init

func init() {
	format = goopt.String([]string{"--fmt", "--format"}, "",
		"Log format (e.g. '$remote_addr [$time_local] \"$request\"')")
	nginxConfig = goopt.String([]string{"--nginx"}, "",
		"Nginx config to look for 'log_format' directive. You also should specify --nginx-format")
	nginxFormat = goopt.String([]string{"--nginx-format"}, "",
		"Name of nginx 'log_format', should be passed with --nginx option")
	aggField = goopt.String([]string{"-a", "--aggregate"}, "request_time",
		"Nginx access log variable to aggregate")
	groupBy = goopt.String([]string{"-g", "--group-by"}, "request",
		"Nginx access log variable to group by")
	groupByRegexp = goopt.String([]string{"-r", "--regexp"}, "",
		"You can specify regular expression to extract exact data from group by data. "+
			"For example, you might want to group by a path inside $request, so you should "+
			"set this option to '^\\S+\\s(.*)(?:\\?.*)?$'.")
	groupByGeneralize = goopt.String([]string{"--generalize"}, "",
		"Regular expression to generalize data. For example to make /foo/123 and /foo/234 equal")
	debug = goopt.Flag([]string{"--debug"}, []string{"--no-debug"},
		"Log debug information", "Do not log debug information")
	jsonOutput = goopt.String([]string{"-o", "--json"}, "",
		"Save result as json encoded file")
}
开发者ID:satyrius,项目名称:log-parser,代码行数:22,代码来源:parser.go

示例6: main

// main handles parsing command line arguments and spawning instances of
// findImages()
func main() {
	rand.Seed(time.Now().UTC().UnixNano())

	var interval = goopt.Int([]string{"-i", "--interval"}, 2000,
		"Milliseconds between requests per connection")
	var connections = goopt.Int([]string{"-c", "--connections"}, 4,
		"Number of simultanious connections")
	var directory = goopt.String([]string{"-d", "--directory"}, "images",
		"Directory to save images to")

	goopt.Description = func() string {
		return "Download random images from imgur"
	}
	goopt.Version = "0.0.1"
	goopt.Summary = "Random imgur downloader"
	goopt.Parse(nil)

	// Create requested number of connections.
	for threadNum := 1; threadNum < *connections; threadNum++ {
		go findImages(*interval, *directory, threadNum)
	}
	findImages(*interval, *directory, 0)
}
开发者ID:haesken,项目名称:rand_imgur_go,代码行数:25,代码来源:rand_imgur.go

示例7: main

import (
	"errors"
	"fmt"
	"github.com/droundy/goopt"
	"github.com/russross/blackfriday"
	"io/ioutil"
	"os"
	"text/template"
)

type TemplateData struct {
	Contents string
}

// Command-line flags
var outpath = goopt.String([]string{"-o", "--out"}, "", "The (optional) path to an output file")
var templatePath = goopt.String([]string{"-t", "--template"}, "", "The path to the template to be used")
var output string

func main() {
	setup()
	input := readInput(goopt.Args)
	if input == nil {
		fmt.Println("No input found")
		os.Exit(1)
	}
	outfile := getOutfile()
	markdown := blackfriday.MarkdownBasic(input)
	if *templatePath != "" {
		tpl, err := loadTemplate(*templatePath)
		if err != nil {
开发者ID:manuclementz,项目名称:md,代码行数:31,代码来源:md.go

示例8: main

package main

// test out the goopt package...

import (
	"fmt"
	goopt "github.com/droundy/goopt"
	"strings"
)

var amVerbose = goopt.Flag([]string{"--verbose"}, []string{},
	"output verbosely", "")
var amHappy = goopt.Flag([]string{"-h", "--happy"}, []string{"-u", "--unhappy", "--sad"}, "be happy", "be unhappy")

var foo = goopt.String([]string{"--name"}, "anonymous", "pick your name")
var bar = goopt.String([]string{"-b"}, "BOO!", "pick your scary sound")
var baz = goopt.String([]string{"-o"}, "", "test whether a silent default works")
var speed = goopt.Alternatives([]string{"--speed", "--velocity"},
	[]string{"slow", "medium", "fast"},
	"set the speed")

var words = goopt.Strings([]string{"--word", "--saying", "-w", "-s"}, "word",
	"specify a word to speak")

var width = goopt.Int([]string{"-l", "--length"}, 1, "number of ?s")

func main() {
	goopt.Summary = "silly test program"
	goopt.Parse(nil)
	if *amVerbose {
		fmt.Println("I am verbose.")
开发者ID:endurox-dev,项目名称:goopt,代码行数:31,代码来源:test-program.go

示例9: main

	"os"
	"bufio"
	"github.com/droundy/goopt"
	git "./git/git"
	"./git/plumbing"
	"./util/out"
	"./util/debug"
	"./util/error"
	"./util/help"
	"./iolaus/prompt"
	"./iolaus/test"
	"./iolaus/core"
	hashes "./gotgo/slice(git.Commitish)"
)

var shortlog = goopt.String([]string{"-m","--patch"}, "COMMITNAME",
	"name of commit")

var description = func() string {
	return `
Record is used to name a set of changes and record the patch to the
repository.
`}

func main() {
	goopt.Vars["Verb"] = "Record"
	goopt.Vars["verb"] = "record"
	defer error.Exit(nil) // Must call exit so that cleanup will work!
	help.Init("record changes.", description, core.ModifiedFiles)
	git.AmInRepo("Must be in a repository to call record!")
	//plumbing.ReadTree(git.Ref("HEAD"))
开发者ID:droundy,项目名称:iolaus,代码行数:31,代码来源:iolaus-record.go

示例10: main

var Summary = `gostatic path/to/config

Build a site.
`

var showVersion = goopt.Flag([]string{"-V", "--version"}, []string{},
	"show version and exit", "")
var showProcessors = goopt.Flag([]string{"--processors"}, []string{},
	"show internal processors", "")
var showSummary = goopt.Flag([]string{"--summary"}, []string{},
	"print everything on stdout", "")
var showConfig = goopt.Flag([]string{"--show-config"}, []string{},
	"dump config as JSON on stdout", "")
var doWatch = goopt.Flag([]string{"-w", "--watch"}, []string{},
	"watch for changes and serve them as http", "")
var port = goopt.String([]string{"-p", "--port"}, "8000",
	"port to serve on")
var verbose = goopt.Flag([]string{"-v", "--verbose"}, []string{},
	"enable verbose output", "")

// used in Page.Changed()
var force = goopt.Flag([]string{"-f", "--force"}, []string{},
	"force building all pages", "")

func main() {
	goopt.Version = Version
	goopt.Summary = Summary

	goopt.Parse(nil)

	if *showSummary && *doWatch {
		errhandle(fmt.Errorf("--summary and --watch do not mix together well"))
开发者ID:minhajuddin,项目名称:gostatic,代码行数:32,代码来源:gostatic.go

示例11: stringify

	}
	if err == io.EOF {
		err = nil
	}
	return
}

//replace slashes and whitespaces with underscore
func stringify(tstring string) (stringified string) {
	str := strings.Replace(tstring, "\"", "", -1)
	str = strings.Replace(str, "/", "_", -1)
	stringified = strings.Replace(str, " ", "_", -1)
	return
}

var opt_conf = goopt.String([]string{"-c", "--config"}, "config file", "path to config file")
var opt_data = goopt.String([]string{"-d", "--data"}, "data csv", "path to data csv file")
var opt_statsname = goopt.String([]string{"-s", "--statsname"}, "nfs", "extending name for the bucket: $basename.nfs")
var opt_mover = goopt.String([]string{"-m", "--datamover"}, "server_2", "extending name for the bucket: $basename.$movername.nfs")

func main() {
	goopt.Version = version
	goopt.Summary = "send emc vnx performance data to graphite"
	goopt.Parse(nil)

	if f, _ := exists(*opt_conf); f == false {
		fmt.Print(goopt.Help())
		fmt.Println("ERROR: config file " + *opt_conf + " doesn't exist")
		return
	}
	c, _ := config.ReadDefault(*opt_conf)
开发者ID:koumdros,项目名称:vnx2graphite,代码行数:31,代码来源:vnx2graphite.go

示例12: usernameInWhitelist

import (
	"encoding/json"
	"log"
	"net"
	"os"
	"os/exec"
	"os/signal"
	"strconv"
	"syscall"
	"time"
	//"github.com/Syfaro/telegram-bot-api"
	goopt "github.com/droundy/goopt"
	"gopkg.in/go-telegram-bot-api/telegram-bot-api.v4"
)

var param_cfgpath = goopt.String([]string{"-c", "--config"}, "/etc/leicht/default.json", "set config file path")

func usernameInWhitelist(username string, whitelist []string) bool {
	present := false
	for _, item := range whitelist {
		if username == item {
			present = true
		}
	}
	return present
}

func main() {

	goopt.Description = func() string {
		return "Leicht - universal telegram bot"
开发者ID:Like-all,项目名称:leicht,代码行数:31,代码来源:main.go

示例13: main

package main

import (
	"bytes"
	"log"
	"net"
	"os/exec"
	"regexp"
	"strings"
	"time"

	"github.com/droundy/goopt"
)

var connect = goopt.String([]string{"-s", "--server"}, "127.0.0.1", "Server to connect to (and listen if listening)")
var port = goopt.Int([]string{"-p", "--port"}, 2222, "Port to connect to (and listen to if listening)")

var listen = goopt.Flag([]string{"-l", "--listen"}, []string{}, "Create a listening TFO socket", "")

func main() {

	goopt.Parse(nil)

	// IPv4 only for no real reason, could be v6 by adjusting the sizes
	// here and where it's used
	var serverAddr [4]byte

	IP := net.ParseIP(*connect)
	if IP == nil {
		log.Fatal("Unable to process IP: ", *connect)
	}
开发者ID:zgbkny,项目名称:tcp-fast-open,代码行数:31,代码来源:main.go

示例14: main

	Version = "0.4.3"
	Summary = "gr [OPTS] string-to-search\n"

	byteNewLine []byte = []byte("\n")

	ignoreCase = goopt.Flag([]string{"-i", "--ignore-case"}, []string{},
		"ignore pattern case", "")
	onlyName = goopt.Flag([]string{"-n", "--filename"}, []string{},
		"print only filenames", "")
	ignoreFiles = goopt.Strings([]string{"-x", "--exclude"}, "RE",
		"exclude files that match the regexp from search")
	singleline = goopt.Flag([]string{"-s", "--singleline"}, []string{},
		"match on a single line (^/$ will be beginning/end of line)", "")
	plaintext = goopt.Flag([]string{"-p", "--plain"}, []string{},
		"search plain text", "")
	replace = goopt.String([]string{"-r", "--replace"}, "",
		"replace found substrings with this string")
	force = goopt.Flag([]string{"--force"}, []string{},
		"force replacement in binary files", "")
	showVersion = goopt.Flag([]string{"-V", "--version"}, []string{},
		"show version and exit", "")
	noIgnoresGlobal = goopt.Flag([]string{"-I", "--no-autoignore"}, []string{},
		"do not read .git/.hgignore files", "")
	verbose = goopt.Flag([]string{"-v", "--verbose"}, []string{},
		"be verbose (show non-fatal errors, like unreadable files)", "")
)

func main() {
	goopt.Author = Author
	goopt.Version = Version
	goopt.Summary = Summary
	goopt.Usage = func() string {
开发者ID:jwhitlark,项目名称:goreplace,代码行数:32,代码来源:goreplace.go

示例15: main

// Package ftp implements a FTP client as described in RFC 959.
package main

import (
	"fmt"
	goopt "github.com/droundy/goopt"
	ftp "github.com/jlaffaye/ftp"
)

var server_ip = goopt.String([]string{"-h"}, "0.0.0.0", "FTP服务器IP地址")
var server_port = goopt.Int([]string{"-p"}, 21, "FTP服务器端口")
var username = goopt.String([]string{"-u"}, "anonymous", "登陆用户名")
var password = goopt.String([]string{"-k"}, "anonymous", "登陆用户密码")

var dir = goopt.String([]string{"-d"}, "null", "所要查询的目录")
var file = goopt.String([]string{"-f"}, "null", "所要查询的文件名")

func main() {

	goopt.Description = func() string {
		return "Example program for using the goopt flag library."
	}
	goopt.Version = "1.0"
	goopt.Summary = "checker.exe -h 127.0.0.1 -u user -p 123qwe -d /dir -f file1"
	goopt.Parse(nil)

	fmt.Printf("FTP agrs info server_ip[%v]]\n", *server_ip)
	fmt.Printf("FTP agrs info server_port[%v]\n", *server_port)
	fmt.Printf("FTP agrs info username[%v]\n", *username)
	fmt.Printf("FTP agrs info password[%v]\n", *password)
	fmt.Printf("FTP agrs info dir[%v]\n", *dir)
开发者ID:volunteer2003,项目名称:checker,代码行数:31,代码来源:checker.go


注:本文中的github.com/droundy/goopt.String函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。