本文整理匯總了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)
}
示例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)
}
示例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())
}
示例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))
})
}
}
示例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")
}
示例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)
}
示例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 {
示例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.")
示例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"))
示例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"))
示例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)
示例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"
示例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)
}
示例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 {
示例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)