Beispiel #1
0
func main() {
	var x float32
	var y int
	var ch1, ch2 string
	var name string

	fmt.Println("Enter a character")
	if _, err := fmt.Scanln(&ch1); err != nil {
		fmt.Println("Error:", err)
	}

	fmt.Println("Enter a number")
	if _, err := fmt.Scanln(&y); err != nil {
		fmt.Println("Error:", err)
	}

	fmt.Println("Enter another character")
	if _, err := fmt.Scanln(&ch2); err != nil {
		fmt.Println("Error:", err)
	}

	fmt.Println("Enter a name")
	if _, err := fmt.Scanf("%s", &name); err != nil {
		fmt.Println("Error:", err)
	}

	fmt.Println("Enter a floating point value")
	if _, err := fmt.Scanf("%g", &x); err != nil {
		fmt.Println("Error:", err)
	}

	// Display the values read
	fmt.Printf("ch1\t=\t%s\ny\t=\t%d\nch2\t=\t%s\nName\t=\t%s\nx\t=\t%g\n",
		ch1, y, ch2, name, x)
}
Beispiel #2
0
func runLogin(cmd *Command, args []string) {
	if len(args) != 0 {
		cmd.PrintUsage()
		os.Exit(2)
	}

	oldEmail := client.Username
	var email string
	if oldEmail == "" {
		fmt.Printf("Enter email: ")
	} else {
		fmt.Printf("Enter email [%s]: ", oldEmail)
	}
	_, err := fmt.Scanln(&email)
	switch {
	case err != nil && err.Error() != "unexpected newline":
		printFatal(err.Error())
	case email == "" && oldEmail == "":
		printFatal("email is required.")
	case email == "":
		email = oldEmail
	}

	// NOTE: gopass doesn't support multi-byte chars on Windows
	password, err := readPassword("Enter password: "******"unexpected newline":
		printFatal("password is required.")
	default:
		printFatal(err.Error())
	}

	address, token, err := attemptLogin(email, password, "")
	if err != nil {
		if herror, ok := err.(heroku.Error); ok && herror.Id == "two_factor" {
			// 2FA requested, attempt 2FA login
			var twoFactorCode string
			fmt.Printf("Enter two-factor auth code: ")
			if _, err := fmt.Scanln(&twoFactorCode); err != nil {
				printFatal("reading two-factor auth code: " + err.Error())
			}
			address, token, err = attemptLogin(email, password, twoFactorCode)
			must(err)
		} else {
			must(err)
		}
	}

	nrc, err = hkclient.LoadNetRc()
	if err != nil {
		printFatal("loading netrc: " + err.Error())
	}

	err = nrc.SaveCreds(address, email, token)
	if err != nil {
		printFatal("saving new token: " + err.Error())
	}
	fmt.Println("Logged in.")
}
Beispiel #3
0
func loginAction(c *cli.Context) {
	api := getAPI(c)
	var url string
	var version string
	var username string
	var password string
	fmt.Printf("URL: ")
	_, urlErr := fmt.Scanln(&url)
	if urlErr != nil {
		panic(urlErr)
	}
	fmt.Printf("Username: "******"Version (default: 1): ")
	_, verErr := fmt.Scanln(&version)
	if verErr != nil {
		version = "1"
	}
	userData, loginErr := api.Login(url, username, password)
	if loginErr != nil {
		LogMessage("Error logging in.  Please check username/password.", "r")
		os.Exit(1)
	}
	saveConfig(username, userData.ApiKey, url, version, c.GlobalString("config"))
	LogMessage("Login successful", "g")
}
Beispiel #4
0
func main() {
	var pin string
	var nickname string
	fmt.Print("Enter game pin: ")
	fmt.Scanln(&pin)
	fmt.Print("Enter nickname: ")
	fmt.Scanln(&nickname)
	fmt.Println("Connecting...")
	conn, err := kahoot.NewConnection(pin)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(1)
	}
	if err := conn.Register(nickname); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	fmt.Println("Awaiting questions...")
	for {
		if conn.WaitQuestion() != nil {
			fmt.Println("Done question loop:", err)
			os.Exit(1)
		}
		fmt.Print("Got question. Answer: ")
		var number string
		fmt.Scanln(&number)
		parsed, _ := strconv.Atoi(number)
		if err := conn.SendAnswer(parsed); err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
	}
}
Beispiel #5
0
func gravatar() {
	var name, email string

	fmt.Println("Please enter your first name")
	fmt.Scanln(&name)

	fmt.Println("Please enter your email")
	fmt.Scanln(&email)

	email = strings.ToLower(email)

	h := md5.New()
	io.WriteString(h, email)
	finalBytes := h.Sum(nil)
	finalString := hex.EncodeToString(finalBytes)

	//generate page
	t, _ := template.New("tpl3").Parse(`
	{{define "Gravatar"}}
		<h1>{{.Name}}</h1>
		<img src="http://www.gravatar.com/avatar/{{.Email}}"/>
	{{end}}
	`)
	out, _ := os.Create("myGravatar.html")
	_ = t.ExecuteTemplate(out, "Gravatar", Person{name, finalString})
}
func main() {
	var len1 float64
	var bre1 float64
	var choice int

	fmt.Println("\n********PERIMETER OF SHAPE************\n Enter 1 for Rectangle\n Enter 2 for Circle")
	fmt.Scanln(&choice)
	switch choice {
	case 1:
		{
			fmt.Println("Enter the length and breadth of rectangle::")
			fmt.Scanln(&len1, &bre1)
			r := rectangle{len: len1, breadth: bre1}
			fmt.Println("Details of the rectangle are:", r)
			s := shape(r)
			fmt.Println("Perimeter of rectangle is ::", s.perimeter())
		}
	case 2:
		{
			var rad float64
			fmt.Println("Enter the radius of the Circle")
			fmt.Scanln(&rad)
			c := circle{radius: rad}
			fmt.Println("Details of circle are:", c)
			s := shape(c)
			s = c
			fmt.Println("The perimeter of circle is", s.perimeter())
		}
	default:
		fmt.Println("Wrong Choice")
	}
}
Beispiel #7
0
func main() {
	rows, cols, gen := 0, 0, 0
	var row string
	var board []string
	fmt.Scanf("%d %d", &rows, &cols)
	fmt.Scanln(&row)
	board = add_wall_row(cols+2, board)
	for i := 0; i < rows; i++ {
		fmt.Scanln(&row)
		row = WALL + row + WALL
		board = append(board, row)
	}
	board = add_wall_row(cols+2, board)
	for {
		gen += 1
		fmt.Printf("Generation %d:\n", gen)
		print(board)
		new_board := generation(board)
		if compare_boards(board, new_board) || gen >= MAX_GENS {
			gen += 1
			fmt.Printf("Generation %d:\n", gen)
			print(new_board)
			return
		}
		board = new_board
	}
}
func main() {
	n := 0
	eps := 1e-2
	var a float64
	var b float64
	fmt.Println("a: ")
	fmt.Scanln(&a)
	fmt.Println("b: ")
	fmt.Scanln(&b)

	fmt.Println("n", "a", "b", "m", "|Dx/2|")
	for {
		m := (a + b) / 2.0
		Dx := math.Abs((b - a) / 2.0)
		fmt.Println(n+1, a, b, m, Dx)
		if f(a)*f(m) < 0 {
			b = m
		} else {
			a = m
		}
		n++
		if Dx < eps {
			break
		}
	}
}
Beispiel #9
0
func do_singletest(wi wordinfo, date time.Time, nr, total int) {
	input := ""
	question := wi.Word

	fmt.Printf("==============================================\n")
	fmt.Printf("Question %d/%d:\n", nr, total)
	fmt.Printf("\n [[ %s ]]\n", wi.Word)
	fmt.Printf("\n\nPress Enter after you remember the meaning of it:\n")
	fmt.Printf("\n Reference: %d Test success/fail: %d/%d\n",
		wi.Totalfreq, len(wi.Succ_history), len(wi.Fail_history))
	fmt.Scanln(&input)
	fmt.Printf("----------------------------------------------\n")
	fmt.Printf("The maning of %s was:\n%s\n\n",
		question, daum_dict(question))
	fmt.Printf("----------------------------------------------\n")
	fmt.Printf("Were you understanding it well? (Yes/No)\n")
	fmt.Scanln(&input)
	if strings.HasPrefix(strings.ToUpper(input), "Y") {
		wi.Succ_history = append(wi.Succ_history, date)
		fmt.Printf("your feedback, Yes applied\n")
	} else {
		wi.Fail_history = append(wi.Fail_history, date)
		fmt.Printf("your feedback, No applied\n")
	}
	winfos.Wordinfos[wi.Word] = wi
	fmt.Printf("----------------------------------------------\n")
	fmt.Printf("\n\n\n")
}
Beispiel #10
0
func main() {
	prime_limit := int(math.Sqrt(float64(sieve_limit)))
	l := gen_primes(prime_limit)
	if verbose {
		log.Println("Generated primes below ", prime_limit)
	}

	var rows int
	fmt.Scanln(&rows)
	if verbose {
		log.Println(rows, " rows to come.")
	}

	for i := 1; i <= rows; i++ {
		if verbose {
			log.Println("Processing line ", i)
		}
		var start, stop int
		fmt.Scanln(&start, &stop)
		if verbose {
			log.Println("Generating primes between ", start, " and ", stop)
		}
		r := range_primes(start, stop, l)

		if verbose {
			log.Println("There are ", len(r), " results.")
		}

		for _, prime := range r {
			fmt.Println(prime)
		}
		fmt.Println("")
	}
}
Beispiel #11
0
func main() {
	fmt.Println(runtime.NumGoroutine())
	//runtime.GOMAXPROCS(1)

	//生成随机种子
	rand.Seed(time.Now().Unix())

	begin := make(chan bool)
	go busy(begin)
	fmt.Println(runtime.NumGoroutine())
	<-begin
	fmt.Println("is f*****g!")

	var input string
	fmt.Scanln(&input)

	fmt.Println("done1")

	var name string
	for i := 0; i < 3; i++ {
		name = fmt.Sprintf("go_%02d", i) //生成ID
		//生成随机等待时间,从0-4秒
		go routine(name, time.Duration(rand.Intn(5))*time.Second)
	}

	fmt.Println(runtime.NumGoroutine())
	//让主进程停住,不然主进程退了,goroutine也就退了

	fmt.Scanln(&input)
	fmt.Println("done")
	fmt.Println(runtime.NumGoroutine())
}
Beispiel #12
0
func main() {
	flag.Parse()

	uid := os.Getuid()
	euid := os.Geteuid()

	if uid != 0 || euid != 0 {
		println("grab-box not started with root privileges. Please run grab-box as root.")
		return
	}

	fmt.Println("Welcome to grab-box\n")

	if archiveFilename == nil || *archiveFilename == "" {
		fmt.Println("What is the username/boxname of the box?")

		var slug string
		if _, err := fmt.Scanln(&slug); err != nil {
			log.Fatal(err)
		}
		fmt.Println("")

		metaUrl := fmt.Sprintf("https://app.wercker.com/api/v2/boxes/%v/*", slug)
		response, err := http.Get(metaUrl)
		if err != nil {
			print("Unable to create response for url: %v", err)
		}
		defer response.Body.Close()

		var metaDoc map[string]interface{}
		decoder := json.NewDecoder(response.Body)
		if err := decoder.Decode(&metaDoc); err != nil {
			print("Unable to decode meta data response: %v", err)
		}

		boxurl := metaDoc["tarballUrl"].(string)
		filename, err := downloadBox(boxurl)
		if err != nil {
			log.Fatal(err)
		}

		archiveFilename = &filename
	}

	if boxName == nil || *boxName == "" {
		fmt.Println("What is the name of the box?\n")

		if _, err := fmt.Scanln(boxName); err != nil {
			log.Fatal(err)
		}
	}

	unpackArchive(*archiveFilename, *boxName)

	fmt.Println("\nFixing lxc config...")
	fixConfig(fmt.Sprintf("/var/lib/lxc/%v/config", *boxName), *boxName)

	fmt.Printf("\n\nFinished! You can execute the following command to start the container:\n\n")
	fmt.Printf("\tsudo lxc-start -n '%v'", *boxName)
}
Beispiel #13
0
func main() {
	var pin string
	var nickname string
	var answer string
	fmt.Print("Game pin: ")
	fmt.Scanln(&pin)
	fmt.Print("Nickname: ")
	fmt.Scanln(&nickname)
	fmt.Println("Connecting...")
	conn, err := kahoot.NewConnection(pin)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(1)
	}
	if err := conn.Register(nickname); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	for {
		fmt.Print("Enter to answer question: ")
		fmt.Scanln(&answer)
		fmt.Print("Answer: ")
		var number string
		fmt.Scanln(&number)
		parsed, _ := strconv.Atoi(number)
		if err := conn.SendAnswer(parsed); err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
	}
}
Beispiel #14
0
func main() {
	guesses := 0
	var name string
	var guess int
	rand.Seed(time.Now().Unix())
	randnum := rand.Intn(100)
	randnum += 1
	fmt.Println("Hello! What is your name?")
	fmt.Scanln(&name)
	fmt.Printf("Hello %s\n", name)
	fmt.Println("I'm thinking of a number between 1 and 100 ")
	fmt.Println("What is the number I am thinking of?")

	for {
		fmt.Scanln(&guess)
		guesses++
		if guess < randnum {
			fmt.Println("Your guess was too low, try again.")
		} else if guess > randnum {
			fmt.Println("Your guess was too high, try again.")
		} else {
			fmt.Printf("Congratulations %s! you guessed the number was %d\n", name, randnum)
			break
		}
	}
	fmt.Printf("It took you %d guesses to do this\n", guesses)

}
Beispiel #15
0
func cmdResetDatabase() {
	if flagCmdResetDatabase {

		if len(flagConfirmBackup) == 0 {
			fmt.Print("Have you performed a database backup? (YES/NO): ")
			fmt.Scanln(&flagConfirmBackup)
		}

		if flagConfirmBackup != "YES" {
			fmt.Print("ABORTED: You did not answer YES exactly, in all capitals.")
			flushLogAndExit(1)
		}

		var confirm string
		fmt.Printf("Are you sure you want to delete everything?  ALL data will be permanently deleted? (YES/NO): ")
		fmt.Scanln(&confirm)
		if confirm != "YES" {
			fmt.Print("ABORTED: You did not answer YES exactly, in all capitals.")
			flushLogAndExit(1)
		}

		api.Srv.Store.DropAllTables()
		fmt.Print("SUCCESS: Database reset.")
		flushLogAndExit(0)
	}

}
Beispiel #16
0
func main() {
	var password string
	var user string
	var oourl string
	var choice int
	fmt.Printf("Enter Username:"******"DOMAIN\\" + user
	fmt.Printf("Enter password:"******"Enter OO url (http|https://<fqdn>:<port>/oo):")
	fmt.Scanln(&oourl)
	oourl = oourl + "/rest/latest/"
	fmt.Printf("What do you want to do?\n1-Get Version\n2-Cancel paused flows\n")
	fmt.Scanln(&choice)
	switch choice {
	case 1:
		version := getVersion(user, password, oourl)
		fmt.Printf(version + "\n")
	case 2:
		cancelled := cancelPausedFlows(user, password, oourl)
		fmt.Printf(cancelled + "\n")
	default:
		fmt.Printf("I don't understand")
	}
	bufio.NewReader(os.Stdin).ReadBytes('\n')
}
Beispiel #17
0
func deleteAllUsersCommandF(cmd *cobra.Command, args []string) error {
	initDBCommandContextCobra(cmd)
	if len(args) > 0 {
		return errors.New("Don't enter any agruments.")
	}

	confirmFlag, _ := cmd.Flags().GetBool("confirm")
	if !confirmFlag {
		var confirm string
		CommandPrettyPrintln("Have you performed a database backup? (YES/NO): ")
		fmt.Scanln(&confirm)

		if confirm != "YES" {
			return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
		}
		CommandPrettyPrintln("Are you sure you want to delete the teams specified?  All data will be permanently deleted? (YES/NO): ")
		fmt.Scanln(&confirm)
		if confirm != "YES" {
			return errors.New("ABORTED: You did not answer YES exactly, in all capitals.")
		}
	}

	if err := api.PermanentDeleteAllUsers(); err != nil {
		return err
	} else {
		CommandPrettyPrintln("Sucsessfull. All users deleted.")
	}

	return nil
}
Beispiel #18
0
func main() {
	var pin string
	var nickname string
	fmt.Print("Enter game pin: ")
	fmt.Scanln(&pin)
	fmt.Print("Enter nickname: ")
	fmt.Scanln(&nickname)
	fmt.Println("Connecting...")
	conn, err := kahoot.NewConnection(pin)
	if err != nil {
		fmt.Println("Error:", err)
		os.Exit(1)
	}
	if err := conn.Register(nickname); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	fmt.Println("Awaiting questions...")
	for {
		if conn.WaitQuestion() != nil {
			fmt.Println("Done question loop:", err)
			os.Exit(1)
		}
		fmt.Println("CRASHING!")
		conn.SendCrashAnswer()
	}
}
Beispiel #19
0
func ACL() {
	var driver, host, db, user, pass string

	fmt.Println("Setup ACL database ==============")

	fmt.Print("  driver (mongo/json/csv/mysql) : ")
	fmt.Scanln(&driver)

	fmt.Print("  host (& port) : ")
	fmt.Scanln(&host)

	fmt.Print("  database name : ")
	fmt.Scanln(&db)

	fmt.Print("  username : "******"  password : "******"driver", driver)
	config.Set("host", host)
	config.Set("db", db)
	config.Set("user", user)
	config.Set("pass", pass)

	fmt.Println("ACL Configuration saved!")
	colonycore.SetConfig(colonycore.CONF_DB_ACL, config)
}
Beispiel #20
0
func Config(details *utils.ArtifactoryDetails, interactive, shouldEncPassword bool) {
	var bytePassword []byte
	if interactive {
		if details.Url == "" {
			print("Artifactory Url: ")
			fmt.Scanln(&details.Url)
		}
		if details.User == "" {
			print("User: "******"" {
			print("Password: ")
			var err error
			bytePassword, err = terminal.ReadPassword(int(syscall.Stdin))
			details.Password = string(bytePassword)
			utils.CheckError(err)
		}
	}
	details.Url = utils.AddTrailingSlashIfNeeded(details.Url)
	if shouldEncPassword {
		details = encryptPassword(details)
	}
	writeConfFile(details)
}
func main() {
	var (
		n int
		r float64
	)

	fmt.Scanln(&n, &r)

	ps := make([]point, n)

	for i := 0; i < n; i++ {
		fmt.Scanln(&ps[i].X, &ps[i].Y)
	}

	var l float64

	for i := 0; i < n; i++ {
		p1 := ps[i]
		p2 := ps[(i+1)%n]
		dx := p1.X - p2.X
		dy := p1.Y - p2.Y
		l += math.Sqrt(dx*dx + dy*dy)
	}
	l += 2 * math.Pi * r

	fmt.Printf("%0.2f\n", l)
}
Beispiel #22
0
func topicTruncate(topic string) {
	j := tat.TopicNameJSON{Topic: topic}
	if force {
		out, err := internal.Client().TopicTruncate(j)
		internal.Check(err)
		if internal.Verbose {
			internal.Print(out)
		}
	} else {
		fmt.Print("Are you really sure ? You will delete all messages even if a user has a message in his tasks. Please enter again topic name to confirm: ")
		var confirmTopic string
		fmt.Scanln(&confirmTopic)

		if confirmTopic == topic {
			fmt.Printf("Please enter 'yes' to confirm removing all messages from %s: ", topic)
			var confirmYes string
			fmt.Scanln(&confirmYes)
			if confirmYes == "yes" {
				out, err := internal.Client().TopicTruncate(j)
				internal.Check(err)
				internal.Print(out)
				return
			}
		} else {
			fmt.Printf("Error. You enter %s instead of %s\n", confirmTopic, topic)
		}
		fmt.Println("Nothing done")
	}
}
Beispiel #23
0
//connect to database
func Connect(arg ...string) (*sql.DB, error) {
	//TODO change path
	var path string = "orm.conf"
	if _, err := os.Stat(path); os.IsNotExist(err) {
		path = "/etc/orm.conf"
	}
	set := settings.Settings{File: path}
	database, err := set.Get("database")
	if err != nil {
		fmt.Println(err)
		fmt.Printf("Database server: ")
		fmt.Scanln(&database)
	}
	usr, err := set.Get("user")
	if err != nil {
		fmt.Println(err)
		fmt.Printf("Username: "******"password")
	if err != nil {
		fmt.Println(err)
		fmt.Printf("Password: "******"mysql", makeDSN(database, usr, pwd))
	if err != nil {
		return db, err
	}
	return db, nil
}
Beispiel #24
0
func main() {
	fmt.Print("vk username: "******"vk password: "******"wall",  // scope (required credentials)
	}
	auth, err := GetAuth(&cred)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("auth", auth)
}
Beispiel #25
0
func main() {

	var yrs int
	var popA, popB, growthA, growthB float64

	fmt.Print("Enter the population of town A: ")
	fmt.Scanln(&popA)

	fmt.Print("Enter the growth rate of town A: ")
	fmt.Scanln(&growthA)

	fmt.Print("Enter the population of town B: ")
	fmt.Scanln(&popB)

	fmt.Print("Enter the growth rate of town B: ")
	fmt.Scanln(&growthB)

	if growthA > 1 {
		growthA = growthA / 100
	}

	if growthB > 1 {
		growthB = growthB / 100
	}

	for popB >= popA {
		popB = (popB * growthB) + popB
		popA = (popA * growthA) + popA
		yrs++
	}

	fmt.Printf("The population of town A will be greater than town B after %v years.\n"+
		"The population of town A is: %v\nThe population of town B is: %v\n\n", yrs, int(popA), int(popB))

}
Beispiel #26
0
func main() {
	fmt.Println("Welcome to a Go program called Name2.")
	fmt.Println("What's your name?")
	fmt.Scanln(&name)
	fmt.Println("Interesting name,", name, ",do you know what it means?")
Ask:
	fmt.Scanln(&answer)
	posAnswers := []string{"y", "Y", "yes", "Yes", "YES", "ja"}
	negAnswers := []string{"n", "N", "no", "No", "NO"}
	bsAnswers := []string{"blerg", "kinda", "pissoff", "smartass"}
	if containsString(posAnswers, answer) {
		fmt.Println("Oh really?")
		goto Ask
	} else if containsString(negAnswers, answer) {
		fmt.Println("Well let me look it up!")
		goto Query
	} else if containsString(bsAnswers, answer) {
		fmt.Println("Piss off type y/n, smart ass")
		goto Ask
	} else {
		fmt.Println("Please type yes or no, then press Enter.")
		goto Ask
	}
Query:
	fmt.Println("Enter host:")
	fmt.Scanln(&host)
	fmt.Println("Scanning the internets.")
	ip, _ := net.LookupIP(host)
	fmt.Println(ip)
	goto Query
}
Beispiel #27
0
func handleDownload(n int) {
	if n == 0 {
		// read identifiers from stdin
		// NOTE: not concurrent => slower than it should be
		var level, id int
		read, err := fmt.Scanln(&level, &id)

		for read > 0 && err == nil {
			sudoku := fetchSudoku(level, id)
			writeWebSudoku(sudoku, level, id)
			read, err = fmt.Scanln(&level, &id)
		}
	} else {
		// download random identifiers
		if n < 0 {
			log.Fatal("arg 'n' must be positive.")
		}
		for i := 0; i < n; i++ {
			level := rand.Intn(4) + 1
			id := rand.Intn(2e9)
			sudoku := fetchSudoku(level, id)
			writeWebSudoku(sudoku, level, id)
		}
	}

}
Beispiel #28
0
func cmdPermDeleteAllUsers() {
	if flagCmdPermanentDeleteAllUsers {
		c := getMockContext()

		if len(flagConfirmBackup) == 0 {
			fmt.Print("Have you performed a database backup? (YES/NO): ")
			fmt.Scanln(&flagConfirmBackup)
		}

		if flagConfirmBackup != "YES" {
			fmt.Print("ABORTED: You did not answer YES exactly, in all capitals.")
			flushLogAndExit(1)
		}

		var confirm string
		fmt.Printf("Are you sure you want to delete all the users?  All data will be permanently deleted? (YES/NO): ")
		fmt.Scanln(&confirm)
		if confirm != "YES" {
			fmt.Print("ABORTED: You did not answer YES exactly, in all capitals.")
			flushLogAndExit(1)
		}

		if err := api.PermanentDeleteAllUsers(c); err != nil {
			l4g.Error("%v", err)
			flushLogAndExit(1)
		} else {
			fmt.Print("SUCCESS: All users deleted.")
			flushLogAndExit(0)
		}
	}
}
Beispiel #29
0
func cmdExchange(cmd command) {
	switch cmd.Action {
	case "PRINT", "DISPLAY":
		com.ColorLog("[%s] DEBUG( %s ) --> %s\n", levelToCmdFormat(cmd.Level),
			getTitle(cmd), watchParametersToStr(cmd.Parameters))
	case "BREAK":
		if App.PrintStack {
			com.ColorLog("[%s] BREAK:\n# %s #", levelToCmdFormat(cmd.Level),
				cmd.Parameters["go.stack"])

			if !App.SkipSuspend && App.PrintSource {
				fmt.Print("press ENTER to view source...")
				fmt.Scanln()
			}
		} else {
			com.ColorLog("[%s] BREAK: 'print_stack' disenabled.\n",
				levelToCmdFormat(cmd.Level))
		}

		if App.PrintSource {
			line, _ := strconv.Atoi(cmd.Parameters["go.line"])
			fmt.Println()
			com.ColorLog("[%s] Source( %s ):\n%s", levelToCmdFormat(cmd.Level),
				cmd.Parameters["go.file"], getFileSource(cmd.Parameters["go.file"], line))
		}

		if !App.SkipSuspend {
			fmt.Print("press ENTER to continue...")
			fmt.Scanln()
		}
	}
}
Beispiel #30
0
func main() {
	if len(os.Args) == 1 {
		log.Fatal("Argument required: <lock file>")
	}
	lockFilePath := os.Args[1]

	lockFile, err := os.OpenFile(lockFilePath, os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0600)
	if err != nil {
		log.Fatal(err)
	}
	defer lockFile.Close()

	err = lockapi.TryLockFile(lockFile)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Press ENTER to unlock...")
	fmt.Scanln()

	err = lockapi.UnlockFile(lockFile)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Press ENTER to end...")
	fmt.Scanln()
}