How to set multipart related boundry in golang

AM trying to prepare a multipart/related message which involve JSON data n1n2Request.JsonData and a binary data binaryData to be sent in HTTP request, however, am having issue abou how to set the boundries in the function below. The server is logging “Failed to parse boundary. missing/invalide boundary”. I need help to set the boundaries correctly.


// GetMultipartRelatedN1N2MessageTransferRequest creates a multipart/related body for N1N2MessageTransferRequest
func GetMultipartRelatedN1N2MessageTransferRequest(inputData models.InputData) (*models.N1N2MessageTransferRequest, string, error) {
    // Create a buffer to hold the multipart data
    var buf bytes.Buffer

    // Create a multipart writer with "multipart/related" type
    writer := multipart.NewWriter(&buf)

    // Define the boundary for the multipart/related content
    boundary := writer.Boundary()

    // Create the N1N2MessageTransferRequest object
    n1n2Request := models.N1N2MessageTransferRequest{}

    // Get LMF instanceID (example placeholder, replace with actual logic)
    _, _, nfId, _, _ := config.Cfg.GetServerInfo()

    // Populate the N1N2MessageTransferReqData
    n1n2Request.JsonData = &models.N1N2MessageTransferReqData{
        N1MessageContainer: &models.N1MessageContainer{
            N1MessageClass: models.N1MessageClass_LPP,
            N1MessageContent: &models.RefToBinaryData{
                ContentId: "N1LoInformation",
            },
            NfId: nfId,
        },
        LcsCorrelationId:       inputData.CorrelationID,
        N1n2FailureTxfNotifURI: "",
    }

    // Add the JSON part as the root body part
    jsonPartHeader := textproto.MIMEHeader{}
    jsonPartHeader.Set("Content-Type", "application/json; charset=UTF-8")
    jsonPartHeader.Set("Content-ID", "jsondata")
    jsonPart, err := writer.CreatePart(jsonPartHeader)
    if err != nil {
        return nil, "", fmt.Errorf("error creating JSON part: %v", err)
    }

    jsonBytes, err := json.Marshal(n1n2Request.JsonData)
    if err != nil {
        return nil, "", fmt.Errorf("error marshaling JSON data: %v", err)
    }
    _, err = jsonPart.Write(jsonBytes)
    if err != nil {
        return nil, "", fmt.Errorf("error writing JSON data: %v", err)
    }

    // Create the LPP message
    lppMessage := models.LPPMessage{
        TransactionID: &models.LPPTransactionID{
            TransactionNumber: common.GenerateNumber(),
            Initiator:         int(models.LocationServer),
        },
        SequenceNumber: common.GenerateNumber(),
        LPPMessageBody: &models.LPPMessageBody{
            C1: &models.C1{
                RequestLocationInformation: &models.RequestLocationInformation{
                    CriticalExtensions: &models.CriticalExtensions{
                        C1: &models.CriticalExtensionsC1{
                            RequestLocationInformationR9: &models.RequestLocationInformationR9IEs{
                                CommonIEsRequestLocationInformation: &models.CommonIEsRequestLocationInformation{
                                    LocationInformationType: int(models.LocationEstimateRequired),
                                    PeriodicalReporting: &models.PeriodicalReportingCriteria{
                                        ReportingAmount:   int(models.RA1),
                                        ReportingInterval: int(models.RI32),
                                    },
                                    LocationCoordinateTypes: &models.LocationCoordinateTypes{
                                        EllipsoidPoint: true,
                                    },
                                    VelocityTypes: &models.VelocityTypes{
                                        HorizontalVelocity: true,
                                    },
                                },
                            },
                        },
                    },
                },
            },
        },
        EndTransaction: true,
    }

    // Encode the LPP message using ASN.1 PER encoding
    binaryData, err := aper.Marshal(lppMessage)
    if err != nil {
        logger.Log.Error().Msgf("Error encoding, aper.Marshal error: %v", err)
        return nil, "", err
    }

    // Add the binary part with a Content-ID header
    binaryPartHeader := textproto.MIMEHeader{}
    binaryPartHeader.Set("Content-ID", "n1message")
    binaryPartHeader.Set("Content-Type", "application/vnd.3gpp.5gnas")
    binaryPart, err := writer.CreatePart(binaryPartHeader)
    if err != nil {
        return nil, "", fmt.Errorf("error creating binary part: %v", err)
    }

    // Write the encoded binary data to the binary part
    _, err = binaryPart.Write(binaryData)
    if err != nil {
        return nil, "", fmt.Errorf("error writing binary data: %v", err)
    }

    // Close the multipart writer to finalize the form data
    err = writer.Close()
    if err != nil {
        return nil, "", fmt.Errorf("error closing multipart writer: %v", err)
    }

    // Attach the buffer's content as the binary data of the N1N2MessageTransferRequest
    n1n2Request.BinaryDataN1Message = buf.Bytes()

    contentType := fmt.Sprintf("multipart/related; boundary=%s", boundary)

    return &n1n2Request, contentType, nil
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật