Есть ли способ восстановить учетную запись, если я потерял 2FA ключ восстановления

Вам нужно

var test = "This is a test"

:= работает только в функциях, а нижний регистр «t» таков, что он виден только в пакете (непортированный).

Более подробное объяснение

test1.go

package main

import "fmt"

// the variable takes the type of the initializer
var test = "testing"

// you could do: 
// var test string = "testing"
// but that is not idiomatic GO

// Both types of instantiation shown above are supported in
// and outside of functions and function receivers

func main() {
    // Inside a function you can declare the type and then assign the value
    var newVal string
    newVal = "Something Else"

    // just infer the type
    str := "Type can be inferred"

    // To change the value of package level variables
    fmt.Println(test)
    changeTest(newVal)
    fmt.Println(test)
    changeTest(str)
    fmt.Println(test)
}

test2.go

package main

func changeTest(newTest string) {
    test = newTest
}

output

testing
Something Else
Type can be inferred

Альтернативно, для более сложных инициализаций пакетов или для настройки того, что требуется для пакета, пакет GO предоставляет функцию init.

package main

import (
    "fmt"
)

var test map[string]int

func init() {
    test = make(map[string]int)
    test["foo"] = 0
    test["bar"] = 1
}

func main() {
    fmt.Println(test) // prints map[foo:0 bar:1]
}

Init будет вызываться до запуска main.

0
задан Borhane E. Guemidi 16 January 2019 в 09:57
поделиться

0 ответов

Другие вопросы по тегам:

Похожие вопросы: