使用Go處理SDK返回的巢狀層級資料並將所需欄位存入資料庫(一)
阿新 • • 發佈:2020-10-29
前言
新專案使用Go搭建服務,其中涉及到很多業務資料的構建以及處理的邏輯,筆者也是剛剛開始寫Go程式碼,剛剛開始的時候必然會踩很多坑,這裡就記錄一下筆者在處理SDK返回的層級資料時遇到的問題以及後續的優化處理。
業務需求描述
從某平臺獲取到的HTTP原始資料格式如下所示:
{ "request_status": "SUCCESS", "request_id": "xxxxxx", "paging": {}, "adaccounts": [ { "sub_request_status": "SUCCESS",HTTP原始資料結構"adaccount": { "id": "06585df8-81a5-4010-b3b5-8d718d0c4487", "updated_at": "2020-10-28T22:09:24.409Z", "created_at": "2020-08-21T11:00:28.455Z", "name": "Fashowtime_05_Muyou_EC_SINO_B", "type": "PARTNER", "status": "ACTIVE", "organization_id": "16412453-e008-4353-a8da-881ed5170e9c", "funding_source_ids": [ "fc7cb056-453a-4b3f-8294-bcaffc5ee1fb" ], "currency": "USD", "timezone": "Asia/Shanghai", } }, {"sub_request_status": "SUCCESS", "adaccount": { "id": "0f9542e9-56bd-4fae-a6a9-5b9bd48004a6", "updated_at": "2020-10-28T21:50:52.923Z", "created_at": "2020-08-21T10:59:07.409Z", "name": "Fashowtime_03_Muyou_EC_SINO_B", "type": "PARTNER", "status": "ACTIVE", "organization_id": "16412453-e008-4353-a8da-881ed5170e9c", "funding_source_ids": [ "8b94cfc2-5932-49c8-8865-e4f33a2bad0c", "fc7cb056-453a-4b3f-8294-bcaffc5ee1fb" ], "currency": "USD", "timezone": "Asia/Shanghai", } }, { "sub_request_status": "SUCCESS", "adaccount": { "id": "47ea8129-d1e0-4fa3-8df8-e9cab4a64e7b", "updated_at": "2020-10-28T21:57:05.953Z", "created_at": "2020-08-21T10:57:34.614Z", "name": "Fashowtime_01_Muyou_EC_SINO_B", "type": "PARTNER", "status": "ACTIVE", "organization_id": "16412453-e008-4353-a8da-881ed5170e9c", "funding_source_ids": [ "fc7cb056-453a-4b3f-8294-bcaffc5ee1fb" ], "currency": "USD", "timezone": "Asia/Shanghai", } }, { "sub_request_status": "SUCCESS", "adaccount": { "id": "489ece86-ed2a-4b2f-a697-b470c5f12652", "updated_at": "2020-10-28T21:56:38.374Z", "created_at": "2020-08-21T10:58:35.585Z", "name": "Fashowtime_02_Muyou_EC_SINO_B", "type": "PARTNER", "status": "ACTIVE", "organization_id": "16412453-e008-4353-a8da-881ed5170e9c", "funding_source_ids": [ "fc7cb056-453a-4b3f-8294-bcaffc5ee1fb" ], "currency": "USD", "timezone": "Asia/Shanghai", } }, { "sub_request_status": "SUCCESS", "adaccount": { "id": "fa52ec27-fe6c-489d-a606-6a6e19c66690", "updated_at": "2020-10-28T21:56:34.531Z", "created_at": "2020-08-21T10:59:53.850Z", "name": "Fashowtime_04_Muyou_EC_SINO_B", "type": "PARTNER", "status": "ACTIVE", "organization_id": "16412453-e008-4353-a8da-881ed5170e9c", "funding_source_ids": [ "fc7cb056-453a-4b3f-8294-bcaffc5ee1fb" ], "currency": "USD", "timezone": "Asia/Shanghai", } } ] }
123
123
123