str

package
v0.1.43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2022 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type String

Example
package main

import (
	"fmt"

	globalSym "bitbucket.org/taubyte/go-sdk-symbols/globals"
	"bitbucket.org/taubyte/go-sdk/globals/scope"
	"bitbucket.org/taubyte/go-sdk/globals/str"
)

func main() {
	// Mocking the calls to the vm for usage in tests and playground
	globalSym.MockData{
		Data: map[string][]uint8{
			"/string/name":             []byte("Hello, world!"),
			"/application/string/name": []byte("Hello, world! (scoped)"),
		},
	}.Mock()

	{
		name, err := str.GetOrCreate("name")
		if err != nil {
			return
		}

		fmt.Println("Global scope:", name.Value())

		err = name.Set("Hello, Mars!")
		if err != nil {
			return
		}

		name, err = str.Get("name")
		if err != nil {
			return
		}

		fmt.Println("Global scope set:", name.Value())
	}

	{
		name, err := str.Get("name", scope.Application)
		if err != nil {
			return
		}

		fmt.Println("Application scope:", name.Value())
	}

}
Output:

Global scope: Hello, world!
Global scope set: Hello, Mars!
Application scope: Hello, world! (scoped)

func Get

func Get(name string, scope ...internal.Option) (String, error)

func GetOrCreate

func GetOrCreate(name string, scope ...internal.Option) (String, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL