本文整理汇总了Golang中fmt.Scanln函数的典型用法代码示例。如果您正苦于以下问题:Golang Scanln函数的具体用法?Golang Scanln怎么用?Golang Scanln使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了Scanln函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: main

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)
}

开发者ID:dsifford,项目名称:CSC_1100,代码行数:35,代码来源:Warm-up02.go

示例2: runLogin

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: ")
    switch {
    case err == nil:
    case err.Error() == "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.")
}

开发者ID:brianz,项目名称:empire,代码行数:60,代码来源:auth.go

示例3: loginAction

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: ")
    _, usernameErr := fmt.Scanln(&username)
    if usernameErr != nil {
        panic(usernameErr)
    }
    password, passwordErr := getpass.GetPass()
    if passwordErr != nil {
        panic(passwordErr)
    }
    fmt.Printf("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")
}

开发者ID:vyctorbh,项目名称:shipyard-cli,代码行数:33,代码来源:actions.go

示例4: main

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)
        }
    }
}

开发者ID:nick2228,项目名称:kahoot-hack,代码行数:33,代码来源:regular.go

示例5: gravatar

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})
}

开发者ID:jennifergarner,项目名称:CS191T,代码行数:26,代码来源:exercises.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng