// Create a new BasicStateBag instance state := &multistep.BasicStateBag{} // Set a value in the state bag state.Put("foo", "bar") // Check whether or not a key exists in the state bag if val, ok := state.GetOk("foo"); ok { fmt.Printf("The value of 'foo' is '%v'\n", val) } else { fmt.Printf("The key 'foo' does not exist in the state bag\n") }
// Create a new BasicStateBag instance state := &multistep.BasicStateBag{} // Attempt to retrieve a value that doesn't exist if val, ok := state.GetOk("bar"); ok { fmt.Printf("The value of 'bar' is '%v'\n", val) } else { fmt.Printf("The key 'bar' does not exist in the state bag\n") }In this example, we create a new BasicStateBag instance and attempt to retrieve a value with the key "bar", which has not been set. The GetOk method will return false, indicating that the key does not exist in the state bag. The else block will be executed, and the message "The key 'bar' does not exist in the state bag" will be printed to the console. Therefore, the package library is "github.com/mitchellh/multistep".