code: func (w *SegmentWAL) openSegmentFile(name string) (*os.File, error) {
  	// We must open all files in read/write mode as we may have to truncate along
  	// the way and any file may become the head.
  	f, err := os.OpenFile(name, os.O_RDWR, 0666)
  	if err != nil {
  		return nil, err
  	}
  	metab := make([]byte, 8)
  
  	// If there is an error, we need close f for platform windows before gc.
  	// Otherwise, file op may fail.
  	hasError := true
  	defer func() {
  		if hasError {
  			f.Close()
  		}
  	}()
  
  	if n, err := f.Read(metab); err != nil {
  		return nil, errors.Wrapf(err, "validate meta %q", f.Name())
  	} else if n != 8 {
  		return nil, errors.Errorf("invalid header size %d in %q", n, f.Name())
  	}
  
  	if m := binary.BigEndian.Uint32(metab[:4]); m != WALMagic {
  		return nil, errors.Errorf("invalid magic header %x in %q", m, f.Name())
  	}
  	if metab[4] != WALFormatDefault {
  		return nil, errors.Errorf("unknown WAL segment format %d in %q", metab[4], f.Name())
  	}
  	hasError = false
  	return f, nil
  }
docs: // openSegmentFile opens the given segment file and consumes and validates header.