如何将自定义结构堆叠起来然后可以访问所有字段?

I have struct Foo with fields Field_1 and Field_2.

  package foo  
  type Custom struct {
      start_row int
      start_column int
      move_row int
      move_column int
    }

    type Foo struct{
      Field_1 [100]Custom
      Field_2 stack.Stack
    }

How can I initialize Foo? Something like this,

new_element := &foo.Foo { [100]foo.Custom{}, stack.Stack {} }

But I need specify stack as container for foo.Custom struct, because I need to access later start_row, start_column like this

Element: = Field_2.Pop()
fmt.Printf("%d 
", Element.start_row)

Here is stack implementation

package stack

type Stack struct {
  top *Element
  size int
}

type Element struct {
  value interface{}
  next *Element
}

// Get length of the stack
func (s *Stack) Length() int {
  return s.size
}

// Push a new element into the stack
func (s *Stack) Push(value interface{}) {
  s.top = &Element{value, s.top}
  s.size += 1
}

// Remove the top element from the stack and return value
// If stack is empty return nil
func (s *Stack) Pop() (value interface{}) {
  if s.size > 0 {
    value, s.top = s.top.value, s.top.next
    s.size -= 1
    return
  }
  return nil
}

Few points:

  1. all fields in Custom are not exported, you can't modify them directly from a different package.

  2. You can't create Foo that way, however since it's an array you can simply just use new_element := &foo.Foo{Field_2: Stack{}}.

With the current implementation of package stack, there is no way to enforce the type of value that gets stored inside struct Element.