Example #1
0
func TestAnchorMerger(t *testing.T) {
	color.NoColor = false

	in := []byte(`---
vars: &v
  env: qa
deploy:
  env: live`)
	expect := `{"deploy":{"env":"live"},"vars":{"env":"qa"}}`

	if err := ioutil.WriteFile("/tmp/test", in, 0644); err != nil {
		color.Red("Error file not create")
		t.Error("Error file not create")
		t.Fail()
	}

	defer os.Remove("/tmp/test")

	if g, err := LoadFile("/tmp/test"); err != nil {
		color.Red("%v\n", err)
		t.Error(err)
		t.Fail()
	} else {
		if g.String() == expect {
			color.Green("\n%s: OK\n", "FileLoad")
		} else {
			color.Red("%s != %s", g.String(), expect)
			t.Error(fmt.Errorf("%s != %s", g.String(), expect))
			t.Fail()
		}
	}
}
Example #2
0
func getClientCredentials(c *cli.Context) []string {
	credentials := []string{c.GlobalString("client-id"), c.GlobalString("client-secret")}

	if credentials[0] == "" || credentials[1] == "" {
		color.Yellow("No client credentials given. Fallback to builtin default...")
		color.Yellow("Keep in mind that your document might be visible to other users.")
		color.Yellow("Your unique user-id is the only secret to protect your data.\n\n")

		superSecretSecret := []byte("V;4nJvuANmoywKNYk.yewNhqwmAQctc3BvByxeozQVpiK")

		// Decode HEX default credentials
		credentialsBytes, err := hex.DecodeString(defaultClientCredentials)
		if err != nil {
			color.Red("Error: client-id and client-secret missing and fallback decoding (step 1) failed: %s\n\n", err)
			cli.ShowCommandHelp(c, c.Command.FullName())
			os.Exit(1)
		}

		decodedCredentials := strings.Split(string(xorBytes(credentialsBytes, superSecretSecret)), ":")

		if len(decodedCredentials) < 2 {
			color.Red("Error: client-id and client-secret missing and fallback decoding (step 2) failed: %s\n\n", err)
			cli.ShowCommandHelp(c, c.Command.FullName())
			os.Exit(1)
		}
		credentials = decodedCredentials
	}

	return credentials
}
Example #3
0
// Build listens watch events from Watcher and sends messages to Runner
// when new changes are built.
func (b *Builder) Build(p *Params) {
	go b.registerSignalHandler()
	go func() {
		b.watcher.update <- true
	}()

	for <-b.watcher.Wait() {
		fileName := p.createBinaryName()

		pkg := p.GetPackage()

		color.Cyan("Building %s...\n", pkg)

		// build package
		cmd, err := runCommand("go", "build", "-o", fileName, pkg)
		if err != nil {
			log.Fatalf("Could not run 'go build' command: %s", err)
			continue
		}

		if err := cmd.Wait(); err != nil {
			if err := interpretError(err); err != nil {
				color.Red("An error occurred while building: %s", err)
			} else {
				color.Red("A build error occurred. Please update your code...")
			}

			continue
		}

		// and start the new process
		b.runner.restart(fileName)
	}
}
Example #4
0
func runAllProcessorTests(t *testing.T, cases map[string]processorTestCase) {
	color.NoColor = false

	json := `{
		"var1": "var1",
		"var-var": "var-var",
		"var": {"var": "1"},
		"version": "{{ feature }}-{{ feature-suffix }}",
		"feature": "value-unknown",
		"feature-suffix": "{{ feature }}",
		"list": [1, 2, 3]
	}`

	tree, err := gabs.ParseJSON([]byte(json))
	if err != nil {
		color.Red("%v: failed!\n", err)
		t.Fail()
	}

	for name, test := range cases {
		if res, err := Template(test.in, tree); err == nil {
			if test.expect == res {
				color.Green("%v: Ok\n", name)
			} else {
				color.Red("%v: %v != %v: failed!\n", name, test.expect, res)
				t.Fail()
			}
		} else {
			color.Red("error %v\n: failed!", err)
			t.Fail()
		}
	}
}
Example #5
0
func (n *Notifier) Run(message string) {
	switch n.Name {
	case "slack":
		if slack_api == nil {
			color.Red("[!] Slack used as a notifier, but not configured with ENV vars.")
			return
		}
		err = slack_api.ChatPostMessage(slack_channel.Id, message, &slack.ChatPostMessageOpt{IconEmoji: ":fire:"})
		if err != nil {
			color.Red(fmt.Sprintf("[!] Error posting to Slack: %s", err))
		}
	case "hipchat":
		if hipchat_api == nil {
			color.Red("[!] HipChat used as a notifier, but not configured with ENV vars.")
			return
		}
		_, err = hipchat_api.Room.Notification(os.Getenv("HIPCHAT_ROOM_ID"), &hipchat.NotificationRequest{Message: "Testing", Color: "red"})
		if err != nil {
			color.Red(fmt.Sprintf("[!] Error posting to HipChat: %s", err))
		}
	case n.Name: // default
		color.Yellow(fmt.Sprintf("[>] Unknown notifier: %s", n.Name))
	}

}
Example #6
0
func variables(v *vaulted.Vault) {
	exit := false

	for exit == false {
		printVariables(v)
		input := readMenu("\nEdit environment variables: [a,D,?,b]: ")
		switch input {
		case "a":
			variableKey := readValue("Name: ")
			variableValue := readValue("Value: ")
			if v.Vars == nil {
				v.Vars = make(map[string]string)
			}
			v.Vars[variableKey] = variableValue
		case "D":
			variable := readValue("Variable name: ")
			_, ok := v.Vars[variable]
			if ok {
				delete(v.Vars, variable)
			} else {
				color.Red("Variable '%s' not found", variable)
			}
		case "b":
			exit = true
		case "?", "help":
			variableMenu()
		default:
			color.Red("Command not recognized")
		}
	}
}
Example #7
0
func sshKeysMenu(v *vaulted.Vault) {
	exit := false

	for exit == false {
		printSSHKeys(v)
		input := readMenu("\nEdit ssh keys: [a,D,?,b]: ")
		switch input {
		case "a":
			addSSHKey(v)
		case "D":
			key := readValue("Key: ")
			_, ok := v.SSHKeys[key]
			if ok {
				delete(v.SSHKeys, key)
			} else {
				color.Red("Key '%s' not found", key)
			}
		case "b":
			exit = true
		case "?", "help":
			sshKeysHelp()
		default:
			color.Red("Command not recognized")
		}
	}
}
Example #8
0
func (r Documentation) Output(results <-chan []resource.TestResult) (hasFail bool) {
	testCount := 0
	var failed []resource.TestResult
	for resultGroup := range results {
		for _, testResult := range resultGroup {
			if testResult.Successful {
				fmt.Println(humanizeResult(testResult))
				testCount++
			} else {
				fmt.Println(humanizeResult(testResult))
				failed = append(failed, testResult)
				testCount++
			}
		}
		fmt.Println("")
	}

	fmt.Print("\n")
	if len(failed) > 0 {
		color.Red("Failures:")
		for _, testResult := range failed {
			fmt.Println(humanizeResult(testResult))
		}
		fmt.Print("\n")
	}

	if len(failed) > 0 {
		color.Red("Count: %d failed: %d\n", testCount, len(failed))
		return true
	}
	color.Green("Count: %d failed: %d\n", testCount, len(failed))
	return false
}
Example #9
0
func getOpts(context *cli.Context) (string, string, string, string, string) {
	etcdURI := context.String("etcd-uri")
	redisURI := context.String("redis-uri")
	redisQueue := context.String("redis-queue")
	deployStateUri := context.String("deploy-state-uri")
	cluster := context.String("cluster")

	if etcdURI == "" || redisURI == "" || redisQueue == "" || deployStateUri == "" || cluster == "" {
		cli.ShowAppHelp(context)

		if etcdURI == "" {
			color.Red("  Missing required flag --etcd-uri or GOVERNATOR_ETCD_URI")
		}
		if redisURI == "" {
			color.Red("  Missing required flag --redis-uri or GOVERNATOR_REDIS_URI")
		}
		if redisQueue == "" {
			color.Red("  Missing required flag --redis-queue or GOVERNATOR_REDIS_QUEUE")
		}
		if deployStateUri == "" {
			color.Red("  Missing required flag --deploy-state-uri or DEPLOY_STATE_URI")
		}
		if cluster == "" {
			color.Red("  Missing required flag --cluster or CLUSTER")
		}
		os.Exit(1)
	}

	return etcdURI, redisURI, redisQueue, deployStateUri, cluster
}
Example #10
0
func Validate(c *cli.Context, startTime time.Time) {
	gossConfig := getGossConfig(c)
	sys := system.New(c)
	outputer := getOutputer(c)

	sleep := c.Duration("sleep")
	retryTimeout := c.Duration("retry-timeout")
	i := 1
	for {
		iStartTime := time.Now()
		out := validate(sys, gossConfig, c.Int("max-concurrent"))
		exitCode := outputer.Output(os.Stdout, out, iStartTime)
		if retryTimeout == 0 || exitCode == 0 {
			os.Exit(exitCode)
		}
		elapsed := time.Since(startTime)
		if elapsed+sleep > retryTimeout {
			color.Red("\nERROR: Timeout of %s reached before tests entered a passing state", retryTimeout)
			os.Exit(3)
		}
		color.Red("Retrying in %s (elapsed/timeout time: %.3fs/%s)\n\n\n", sleep, elapsed.Seconds(), retryTimeout)
		// Reset cache
		sys = system.New(c)
		time.Sleep(sleep)
		i++
		fmt.Printf("Attempt #%d:\n", i)
	}
}
Example #11
0
func init() {
	// Verifies the existance of an anirip folder in our temp directory
	_, err := os.Stat(tempDir)
	if err != nil {
		os.Mkdir(tempDir, 0777)
	}

	// Checks for the existance of our AdobeHDS script which we will get if we don't have it
	_, err = os.Stat(tempDir + string(os.PathSeparator) + "AdobeHDS.php")
	if err != nil {
		adobeHDSResp, err := anirip.GetHTTPResponse("GET", "https://raw.githubusercontent.com/K-S-V/Scripts/master/AdobeHDS.php", nil, nil, nil)
		if err != nil {
			color.Red("[anirip] There was an error retrieving AdobeHDS.php script from GitHub...")
			return
		}
		defer adobeHDSResp.Body.Close()
		adobeHDSBody, err := ioutil.ReadAll(adobeHDSResp.Body)
		if err != nil {
			color.Red("[anirip] There was an error reading the AdobeHDS.php body...")
			return
		}
		err = ioutil.WriteFile(tempDir+string(os.PathSeparator)+"AdobeHDS.php", adobeHDSBody, 0777)
		if err != nil {
			color.Red("[anirip] There was an error writing AdobeHDS.php to file...")
			return
		}
	}
}
Example #12
0
File: main.go Project: sparrc/stash
func main() {
	flag.Usage = usageExit
	flag.Parse()
	if *fversion {
		fmt.Printf("Stash: Version - %s\n", Version)
		return
	}

	log.SetFlags(0)
	log.SetPrefix("DEBUG: ")
	args := flag.Args()
	if len(args) < 1 {
		usageExit()
	}

	switch args[0] {
	case "help":
		help(args[1:])
		return
	case "destination", "dest":
		runCmd(subcmd.Destination, args[1:])
		return
	case "folder", "fold":
		runCmd(subcmd.Folder, args[1:])
		return
	case "daemon", "daem":
		runCmd(subcmd.Daemon, args[1:])
		return
	}

	color.Red("stash: unknown subcommand %q\n", args[0])
	color.Red("Run 'stash help' for usage.\n")
	os.Exit(2)
}
Example #13
0
func (r Rspecish) Output(results <-chan []resource.TestResult, startTime time.Time) (exitCode int) {
	testCount := 0
	var failed []resource.TestResult
	for resultGroup := range results {
		for _, testResult := range resultGroup {
			if testResult.Successful {
				fmt.Printf(green("."))
			} else {
				fmt.Printf(red("F"))
				failed = append(failed, testResult)
			}
			testCount++
		}
	}

	fmt.Print("\n\n")
	if len(failed) > 0 {
		color.Red("Failures:")
		for _, testResult := range failed {
			fmt.Println(humanizeResult(testResult))
		}
		fmt.Print("\n")
	}

	fmt.Printf("Total Duration: %.3fs\n", time.Since(startTime).Seconds())
	if len(failed) > 0 {
		color.Red("Count: %d, Failed: %d\n", testCount, len(failed))
		return 1
	}
	color.Green("Count: %d, Failed: %d\n", testCount, len(failed))
	return 0
}
Example #14
0
func CopyFile(conn *ssh.Client, FileName, DirectoryPath string) bool {
	defer conn.Close()
	if !strings.HasSuffix(DirectoryPath, "/") {
		DirectoryPath = DirectoryPath + "/"
	}
	con, err := sftp.NewClient(conn, sftp.MaxPacket(5e9))
	if err != nil {
		color.Red("%s传输文件新建会话错误: %s\n", conn.RemoteAddr(), err)
		return false
	}
	sFile, _ := os.Open(FileName)
	defer sFile.Close()
	dFile := DirectoryPath + FileName
	fmt.Printf("%s 目标路径:%s\n", conn.RemoteAddr(), dFile)
	File, err := con.OpenFile(dFile, os.O_CREATE|os.O_TRUNC|os.O_RDWR)
	if err != nil {
		color.Red("%s 创建文件%s错误: %s \n", conn.RemoteAddr(), dFile, err)
		return false
	}
	defer File.Close()
	for {
		buf := make([]byte, 1024)
		n, err := sFile.Read(buf)
		if err != nil {
			if err.Error() == "EOF" {
				break
			}
			return false
		}
		File.Write(buf[:n])
	}
	Result <- fmt.Sprintf("上传%s到%s成功.\n", FileName, conn.RemoteAddr())
	return true
}
Example #15
0
func copyfile() {
	color.Yellow("开始执行文件发送:")
	info, err := os.Lstat(all_ssh.ArgsInfo.File)
	if err != nil || info.IsDir() {
		color.Blue("检查要发送的文件.")
		return
	}
	for _, v := range all_ssh.ServerList {
		go func() {
			client := all_ssh.Connection(v)
			if client != nil {
				all_ssh.CopyFile(client, all_ssh.ArgsInfo.File, all_ssh.ArgsInfo.Dir)
			}
		}()
	}
	var num int
	var Over chan os.Signal = make(chan os.Signal, 1)
	go signal.Notify(Over, os.Interrupt, os.Kill)
	go result(&num, Over)
	<-Over
	color.Yellow("一共有%d条错误.\n", len(all_ssh.ErrorList))
	for _, v := range all_ssh.ErrorList {
		color.Red(v)
	}
	color.Red("收到结果:%d条\n", num)
}
Example #16
0
func (m *Manager) printError(body []byte) {
	e := Error{}
	err := json.Unmarshal(body, &e)
	if err != nil {
		color.Red(err.Error())
	}

	color.Red(e.Message)
}
Example #17
0
File: gini.go Project: gini/gapicmd
func uploadDocument(c *cli.Context) {
	filename := c.String("filename")
	doctype := c.String("doctype")
	userid := getUserIdentifier(c)

	if len(c.Args()) < 1 {
		cli.ShowCommandHelp(c, c.Command.FullName())
		return
	}

	if _, err := os.Stat(c.Args().First()); os.IsNotExist(err) {
		color.Red("\nError: cannot find %s\n\n", c.Args().First())
		cli.ShowCommandHelp(c, c.Command.FullName())
		return
	}

	bodyBuf, err := os.Open(c.Args().First())
	if err != nil {
		color.Red("\nError: failed to read %s\n\n", c.Args().First())
		cli.ShowCommandHelp(c, c.Command.FullName())
		return
	}

	api := getApiClient(c)

	doc, err := api.Upload(bodyBuf, giniapi.UploadOptions{
		FileName:       filename,
		DocType:        doctype,
		UserIdentifier: userid,
	})

	if err != nil {
		color.Red("\nError: %s\n\n", err)
		return
	}

	done <- true
	wg.Wait()

	renderResults(doc)

	if c.GlobalBool("curl") {
		curl := curlData{
			Headers: map[string]string{
				"Accept":            "application/vnd.gini.v1+json",
				"X-User-Identifier": userid,
			},
			Body:   fmt.Sprintf("--data-binary '@%s'", c.Args().First()),
			URL:    fmt.Sprintf("%s/documents", api.Endpoints.API),
			Method: "POST",
		}

		curl.render(c)
	}
}
Example #18
0
File: gini.go Project: gini/gapicmd
func getProcessed(c *cli.Context) {
	userid := getUserIdentifier(c)

	if len(c.Args()) != 2 {
		cli.ShowCommandHelp(c, c.Command.FullName())
		return
	}

	api := getApiClient(c)
	u := fmt.Sprintf("%s/documents/%s", api.Endpoints.API, c.Args().First())

	doc, err := api.Get(u, userid)

	if err != nil {
		color.Red("\nError: %s\n\n", err)
		return
	}

	body, err := doc.GetProcessed()

	if err != nil {
		color.Red("\nError: %s\n\n", err)
		return
	}

	err = ioutil.WriteFile(c.Args()[1], body, 0644)

	if err != nil {
		color.Red("\nError: %s\n\n", err)
		return
	}

	done <- true
	wg.Wait()

	renderResults(doc)

	if c.GlobalBool("curl") {
		curl := curlData{
			Headers: map[string]string{
				"Accept":            "application/vnd.gini.v1+json,application/octet-stream",
				"X-User-Identifier": userid,
			},
			Body:   "",
			URL:    doc.Links.Processed,
			Method: "GET",
		}

		curl.render(c)
	}
}
Example #19
0
File: gini.go Project: gini/gapicmd
func getExtractions(c *cli.Context) {
	incubator := c.Bool("incubator")
	userid := getUserIdentifier(c)

	if len(c.Args()) < 1 {
		cli.ShowCommandHelp(c, c.Command.FullName())
		return
	}

	api := getApiClient(c)
	u := fmt.Sprintf("%s/documents/%s", api.Endpoints.API, c.Args().First())

	doc, err := api.Get(u, userid)

	if err != nil {
		color.Red("\nError: %s\n\n", err)
		return
	}

	ext, err := doc.GetExtractions(incubator)
	if err != nil {
		color.Red("\nError: %s\n\n", err)
		return
	}

	done <- true
	wg.Wait()

	renderResults(ext)

	if c.GlobalBool("curl") {
		accept := "application/vnd.gini.v1+json"
		if incubator {
			accept = "application/vnd.gini.incubator+json"
		}

		curl := curlData{
			Headers: map[string]string{
				"Accept":            accept,
				"X-User-Identifier": userid,
			},
			Body:   "",
			URL:    doc.Links.Extractions,
			Method: "GET",
		}

		curl.render(c)
	}
}
func handleInteractiveMode() {
	reader := bufio.NewReader(os.Stdin)
	for {
		red := color.New(color.FgCyan)
		red.Printf("%s %s %s => ", time.Now().Format("15:04:05"), *serverFlag, *executorFlag)

		line, err := reader.ReadString('\n')
		if err != nil {
			log.Fatal(color.RedString("ERROR reading string: %s", err.Error()))
		}
		line = strings.Trim(line, "\r\n")

		if strings.EqualFold(line, "exit") {
			color.Green("Exit command received. Good bye.")
			os.Exit(0)
		}

		exeAndArgs, err := parsecommand.Parse(line)
		if err != nil {
			color.Red("Cannot parse line '%s', error: %s", line, err.Error())
			continue
		}

		var exe string
		var args []string = []string{}

		exe = exeAndArgs[0]
		if len(exeAndArgs) > 1 {
			args = exeAndArgs[1:]
		}

		onFeedback := func(fb string) {
			fmt.Println(fb)
		}

		color.Green("Exe '%s' and args '%#v'", exe, args)
		color.Yellow("-------------------------------------")
		println()
		err = execute(false, onFeedback, *serverFlag, *executorFlag, *clientPemFlag, exe, args...)
		if err != nil {
			color.Red("Execute failed with error: %s", err.Error())
			continue
		}
		println()
		color.Yellow("-------------------------------------")
		println()
		println()
	}
}
Example #21
0
func ReadKey(keypath []string) {
	for _, v := range keypath {
		buf, err := ioutil.ReadFile(v)
		if err != nil {
			color.Red("读取key文件%s失败:\n%s\n", v, err)
			os.Exit(1)
		}
		signer, err := ssh.ParsePrivateKey(buf)
		if err != nil {
			color.Red("解析key文件%s失败:\n%s\n", v, err)
			os.Exit(1)
		}
		privateKey = append(privateKey, ssh.PublicKeys(signer))
	}
}
Example #22
0
func (s *Service) Save(h *Hit) {
	h.SetStore(s.Store)
	bytes, e := h.AsBytes()
	if e != nil {
		color.Red("%s", e)
		// TODO
		_ = e
	}
	e = s.Store.Binlog().Append(bytes)
	if e != nil {
		color.Red("%s", e)
		// TODO
		_ = e
	}

	siteId, e := s.Store.SiteId(h.Host)
	if e != nil {
		color.Red("%s", e)
		// TODO
		_ = e
	}

	if ok, e := s.Store.NeedFlush(siteId); ok {
		if e != nil {
			color.Red("%s", e)
			// TODO
			_ = e
		}
		e = s.Store.Flush(siteId)
		if e != nil {
			color.Red("%s", e)
			// TODO
			_ = e
		}
	}

	_, e = s.Store.IncHit(siteId)
	if e != nil {
		color.Red("%s", e)
		// TODO
		_ = e
	}

	uid, e := s.Store.UserId(h.Uid)
	if e != nil {
		color.Red("%s", e)
		// TODO
		_ = e
	}

	_, e = s.Store.TodayUnique(siteId, uid)
	if e != nil {
		color.Red("%s", e)
		// TODO
		_ = e
	}

}
Example #23
0
func (r Results) print(limit int) {
	i := 0
	if r.ResultType == "exact" {
		for _, def := range r.List {
			if limit == -1 || i < limit {
				// ugly code for windows!
				color.Set(color.FgBlue)
				fmt.Printf("%d)\n", i+1)
				color.Unset()

				color.Set(color.FgGreen)
				fmt.Printf("%s\n", "Def:")
				color.Unset()
				fmt.Println(def.Definition)

				color.Set(color.FgGreen)
				fmt.Printf("%s\n", "Eg:")
				color.Unset()
				fmt.Printf("%s\n\n", def.Example)
				i++
			}
		}
	} else {
		color.Red("No definitions.\n")
		return
	}
}
Example #24
0
func (c *Client) doError(messages ...error) {
	bold_yellow := color.New(color.FgYellow, color.Bold)
	bold_yellow.Println("Got error! ===>")
	for _, msg := range messages {
		color.Red("  " + msg.Error())
	}
}
Example #25
0
//
// required for serach options
//
func getSearchOpt() (SearchType, FilterType) {
	var (
		search SearchType = SearchBySubject
		filter FilterType = SearchFilterAll
	)

	for {
		color.White("Please select search range:\n")
		for k := SearchFilterAll; k <= SearchConference; k++ {
			fmt.Fprintf(color.Output, "\t %s: %s\n", color.CyanString("%d", k), searchFilterHints[k])
		}

		fmt.Fprintf(color.Output, "$ %s", color.CyanString("select: "))
		s := getInputString()
		if len(s) > 0 {
			selected, err := strconv.ParseInt(s, 16, 32)
			if err != nil || selected < int64(SearchFilterAll) || selected > int64(SearchConference) {
				color.Red("Invalid selection\n")
				continue
			}

			filter = FilterType(selected)
		}

		break
	}

	return search, filter
}
Example #26
0
// Read in and parse the congig
// path: Path to config file
func initConf(path string) error {
	// Load settings from conf.json
	file, err := os.Open(path)
	decoder := json.NewDecoder(file)

	// Could not load config file.
	if err != nil {
		color.Red("ERROR:", err)

		if path != "conf.json" {
			fmt.Println("Looking in current directory")
			initConf("./conf.json")
		}
		return err
	}

	// Handle parsing errors
	err = decoder.Decode(&Conf)

	if err != nil {
		fmt.Println("error:", err.Error())
		return err
	}

	if Debug {
		color.Green("[SETTINGS: OK]")
		fmt.Println("Settings Data:", Conf)
	}

	return nil
}
Example #27
0
func ProcessResult(jresult *JobResult) {

	cnt += 1
	TotalDone += 1
	elapsed := time.Since(stTime)

	Rate = float64(cnt) / elapsed.Seconds()

	if elapsed.Seconds() > float64(15) {
		cnt = 1
		stTime = time.Now()
		// color.Blue("\nResetting Counter")
	}

	// color.Cyan("#%d - Rate: %f jobs/seconds\n", TotalDone, Rate)
	if jresult.Status != 0 {
		color.Red("Error: %s", jresult.ErrorMsg)
	}

	resultsToDispatch = append(resultsToDispatch, jresult)

	if len(resultsToDispatch) > Config.DispatchBufferSize {
		DispatchMassResults()
		resultsToDispatch = [](*JobResult){}
	}

}
Example #28
0
File: main.go Project: jordic/tenv
// TEST="asdf,asdf,asdf" ./main template.tpl
func main() {

	if len(os.Args) != 2 {
		color.Red("tenv: v.01")
		color.Blue("------------------------")
		color.Cyan("Prepopulates to stdin given template with information stored in env variables")
		color.Cyan("variables should follow go template syntax {{.VAR_NAME}}")
		color.Cyan("and must be declared on the environment")
		color.Cyan("Usage : tenv filename")
		os.Exit(1)
	}
	var funcMap template.FuncMap
	funcMap = template.FuncMap{
		"split": strings.Split,
	}

	file := filepath.Base(os.Args[1])

	t, err := template.New(file).Funcs(funcMap).ParseFiles(os.Args[1])
	if err != nil {
		log.Fatalf("Error: %s", err)
	}

	context := make(map[string]string)
	for _, v := range os.Environ() {
		p := strings.Split(v, "=")
		context[p[0]] = p[1]
	}

	err = t.ExecuteTemplate(os.Stdout, file, context)
	if err != nil {
		log.Fatal(err)
	}

}
Example #29
0
// Fatalf is a convenience method appending a fatal message to the logger
func Fatalf(msg string, a ...interface{}) {
	_, fn, line, _ := runtime.Caller(1)
	msg = fmt.Sprintf(msg, a...)
	msg = fmt.Sprintf("%+v%s:%d\n\n", msg, fn, line)
	formattedMessage := formattedLogMessage("ERROR", msg)
	color.Red(formattedMessage)
}
Example #30
0
// Fatal is a convenience method appending a fatal message to the logger
func Fatal(obj interface{}) {
	// Get the line number and calling func sig
	_, fn, line, _ := runtime.Caller(1)
	msg := fmt.Sprintf("%+v\n%s:%d\n\n", obj, fn, line)
	formattedMessage := formattedLogMessage("ERROR", msg)
	color.Red(formattedMessage)
}