由于@Volker并未发布他的评论作为答案,因此我会为了完整性而这样做。
所以我已经走在正确的道路上,但是在初始化它时却无法取消引用我的结构的指针接收器:
// Implements the Unmarshaler interface of the yaml pkg.func (e *EpnSeq) UnmarshalYAML(unmarshal func(interface{}) error) error { yamlEpnSequence := make([]uint16, 0) err := unmarshal(&yamlEpnSequence) if err != nil { return err } // make sure to dereference before assignment, // otherwise only the local variable will be overwritten // and not the value the pointer actually points to *e = make(EpnSeq, len(yamlEpnSequence)) for priority, epn := range yamlEpnSequence { e[epn] = uint16(priority) // no crash anymore } return nil}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)