Пример #1
0
Файл: main.go Проект: tav/bolt
func (r Registry) Main(ctx *Context, args []string) {
	opts := optparse.Parser("Usage: bolt <command-1> <command-2> ... [options]\n", "bolt 0.1")
	opts.String([]string{"--boltfile"}, "",
		"use the Boltfile at the given path", "PATH")
	opts.String([]string{"--gen"}, "",
		"save the generated executable at the given path", "PATH")
	opts.Bool([]string{"--recompile"}, false,
		"recompile the generated executable instead of using cached builds")
	noConsoleLog := opts.BoolConfig("no-console-log", false,
		"disable logging to the console [false]")
	completions := append(ctx.completions, r.Keys()...)
	opts.Completer = optparse.ListCompleter(completions...)
	opts.Parse(args)
	if len(args) == 1 {
		listing := r.Listing()
		fmt.Print(listing)
		runtime.Exit(0)
	}
	if !*noConsoleLog {
		log.AddConsoleLogger()
	}
	buf := &bytes.Buffer{}
	yaml.NormaliseID(buf, args[1])
	cmd := buf.String()
	if task, ok := r[cmd]; ok {
		task.Func.Call([]reflect.Value{reflect.ValueOf(ctx)})
	} else {
		fmt.Printf("Task not found:\n\n\t%s\n\n", args[1])
		runtime.Exit(1)
	}
}
Пример #2
0
func main() {

	opts := optparse.Parser(
		"Usage: matchdb <config.yaml> [options]\n",
		"matchdb 0.0.1")

	host := opts.StringConfig("host", "",
		"the host to bind matchdb to")

	port := opts.IntConfig("port", 8090,
		"the port to bind matchdb to [8090]")

	allocLimit := opts.IntConfig("alloc-limit", 5000000,
		"maximum allocation limit in kilobytes [5000000]")

	hashKey := opts.StringConfig("hash-key", "",
		"16-byte hash key encoded as a 32-byte hex string")

	awsAccessKey := opts.StringConfig("aws-access-key", "",
		"the AWS Access Key for DynamoDB")

	awsSecretKey := opts.StringConfig("aws-secret-key", "",
		"the AWS Secret Key for DynamoDB")

	awsRegion := opts.StringConfig("aws-region", "us-east-1",
		"the AWS Region for DynamoDB [us-east-1]")

	masterTable := opts.StringConfig("master-table", "",
		"the DynamoDB table for the master lock")

	masterTimeout := opts.IntConfig("master-timeout", 6000,
		"timeout in milliseconds for the master lock [6000]")

	os.Args[0] = "matchdb"
	runtime.DefaultOpts("matchdb", opts, os.Args)

	initHashKey(*hashKey)
	master := NewMaster("", *awsAccessKey, *awsSecretKey, *awsRegion, *masterTable, time.Duration(*masterTimeout)*time.Millisecond)

	db := &DB{}
	db.Run(*host, *port, master, int64(*allocLimit))

}
Пример #3
0
func main() {

	opts := optparse.Parser("Usage: genapi [options]", "0.1")

	root := opts.String(
		[]string{"-r", "--root"}, "../src/espra",
		"path to the root package directory for the app", "PATH")

	ignoreList := opts.String(
		[]string{"-i", "--ignore"}, "api.go html.go",
		"space-separated list of files/subdirectories to ignore", "LIST")

	digestFile := opts.String(
		[]string{"-d", "--digest"}, "../etc/app/version.digest",
		"path to write the digest of the API version", "PATH")

	os.Args[0] = "genapi"
	opts.Parse(os.Args)
	log.AddConsoleLogger()

	ignore := strings.Split(*ignoreList, " ")
	for i, path := range ignore {
		ignore[i] = filepath.Join(*root, path)
	}

	pkgpath := strings.Split(*root, "/")
	pkgname := pkgpath[len(pkgpath)-1]

	if err := parseDirectory(pkgname, pkgname, *root, ignore); err != nil {
		runtime.StandardError(err)
	}

	for _, method := range methods {
		log.Info("%#v", method)
	}
	log.Wait()

	_ = *digestFile

}
Пример #4
0
func main() {

	// Define the options for the command line and config file options parser.
	opts := optparse.Parser(
		"Usage: matchweb <config.yaml> [options]\n",
		"matchweb 0.0.1")

	host := opts.StringConfig("host", "",
		"the host to bind the matchweb to")

	port := opts.IntConfig("port", 9040,
		"the port to bind the matchweb to [9040]")

	redirectURL := opts.StringConfig("redirect-url", "",
		"the URL that the HTTP Redirector redirects to")

	redirectorHost := opts.StringConfig("redirector-host", "",
		"the host to bind the HTTP Redirector to")

	redirectorPort := opts.IntConfig("redirector-port", 9080,
		"the port to bind the HTTP Redirector to [9080]")

	hstsMaxAge := opts.IntConfig("hsts-max-age", 31536000,
		"max-age value of HSTS in number of seconds [0 (disabled)]")

	clusterID := opts.StringConfig("cluster-id", "",
		"the cluster id to use when responding to ping requests")

	matchdbServer := opts.StringConfig("matchdb-server", "",
		"the address for a single-node MatchDB server setup")

	hashKey := opts.StringConfig("hash-key", "",
		"16-byte hash key encoded as a 32-byte hex string")

	awsAccessKey := opts.StringConfig("aws-access-key", "",
		"the AWS Access Key for DynamoDB")

	awsSecretKey := opts.StringConfig("aws-secret-key", "",
		"the AWS Secret Key for DynamoDB")

	awsRegion := opts.StringConfig("aws-region", "us-east-1",
		"the AWS Region for DynamoDB [us-east-1]")

	masterTable := opts.StringConfig("master-table", "",
		"the DynamoDB table for the master lock")

	masterTimeout := opts.IntConfig("master-timeout", 6000,
		"timeout in milliseconds for the master lock [6000]")

	routingTimeout := opts.IntConfig("routing-timeout", 3000,
		"timeout in milliseconds for routing entries [3000]")

	publishKey := opts.StringConfig("publish-key", "",
		"the shared secret for publishing new items")

	publishClusterID := opts.IntConfig("publish-cluster-id", 0,
		"the cluster id to use when acknowledging publish requests")

	upstreamHost := opts.StringConfig("upstream-host", "localhost",
		"the upstream host to connect to [localhost]")

	upstreamPort := opts.IntConfig("upstream-port", 8080,
		"the upstream port to connect to [8080]")

	upstreamTLS := opts.BoolConfig("upstream-tls", false,
		"use TLS when connecting to upstream [false]")

	websocketOrigin := opts.StringConfig("websocket-origin", "",
		"limit websocket calls to the given origin if specified")

	maintenanceMode := opts.BoolConfig("maintenance", false,
		"start up in maintenance mode [false]")

	// Setup the console log filter.
	log.ConsoleFilters[logPrefix] = func(items []interface{}) (bool, []interface{}) {
		return true, items[2 : len(items)-2]
	}

	// Parse the command line options.
	os.Args[0] = "matchweb"
	runtime.DefaultOpts("matchweb", opts, os.Args)

	// Initialise the TLS config.
	tlsconf.Init()

	// Initialise ping/pong variables.
	setupPong("matchweb", *clusterID)

	// Initialise the key for hashing slots.
	initHashKey(*hashKey)

	// Ensure required config values.
	if *publishKey == "" {
		runtime.Error("The publish-key cannot be empty")
	}

	server := &LiveServer{
		httpClient:       &http.Client{Transport: &http.Transport{TLSClientConfig: tlsconf.Config}},
		publishKey:       []byte(*publishKey),
		publishKeyLength: len(*publishKey),
		websocketOrigin:  *websocketOrigin,
	}

	setUpstreamInfo(server, *upstreamHost, *upstreamPort, *upstreamTLS, *publishClusterID)

	if *hstsMaxAge != 0 {
		server.hstsEnabled = true
		server.hsts = fmt.Sprintf("max-age=%d", *hstsMaxAge)
	}

	// Enable maintenance handling.
	frontends := []Maintainable{server}
	handleMaintenance(frontends, *maintenanceMode)

	// Setup the HTTP Redirector.
	runRedirector(*redirectorHost, *redirectorPort, *redirectURL, *hstsMaxAge)

	// Run the Live Server.
	runHTTP("Live Server", *host, *port, server, "")

	// Enter the wait loop for the process to be killed.
	loopForever := make(chan bool, 1)
	<-loopForever

}
Пример #5
0
func main() {

	opts := optparse.Parser("Usage: html2domly [options]", "v")

	outputFile := opts.String([]string{"-o", "--output"}, "../coffee/templates.coffee", "coffeescript file to compile to", "PATH")
	templatesSrcDir := opts.String([]string{"-i", "--input"}, "../etc/domly", "template source directory", "PATH")
	printJSON := opts.Bool([]string{"--print"}, false, "Print the JSON nicely to the output logger")

	os.Args[0] = "html2domly"
	opts.Parse(os.Args)

	log.AddConsoleLogger()

	var (
		data      []byte
		err       error
		prettyStr string
		basename  string
		pretty    bytes.Buffer
	)

	dir, err := os.Open(*templatesSrcDir)
	if err != nil {
		runtime.StandardError(err)
	}
	defer dir.Close()

	out, err := os.Create(*outputFile)
	if err != nil {
		runtime.StandardError(err)
	}
	defer out.Close()

	names, err := dir.Readdirnames(0)
	if err != nil {
		runtime.StandardError(err)
	}

	out.Write([]byte("define 'templates', (exports, root) ->\n"))

	for _, name := range names {
		if strings.HasSuffix(name, ".html") {
			basename = strings.TrimSuffix(name, ".html")
		} else {
			log.Error("file %v does not end in .html", name)
			continue
		}

		templatePath := filepath.Join(*templatesSrcDir, name)
		data, err = ui.ParseTemplate(templatePath)
		if err != nil {
			log.StandardError(err)
		} else {

			err := json.Indent(&pretty, data, ">", "  ")
			if err != nil {
				log.StandardError(err)
				log.Info("%v", data)
			} else if *printJSON {
				prettyStr = pretty.String()
				pretty.Reset()
				log.Info("%v", prettyStr)
			}
			out.Write([]byte(fmt.Sprintf("  exports['%s'] = `%s`\n", basename, data)))
			log.Info("compiled '%s'", name)
		}

	}
	out.Write([]byte("  return"))

	outPath, _ := filepath.Abs(*outputFile)
	log.Info("compiled domly written to: %v", outPath)

	log.Wait()

}