Skip to content

securestore ​

go
import "github.com/tangoui/tango/sys/securestore"

本页由 site/tools/apigen 从源码注释生成(按 darwin 构建标签选文件),请勿手改。

Package securestore keeps small secrets (tokens, keys, passwords) in the platform's protected storage: the Keychain on iOS and macOS (generic passwords of the app, this device only, available after first unlock); on Android values encrypted with an AES key held in the Android Keystore, stored in the app's private SharedPreferences; the Credential Manager on Windows (generic credentials of the user, not roaming); and the Secret Service on Linux (GNOME Keyring, KWallet) through libsecret. Linux returns ErrUnsupported when libsecret-1 is not installed or no Secret Service is running (headless sessions).

securestore.SetString(a, "session", tok)
tok, err := securestore.GetString(a, "session") // ErrNotFound if never set

Items survive app updates; on iOS Keychain items may survive uninstalling the app. Values are meant to be small (kilobytes). Calls are safe from any goroutine and do not need the main thread. They return ErrUnsupported where the backend has no secure store.

变量 ​

go
var (
	ErrUnsupported = platform.ErrUnsupported
	ErrNotFound    = platform.ErrNotFound
)

函数 ​

func Delete ​

go
func Delete(a *tango.App, key string) error

Delete removes key; deleting a missing key is not an error.

func Get ​

go
func Get(a *tango.App, key string) ([]byte, error)

Get returns the value stored under key, or ErrNotFound.

func GetString ​

go
func GetString(a *tango.App, key string) (string, error)

GetString is Get for text.

func Set ​

go
func Set(a *tango.App, key string, value []byte) error

Set stores value under key, replacing any previous value.

func SetString ​

go
func SetString(a *tango.App, key, value string) error

SetString is Set for text.

以 MIT 许可发布