本文整理匯總了Golang中fmt.Println函數的典型用法代碼示例。如果您正苦於以下問題:Golang Println函數的具體用法?Golang Println怎麽用?Golang Println使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Println函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ExamplePayToAddrScript
// This example demonstrates creating a script which pays to a bitcoin address.
// It also prints the created script hex and uses the DisasmString function to
// display the disassembled script.
func ExamplePayToAddrScript() {
// Parse the address to send the coins to into a btcutil.Address
// which is useful to ensure the accuracy of the address and determine
// the address type. It is also required for the upcoming call to
// PayToAddrScript.
addressStr := "12gpXQVcCL2qhTNQgyLVdCFG2Qs2px98nV"
address, err := btcutil.DecodeAddress(addressStr, &btcnet.MainNetParams)
if err != nil {
fmt.Println(err)
return
}
// Create a public key script that pays to the address.
script, err := btcscript.PayToAddrScript(address)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("Script Hex: %x\n", script)
disasm, err := btcscript.DisasmString(script)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Script Disassembly:", disasm)
// Output:
// Script Hex: 76a914128004ff2fcaf13b2b91eb654b1dc2b674f7ec6188ac
// Script Disassembly: OP_DUP OP_HASH160 128004ff2fcaf13b2b91eb654b1dc2b674f7ec61 OP_EQUALVERIFY OP_CHECKSIG
}
示例2: TestSecureSecretoxKey
func TestSecureSecretoxKey(t *testing.T) {
key1, ok := secretbox.GenerateKey()
if !ok {
fmt.Println("pwkey: failed to generate test key")
t.FailNow()
}
skey, ok := SecureSecretboxKey(testPass, key1)
if !ok {
fmt.Println("pwkey: failed to secure secretbox key")
t.FailNow()
}
key, ok := RecoverSecretboxKey(testPass, skey)
if !ok {
fmt.Println("pwkey: failed to recover box private key")
t.FailNow()
}
if !bytes.Equal(key[:], key1[:]) {
fmt.Println("pwkey: recovered key doesn't match original")
t.FailNow()
}
if _, ok = RecoverBoxKey([]byte("Password"), skey); ok {
fmt.Println("pwkey: recover should fail with bad password")
t.FailNow()
}
}
示例3: TestVersion
func TestVersion(t *testing.T) {
v := new(Version)
v.Version = uint16(1)
v.Timestamp = time.Unix(0, 0)
v.IpAddress = net.ParseIP("1.2.3.4")
v.Port = uint16(4444)
v.UserAgent = "Hello World!"
verBytes := v.GetBytes()
if len(verBytes) != verLen+12 {
fmt.Println("Incorrect Byte Length: ", verBytes)
t.Fail()
}
v2 := new(Version)
err := v2.FromBytes(verBytes)
if err != nil {
fmt.Println("Error Decoding: ", err)
t.FailNow()
}
if v2.Version != 1 || v2.Timestamp != time.Unix(0, 0) || v2.IpAddress.String() != "1.2.3.4" || v2.Port != 4444 || v2.UserAgent != "Hello World!" {
fmt.Println("Incorrect decoded version: ", v2)
t.Fail()
}
}
示例4: getUberCost
func getUberCost(start locationStruct, end locationStruct) (int, int, float64, string) {
uberURL := strings.Replace(uberRequestURL, startLatitude, strconv.FormatFloat(start.Coordinate.Lat, 'f', -1, 64), -1)
uberURL = strings.Replace(uberURL, startLongitude, strconv.FormatFloat(start.Coordinate.Lng, 'f', -1, 64), -1)
uberURL = strings.Replace(uberURL, endLatitude, strconv.FormatFloat(end.Coordinate.Lat, 'f', -1, 64), -1)
uberURL = strings.Replace(uberURL, endLongitude, strconv.FormatFloat(end.Coordinate.Lng, 'f', -1, 64), -1)
res, err := http.Get(uberURL)
if err != nil {
//w.Write([]byte(`{ "error": "Unable to parse data from Google. Error at res, err := http.Get(url) -- line 75"}`))
fmt.Println("Unable to parse data from Google. Error at res, err := http.Get(url) -- line 75")
panic(err.Error())
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
//w.Write([]byte(`{ "error": "Unable to parse data from Google. body, err := ioutil.ReadAll(res.Body) -- line 84"}`))
fmt.Println("Unable to parse data from Google. Error at res, err := http.Get(url) -- line 84")
panic(err.Error())
}
var uberResult UberResults
_ = json.Unmarshal(body, &uberResult)
return uberResult.Prices[0].LowEstimate, uberResult.Prices[0].Duration, uberResult.Prices[0].Distance, uberResult.Prices[0].ProductID
}
示例5: ExampleLambda_CreateFunction
func ExampleLambda_CreateFunction() {
svc := lambda.New(session.New())
params := &lambda.CreateFunctionInput{
Code: &lambda.FunctionCode{ // Required
S3Bucket: aws.String("S3Bucket"),
S3Key: aws.String("S3Key"),
S3ObjectVersion: aws.String("S3ObjectVersion"),
ZipFile: []byte("PAYLOAD"),
},
FunctionName: aws.String("FunctionName"), // Required
Handler: aws.String("Handler"), // Required
Role: aws.String("RoleArn"), // Required
Runtime: aws.String("Runtime"), // Required
Description: aws.String("Description"),
MemorySize: aws.Int64(1),
Publish: aws.Bool(true),
Timeout: aws.Int64(1),
}
resp, err := svc.CreateFunction(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例6: main
func main() {
file, err := os.Create("samp.txt")
if err != nil {
log.Fatal(err)
}
file.WriteString("This is some random text")
file.Close()
stream, err := ioutil.ReadFile("samp.txt")
if err != nil {
log.Fatal(err)
}
readString := string(stream)
fmt.Println(readString)
randInt := 5
// randFloat := 10.5
randString := "100"
// randString2 := "250.5"
fmt.Println(float64(randInt))
newInt, _ := strconv.ParseInt(randString, 0, 64)
newFloat, _ := strconv.ParseFloat(randString, 64)
fmt.Println(newInt, newFloat)
}
示例7: main
func main() {
consumer := consumer.New(dopplerAddress, &tls.Config{InsecureSkipVerify: true}, nil)
consumer.SetDebugPrinter(ConsoleDebugPrinter{})
messages, err := consumer.RecentLogs(appGuid, authToken)
if err != nil {
fmt.Printf("===== Error getting recent messages: %v\n", err)
} else {
fmt.Println("===== Recent logs")
for _, msg := range messages {
fmt.Println(msg)
}
}
fmt.Println("===== Streaming metrics")
msgChan, errorChan := consumer.Stream(appGuid, authToken)
go func() {
for err := range errorChan {
fmt.Fprintf(os.Stderr, "%v\n", err.Error())
}
}()
for msg := range msgChan {
fmt.Printf("%v \n", msg)
}
}
示例8: main
func main() {
var opts struct {
ClientID string `long:"client_id" required:"true"`
ClientSecret string `long:"client_secret" required:"true"`
}
_, err := flags.Parse(&opts)
if err != nil {
log.Fatalln(err)
return
}
config := &oauth2.Config{
ClientID: opts.ClientID,
ClientSecret: opts.ClientSecret,
RedirectURL: "urn:ietf:wg:oauth:2.0:oob",
Scopes: []string{"https://www.googleapis.com/auth/gmail.send"},
Endpoint: oauth2.Endpoint{
AuthURL: "https://accounts.google.com/o/oauth2/auth",
TokenURL: "https://accounts.google.com/o/oauth2/token",
},
}
var code string
url := config.AuthCodeURL("")
fmt.Println("ブラウザで以下のURLにアクセスし、認証してCodeを取得してください。")
fmt.Println(url)
fmt.Println("取得したCodeを入力してください")
fmt.Scanf("%s\n", &code)
token, err := config.Exchange(context.Background(), code)
if err != nil {
log.Fatalln("Exchange: ", err)
}
fmt.Println("RefreshToken: ", token.RefreshToken)
}
示例9: initDir
func initDir(args *argContainer) {
err := checkDirEmpty(args.cipherdir)
if err != nil {
fmt.Printf("Invalid cipherdir: %v\n", err)
os.Exit(ERREXIT_INIT)
}
// Create gocryptfs.conf
cryptfs.Info.Printf("Choose a password for protecting your files.\n")
password := readPasswordTwice(args.extpass)
err = cryptfs.CreateConfFile(args.config, password, args.plaintextnames, args.scryptn)
if err != nil {
fmt.Println(err)
os.Exit(ERREXIT_INIT)
}
if args.diriv && !args.plaintextnames {
// Create gocryptfs.diriv in the root dir
err = cryptfs.WriteDirIV(args.cipherdir)
if err != nil {
fmt.Println(err)
os.Exit(ERREXIT_INIT)
}
}
cryptfs.Info.Printf(colorGreen + "The filesystem has been created successfully.\n" + colorReset)
cryptfs.Info.Printf(colorGrey+"You can now mount it using: %s %s MOUNTPOINT\n"+colorReset,
PROGRAM_NAME, args.cipherdir)
os.Exit(0)
}
示例10: txnCommandFunc
// txnCommandFunc executes the "txn" command.
func txnCommandFunc(c *cli.Context) {
if len(c.Args()) != 0 {
panic("unexpected args")
}
reader := bufio.NewReader(os.Stdin)
next := compareState
txn := &pb.TxnRequest{}
for next != nil {
next = next(txn, reader)
}
conn, err := grpc.Dial("127.0.0.1:12379")
if err != nil {
panic(err)
}
etcd := pb.NewEtcdClient(conn)
resp, err := etcd.Txn(context.Background(), txn)
if err != nil {
fmt.Println(err)
}
if resp.Succeeded {
fmt.Println("executed success request list")
} else {
fmt.Println("executed failure request list")
}
}
示例11: TestNew
func TestNew(t *testing.T) {
config.SetHome(filepath.Join("..", "..", "cmd", "roy", "data"))
mi, err := newMIMEInfo()
if err != nil {
t.Error(err)
}
tpmap := make(map[string]struct{})
for _, v := range mi {
//fmt.Println(v)
//if len(v.Magic) > 1 {
// fmt.Printf("Multiple magics (%d): %s\n", len(v.Magic), v.MIME)
//}
for _, c := range v.Magic {
for _, d := range c.Matches {
tpmap[d.Typ] = struct{}{}
if len(d.Mask) > 0 {
if d.Typ == "string" {
fmt.Println("MAGIC: " + d.Value)
} else {
fmt.Println("Type: " + d.Typ)
}
fmt.Println("MASK: " + d.Mask)
}
}
}
}
/*
for k, _ := range tpmap {
fmt.Println(k)
}
*/
if len(mi) != 1495 {
t.Errorf("expecting %d MIMEInfos, got %d", 1495, len(mi))
}
}
示例12: main
func main() {
{
errChan := make(chan error)
go func() {
errChan <- nil
}()
select {
case v := <-errChan:
fmt.Println("even if nil, it still receives", v)
case <-time.After(time.Second):
fmt.Println("time-out!")
}
// even if nil, it still receives <nil>
}
{
errChan := make(chan error)
errChan = nil
go func() {
errChan <- nil
}()
select {
case v := <-errChan:
fmt.Println("even if nil, it still receives", v)
case <-time.After(time.Second):
fmt.Println("time-out!")
}
// time-out!
}
}
示例13: main
func main() {
if Same(tree.New(1), tree.New(1)) && !Same(tree.New(1), tree.New(2)) {
fmt.Println("PASSED")
} else {
fmt.Println("FAILED")
}
}
示例14: ExampleExtractPkScriptAddrs
// This example demonstrates extracting information from a standard public key
// script.
func ExampleExtractPkScriptAddrs() {
// Start with a standard pay-to-pubkey-hash script.
scriptHex := "76a914128004ff2fcaf13b2b91eb654b1dc2b674f7ec6188ac"
script, err := hex.DecodeString(scriptHex)
if err != nil {
fmt.Println(err)
return
}
// Extract and print details from the script.
scriptClass, addresses, reqSigs, err := btcscript.ExtractPkScriptAddrs(
script, &btcnet.MainNetParams)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Script Class:", scriptClass)
fmt.Println("Addresses:", addresses)
fmt.Println("Required Signatures:", reqSigs)
// Output:
// Script Class: pubkeyhash
// Addresses: [12gpXQVcCL2qhTNQgyLVdCFG2Qs2px98nV]
// Required Signatures: 1
}
示例15: NewWatcher
func NewWatcher(paths []string) {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
go func() {
for {
select {
case e := <-watcher.Event:
fmt.Println(e)
go Autobuild()
case err := <-watcher.Error:
log.Fatal("error:", err)
}
}
}()
for _, path := range paths {
fmt.Println(path)
err = watcher.Watch(path)
if err != nil {
log.Fatal(err)
}
}
}