本文整理汇总了Golang中github.com/timtadh/getopt.GetOpt函数的典型用法代码示例。如果您正苦于以下问题:Golang GetOpt函数的具体用法?Golang GetOpt怎么用?Golang GetOpt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetOpt函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: countReporter
func countReporter(rptrs map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hf:",
[]string{
"help",
"filename=",
},
)
if err != nil {
errors.Logf("ERROR", "%v", err)
Usage(ErrorCodes["opts"])
}
filename := "count"
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-f", "--filename":
filename = oa.Arg()
default:
errors.Logf("ERROR", "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
r, err := reporters.NewCount(conf, filename)
if err != nil {
errors.Logf("ERROR", "There was error creating output files\n")
errors.Logf("ERROR", "%v", err)
os.Exit(1)
}
return r, args
}
开发者ID:timtadh,项目名称:sfp,代码行数:33,代码来源:cmd.go
示例2: main
func main() {
short := "h"
long := []string{
"help",
"allow-dups",
}
args, optargs, err := getopt.GetOpt(os.Args[1:], short, long)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Usage(ErrorCodes["opts"])
}
port := -1
dups := false
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "--allow-dups":
dups = true
}
}
if len(args) != 1 {
fmt.Fprintln(os.Stderr, "You must specify a port")
Usage(ErrorCodes["opts"])
}
port = parse_int(args[0])
fmt.Println("starting")
server := net.NewServer(func() net.Queue { return queue.NewQueue(dups) })
server.Start(port)
}
开发者ID:jmptrader,项目名称:queued-1,代码行数:33,代码来源:main.go
示例3: uniproxMode
func uniproxMode(argv []string, conf *config.Config) (miners.Miner, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hw:",
[]string{
"help",
"walks=",
"max",
},
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
cmd.Usage(cmd.ErrorCodes["opts"])
}
walks := 15
max := false
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
cmd.Usage(0)
case "-w", "--walks":
walks = cmd.ParseInt(oa.Arg())
case "--max":
max = true
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
cmd.Usage(cmd.ErrorCodes["opts"])
}
}
miner, err := uniprox.NewWalker(conf, walks, max)
if err != nil {
log.Fatal(err)
}
return miner, args
}
开发者ID:timtadh,项目名称:sfp,代码行数:35,代码来源:main.go
示例4: premuskMode
func premuskMode(argv []string, conf *config.Config) (miners.Miner, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"h",
[]string{
"help",
"teleport=",
},
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
cmd.Usage(cmd.ErrorCodes["opts"])
}
teleport := .01
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
cmd.Usage(0)
case "--teleport":
teleport = cmd.ParseFloat(oa.Arg())
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
cmd.Usage(cmd.ErrorCodes["opts"])
}
}
miner := premusk.NewWalker(conf, teleport)
return miner, args
}
开发者ID:timtadh,项目名称:sfp,代码行数:28,代码来源:main.go
示例5: logReporter
func logReporter(rptrs map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hl:p:",
[]string{
"help",
"level=",
"prefix=",
"show-pr",
},
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Usage(ErrorCodes["opts"])
}
level := "INFO"
prefix := ""
showPr := false
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-l", "--level":
level = oa.Arg()
case "-p", "--prefix":
prefix = oa.Arg()
case "--show-pr":
showPr = true
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
return reporters.NewLog(fmtr, showPr, level, prefix), args
}
开发者ID:timtadh,项目名称:sfp,代码行数:35,代码来源:cmd.go
示例6: main
func main() {
short := "hm:"
long := []string{
"help", "mode=",
}
args, optargs, err := getopt.GetOpt(os.Args[1:], short, long)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Usage(ErrorCodes["opts"])
}
var mode string
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-m", "--mode":
switch oa.Arg() {
case "create", "read":
mode = oa.Arg()
default:
fmt.Fprintf(os.Stderr, "mode %v not supported\n", oa.Arg())
Usage(ErrorCodes["opts"])
}
}
}
if len(args) != 2 {
fmt.Fprintf(os.Stderr, "Must supply exactly two file paths")
Usage(ErrorCodes["opts"])
}
list_path := args[0]
keys_path := args[1]
f, err := os.Create("stress-" + mode + ".prof")
if err != nil {
panic(err)
}
defer f.Close()
profile_writer = f
switch mode {
case "create":
assert_file_does_not_exist(list_path)
assert_file_does_not_exist(keys_path)
create(list_path, keys_path)
case "read":
assert_file_exist(list_path)
assert_file_exist(keys_path)
read(list_path, keys_path)
}
}
开发者ID:timtadh,项目名称:file-structures,代码行数:54,代码来源:main.go
示例7: fileReporter
func fileReporter(rptrs map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hp:e:n:",
[]string{
"help",
"patterns=",
"embeddings=",
"names=",
"matrices=",
"probabilities=",
"show-pr",
},
)
if err != nil {
errors.Logf("ERROR", "%v", err)
Usage(ErrorCodes["opts"])
}
patterns := "patterns"
embeddings := "embeddings"
names := "names.txt"
matrices := "matrices.json"
probabilities := "probabilities.prs"
showPr := false
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-p", "--patterns":
patterns = oa.Arg()
case "-e", "--embeddings":
embeddings = oa.Arg()
case "-n", "--names":
names = oa.Arg()
case "--matrices":
matrices = oa.Arg()
case "--probabilites":
probabilities = oa.Arg()
case "--show-pr":
showPr = true
default:
errors.Logf("ERROR", "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
fr, err := reporters.NewFile(conf, fmtr, showPr, patterns, embeddings, names, matrices, probabilities)
if err != nil {
errors.Logf("ERROR", "There was error creating output files\n")
errors.Logf("ERROR", "%v\n", err)
os.Exit(1)
}
return fr, args
}
开发者ID:timtadh,项目名称:sfp,代码行数:53,代码来源:cmd.go
示例8: main
func main() {
short := "hp:"
long := []string{
"help",
"pattern=",
}
_, optargs, err := getopt.GetOpt(os.Args[1:], short, long)
if err != nil {
log.Print(os.Stderr, err)
Usage(1)
}
patterns := make([]string, 0, 10)
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-p", "--pattern":
patterns = append(patterns, oa.Arg())
}
}
if len(patterns) <= 0 {
log.Print("Must supply some regulars expressions!")
Usage(1)
}
asts := make([]frontend.AST, 0, len(patterns))
for _, p := range patterns {
ast, err := frontend.Parse([]byte(p))
if err != nil {
log.Fatal(err)
}
asts = append(asts, ast)
}
lexast := asts[len(asts)-1]
for i := len(asts) - 2; i >= 0; i-- {
lexast = frontend.NewAltMatch(asts[i], lexast)
}
program, err := frontend.Generate(lexast)
if err != nil {
log.Fatal(err)
}
for i, inst := range program {
fmt.Printf("%3d %s\n", i, inst.Serialize())
}
}
开发者ID:jmptrader,项目名称:lexmachine,代码行数:52,代码来源:main.go
示例9: dbscanReporter
func dbscanReporter(rptrs map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hf:e:g:a:",
[]string{
"help",
"filename=",
"epsilon=",
"gamma=",
"attr=",
},
)
if err != nil {
errors.Logf("ERROR", "%v", err)
Usage(ErrorCodes["opts"])
}
clusters := "clusters"
metrics := "metrics"
attr := ""
epsilon := 0.2
gamma := 0.2
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-c", "--clusters-name":
clusters = oa.Arg()
case "-m", "--metrics-name":
metrics = oa.Arg()
case "-a", "--attr":
attr = oa.Arg()
case "-e", "--epsilon":
epsilon = ParseFloat(oa.Arg())
case "-g", "--gamma":
gamma = ParseFloat(oa.Arg())
default:
errors.Logf("ERROR", "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
if attr == "" {
errors.Logf("ERROR", "You must supply --attr=<attr> to dbscan")
Usage(ErrorCodes["opts"])
}
r, err := reporters.NewDbScan(conf, fmtr, clusters, metrics, attr, epsilon, gamma)
if err != nil {
errors.Logf("ERROR", "There was error creating output files\n")
errors.Logf("ERROR", "%v", err)
os.Exit(1)
}
return r, args
}
开发者ID:timtadh,项目名称:sfp,代码行数:52,代码来源:cmd.go
示例10: uniqueReporter
func uniqueReporter(reports map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"h",
[]string{
"help",
"histogram=",
},
)
if err != nil {
errors.Logf("ERROR", "%v", err)
Usage(ErrorCodes["opts"])
}
histogram := ""
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "--histogram":
histogram = oa.Arg()
default:
errors.Logf("ERROR", "Unknown flag '%v'", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
var rptr miners.Reporter
if len(args) == 0 {
errors.Logf("ERROR", "You must supply an inner reporter to unique")
fmt.Fprintln(os.Stderr, "try: unique file")
Usage(ErrorCodes["opts"])
} else if _, has := reports[args[0]]; !has {
errors.Logf("ERROR", "Unknown reporter '%v'", args[0])
fmt.Fprintln(os.Stderr, "Reporters:")
for k := range reports {
fmt.Fprintln(os.Stderr, " ", k)
}
Usage(ErrorCodes["opts"])
} else {
rptr, args = reports[args[0]](reports, args[1:], fmtr, conf)
}
uniq, err := reporters.NewUnique(conf, fmtr, rptr, histogram)
if err != nil {
errors.Logf("ERROR", "Error creating unique reporter '%v'\n", err)
Usage(ErrorCodes["opts"])
}
return uniq, args
}
开发者ID:timtadh,项目名称:sfp,代码行数:47,代码来源:cmd.go
示例11: chainReporter
func chainReporter(reports map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"h",
[]string{
"help",
},
)
if err != nil {
errors.Logf("ERROR", "%v", err)
Usage(ErrorCodes["opts"])
}
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
default:
errors.Logf("ERROR", "Unknown flag '%v'", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
rptrs := make([]miners.Reporter, 0, 10)
for len(args) >= 1 {
if args[0] == "endchain" {
args = args[1:]
break
}
if _, has := reports[args[0]]; !has {
errors.Logf("ERROR", "Unknown reporter '%v'\n", args[0])
fmt.Fprintln(os.Stderr, "Reporters:")
for k := range reports {
fmt.Fprintln(os.Stderr, " ", k)
}
Usage(ErrorCodes["opts"])
}
var rptr miners.Reporter
rptr, args = reports[args[0]](reports, args[1:], fmtr, conf)
rptrs = append(rptrs, rptr)
}
if len(rptrs) == 0 {
errors.Logf("ERROR", "Empty chain")
fmt.Fprintln(os.Stderr, "try: chain log file")
Usage(ErrorCodes["opts"])
}
return &reporters.Chain{rptrs}, args
}
开发者ID:timtadh,项目名称:sfp,代码行数:46,代码来源:cmd.go
示例12: itemsetType
func itemsetType(argv []string, conf *config.Config) (lattice.Loader, func(lattice.DataType, lattice.PrFormatter) lattice.Formatter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hl:", []string{"help", "loader=", "min-items=", "max-items="},
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Usage(ErrorCodes["opts"])
}
loaderType := "int"
min := 0
max := int(math.MaxInt32)
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-l", "--loader":
loaderType = oa.Arg()
case "--min-items":
min = ParseInt(oa.Arg())
case "--max-items":
max = ParseInt(oa.Arg())
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
var loader lattice.Loader
switch loaderType {
case "int":
loader, err = itemset.NewIntLoader(conf, min, max)
default:
fmt.Fprintf(os.Stderr, "Unknown itemset loader '%v'\n", loaderType)
Usage(ErrorCodes["opts"])
}
if err != nil {
log.Panic(err)
}
fmtr := func(_ lattice.DataType, prfmt lattice.PrFormatter) lattice.Formatter {
return &itemset.Formatter{prfmt}
}
return loader, fmtr, args
}
开发者ID:timtadh,项目名称:sfp,代码行数:45,代码来源:cmd.go
示例13: heapProfileReporter
func heapProfileReporter(rptrs map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hp:a:e:",
[]string{
"help",
"profile=",
"after=",
"every=",
},
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Usage(ErrorCodes["opts"])
}
after := 0
every := 1
profile := ""
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-p", "--patterns":
profile = oa.Arg()
case "-a", "--after":
after = ParseInt(oa.Arg())
case "-e", "--every":
every = ParseInt(oa.Arg())
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
if profile == "" {
fmt.Fprintf(os.Stderr, "You must supply a location to write the profile (-p) in heap-profile.\n")
os.Exit(1)
}
r, err := reporters.NewHeapProfile(profile, after, every)
if err != nil {
fmt.Fprintf(os.Stderr, "There was error creating output files\n")
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
return r, args
}
开发者ID:timtadh,项目名称:sfp,代码行数:45,代码来源:cmd.go
示例14: skipReporter
func skipReporter(reports map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hs:",
[]string{
"help",
"skip=",
},
)
if err != nil {
errors.Logf("ERROR", "%v", err)
Usage(ErrorCodes["opts"])
}
skip := 0
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-s", "--skip":
skip = ParseInt(oa.Arg())
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
var rptr miners.Reporter
if len(args) == 0 {
fmt.Fprintln(os.Stderr, "You must supply an inner reporter to skip")
fmt.Fprintln(os.Stderr, "try: skip log")
Usage(ErrorCodes["opts"])
} else if _, has := reports[args[0]]; !has {
fmt.Fprintf(os.Stderr, "Unknown reporter '%v'\n", args[0])
fmt.Fprintln(os.Stderr, "Reporters:")
for k := range reports {
fmt.Fprintln(os.Stderr, " ", k)
}
Usage(ErrorCodes["opts"])
} else {
rptr, args = reports[args[0]](reports, args[1:], fmtr, conf)
}
r := reporters.NewSkip(skip, rptr)
return r, args
}
开发者ID:timtadh,项目名称:sfp,代码行数:43,代码来源:cmd.go
示例15: canonMaxReporter
func canonMaxReporter(reports map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"h",
[]string{
"help",
},
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Usage(ErrorCodes["opts"])
}
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
var rptr miners.Reporter
if len(args) == 0 {
fmt.Fprintln(os.Stderr, "You must supply an inner reporter to canon-max")
fmt.Fprintln(os.Stderr, "try: unique file")
Usage(ErrorCodes["opts"])
} else if _, has := reports[args[0]]; !has {
fmt.Fprintf(os.Stderr, "Unknown reporter '%v'\n", args[0])
fmt.Fprintln(os.Stderr, "Reporters:")
for k := range reports {
fmt.Fprintln(os.Stderr, " ", k)
}
Usage(ErrorCodes["opts"])
} else {
rptr, args = reports[args[0]](reports, args[1:], fmtr, conf)
}
m, err := reporters.NewCanonMax(rptr)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating canon-max reporter '%v'\n", err)
Usage(ErrorCodes["opts"])
}
return m, args
}
开发者ID:timtadh,项目名称:sfp,代码行数:43,代码来源:cmd.go
示例16: qsplorMode
func qsplorMode(argv []string, conf *config.Config) (miners.Miner, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hs:m:",
[]string{
"help",
"score-function=",
"max-queue-size=",
},
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
cmd.Usage(cmd.ErrorCodes["opts"])
}
var scorer qsplor.Scorer = qsplor.Scorers["random"]
var maxQueueSize int = 10
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
cmd.Usage(0)
case "-m", "--max-queue-size":
maxQueueSize = cmd.ParseInt(oa.Arg())
case "-s", "--score-function":
if _, has := qsplor.Scorers[oa.Arg()]; !has {
fmt.Fprintf(os.Stderr, "Unknown score function: %v\n", oa.Arg())
fmt.Fprintf(os.Stderr, "Valid score functions:\n")
for name, _ := range qsplor.Scorers {
fmt.Fprintf(os.Stderr, "%v\n", name)
}
cmd.Usage(cmd.ErrorCodes["opts"])
}
scorer = qsplor.Scorers[oa.Arg()]
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
cmd.Usage(cmd.ErrorCodes["opts"])
}
}
return qsplor.NewMiner(conf, scorer, maxQueueSize), args
}
开发者ID:timtadh,项目名称:sfp,代码行数:39,代码来源:main.go
示例17: fastmaxMode
func fastmaxMode(argv []string, conf *config.Config) (miners.Miner, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"h",
[]string{
"help",
},
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
cmd.Usage(cmd.ErrorCodes["opts"])
}
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
cmd.Usage(0)
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
cmd.Usage(cmd.ErrorCodes["opts"])
}
}
return fastmax.NewWalker(conf), args
}
开发者ID:timtadh,项目名称:sfp,代码行数:23,代码来源:main.go
示例18: dirReporter
func dirReporter(rptrs map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hd:",
[]string{
"help",
"dir-name=",
"show-pr",
},
)
if err != nil {
errors.Logf("ERROR", "%v", err)
Usage(ErrorCodes["opts"])
}
dir := "samples"
showPr := false
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-d", "--dir-name":
dir = oa.Arg()
case "--show-pr":
showPr = true
default:
errors.Logf("ERROR", "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
fr, err := reporters.NewDir(conf, fmtr, showPr, dir)
if err != nil {
errors.Logf("ERROR", "There was error creating output files\n")
errors.Logf("ERROR", "%v", err)
os.Exit(1)
}
return fr, args
}
开发者ID:timtadh,项目名称:sfp,代码行数:37,代码来源:cmd.go
示例19: muskMode
func muskMode(argv []string, conf *config.Config) (miners.Miner, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"h",
[]string{
"help",
},
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
cmd.Usage(cmd.ErrorCodes["opts"])
}
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
cmd.Usage(0)
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
cmd.Usage(cmd.ErrorCodes["opts"])
}
}
miner := walker.NewWalker(conf, musk.MakeMaxUniformWalk(musk.Next, nil))
return miner, args
}
开发者ID:timtadh,项目名称:sfp,代码行数:24,代码来源:main.go
示例20: main
func main() {
// Destroy after `main()` runs.
defer unboundInstance.Destroy()
// Parse and validate args.
leftovers, optargs, err := getopt.GetOpt(os.Args[1:], "p", []string{"preserve"})
if err != nil {
SyncPrintf("error: %s\n", err)
return
} else if len(leftovers) > 0 {
SyncPrintf("error: unrecognized parameter: %s\n", leftovers)
return
}
if len(optargs) > 0 && optargs[0].Opt() == "-p" {
//SyncPrintf("Found opt!\n")
preserveInput = true
}
domains := ReadLinesFromStdin(func(line string) string {
return strings.TrimSpace(line)
})
resultMap := make(map[string]bool)
for _, d := range domains {
resultMap[d] = false
}
tasks := make(chan string, CONCURRENCY) //len(domains))
// Spawn worker goroutines.
wg := new(sync.WaitGroup)
// Adding routines to workgroup and running then.
for i := 0; i < CONCURRENCY; i++ {
wg.Add(1)
go worker(tasks, wg)
}
receiver := func(numDomains int) {
defer wg.Done()
i := 0
Loop:
for {
select {
case result := <-ch:
//log.Println(result.response)
//domain, ips, err := ParseResponse(result.domain, result.response.String())
if err != nil {
SyncPrintf("failed :: domain=%s :: error=%s\n", result.domain, err.Error())
if preserveInput {
SyncPrintf("%s %s\n", result.originalLine, strings.Join(result.addresses, " "))
} else {
SyncPrintf("%s %s\n", result.domain, strings.Join(result.addresses, " "))
}
} else {
if preserveInput {
SyncPrintf("%s %s\n", result.originalLine, strings.Join(result.addresses, " "))
} else {
SyncPrintf("%s %s\n", result.domain, strings.Join(result.addresses, " "))
}
}
resultMap[result.domain] = true
i++
//fmt.Printf("%v/%v\n", i, numDomains)
if i == numDomains {
break Loop
}
/*for d, _ := range resultMap {
if resultMap[d] == false {
fmt.Printf("still waiting on: %v\n", d)
}
}*/
}
}
}
wg.Add(1)
go receiver(len(domains))
// Processing all links by spreading them to `free` goroutines
for _, domain := range domains {
tasks <- domain
}
close(tasks)
// Wait for the workers to finish.
wg.Wait()
}
开发者ID:nathanmyee,项目名称:go-bulk-dns-resolver,代码行数:90,代码来源:main.go
注:本文中的github.com/timtadh/getopt.GetOpt函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论