Skip to content

Instantly share code, notes, and snippets.

@ailabs-software
Created January 8, 2015 23:31
Show Gist options
  • Select an option

  • Save ailabs-software/9abb5fd75fdc010e9a92 to your computer and use it in GitHub Desktop.

Select an option

Save ailabs-software/9abb5fd75fdc010e9a92 to your computer and use it in GitHub Desktop.
Why is CellIdentifier set on struct not seen after return? Am I passing my value?
type LayoutCell struct
{
CellIdentifier string;
CellWidth int;
Widget_name string;
Widget_state *interface{};
}
type LayoutRow struct // CellGroup
{
Cells *[]LayoutCell;
}
type Document []LayoutRow;
func LoadDocument(filename string) (*Document, error) {
// Read file from disc
doc_bytes, err := ioutil.ReadFile(filename);
if (err != nil) { return nil, err; }
var document = make(Document, 0);
var parse_err = json.Unmarshal(doc_bytes, &document);
if (parse_err != nil) { return nil, parse_err; }
// Set CellIdentifiers
for _, layoutRow := range document { // Rows loop
// Loop on cells in range
for i, cell := range *layoutRow.Cells { // Cells loop
cell.CellIdentifier = "cell-" + strconv.Itoa(i);
log.Print(cell.CellIdentifier); // Set cell identifier here! Why is this not seen on document?
}
}
return &document, nil;
}
func main() {
var document = LoadDocument("mytest.json");
// Why is cell.CellIdentifier empty here?
for _, layoutRow := range document { // Rows loop
// Loop on cells in range
for i, cell := range *layoutRow.Cells { // Cells loop
log.Print(cell.CellIdentifier); // Outputs empty string!
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment