Created
January 8, 2015 23:31
-
-
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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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