gitee.com/larksuite/oapi-sdk-go/v3@v3.0.3/service/search/v2/api.go (about) 1 // Package search code generated by oapi sdk gen 2 /* 3 * MIT License 4 * 5 * Copyright (c) 2022 Lark Technologies Pte. Ltd. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 * 9 * The above copyright notice and this permission notice, shall be included in all copies or substantial portions of the Software. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 */ 13 14 package larksearch 15 16 import ( 17 "context" 18 "net/http" 19 20 "gitee.com/larksuite/oapi-sdk-go/v3/core" 21 ) 22 23 func NewService(config *larkcore.Config) *SearchService { 24 s := &SearchService{config: config} 25 s.DataSource = &dataSource{service: s} 26 s.DataSourceItem = &dataSourceItem{service: s} 27 s.Schema = &schema{service: s} 28 return s 29 } 30 31 type SearchService struct { 32 config *larkcore.Config 33 DataSource *dataSource // 数据源 34 DataSourceItem *dataSourceItem // 数据项 35 Schema *schema // 数据范式 36 } 37 38 type dataSource struct { 39 service *SearchService 40 } 41 type dataSourceItem struct { 42 service *SearchService 43 } 44 type schema struct { 45 service *SearchService 46 } 47 48 // 创建数据源 49 // 50 // - 创建一个数据源 51 // 52 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/search-v2/data_source/create 53 // 54 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/searchv2/create_dataSource.go 55 func (d *dataSource) Create(ctx context.Context, req *CreateDataSourceReq, options ...larkcore.RequestOptionFunc) (*CreateDataSourceResp, error) { 56 // 发起请求 57 apiReq := req.apiReq 58 apiReq.ApiPath = "/open-apis/search/v2/data_sources" 59 apiReq.HttpMethod = http.MethodPost 60 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant} 61 apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...) 62 if err != nil { 63 return nil, err 64 } 65 // 反序列响应结果 66 resp := &CreateDataSourceResp{ApiResp: apiResp} 67 err = apiResp.JSONUnmarshalBody(resp) 68 if err != nil { 69 return nil, err 70 } 71 return resp, err 72 } 73 74 // 删除数据源 75 // 76 // - 删除一个已存在的数据源 77 // 78 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/search-v2/data_source/delete 79 // 80 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/searchv2/delete_dataSource.go 81 func (d *dataSource) Delete(ctx context.Context, req *DeleteDataSourceReq, options ...larkcore.RequestOptionFunc) (*DeleteDataSourceResp, error) { 82 // 发起请求 83 apiReq := req.apiReq 84 apiReq.ApiPath = "/open-apis/search/v2/data_sources/:data_source_id" 85 apiReq.HttpMethod = http.MethodDelete 86 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant} 87 apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...) 88 if err != nil { 89 return nil, err 90 } 91 // 反序列响应结果 92 resp := &DeleteDataSourceResp{ApiResp: apiResp} 93 err = apiResp.JSONUnmarshalBody(resp) 94 if err != nil { 95 return nil, err 96 } 97 return resp, err 98 } 99 100 // 获取数据源 101 // 102 // - 获取已经创建的数据源 103 // 104 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/search-v2/data_source/get 105 // 106 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/searchv2/get_dataSource.go 107 func (d *dataSource) Get(ctx context.Context, req *GetDataSourceReq, options ...larkcore.RequestOptionFunc) (*GetDataSourceResp, error) { 108 // 发起请求 109 apiReq := req.apiReq 110 apiReq.ApiPath = "/open-apis/search/v2/data_sources/:data_source_id" 111 apiReq.HttpMethod = http.MethodGet 112 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant} 113 apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...) 114 if err != nil { 115 return nil, err 116 } 117 // 反序列响应结果 118 resp := &GetDataSourceResp{ApiResp: apiResp} 119 err = apiResp.JSONUnmarshalBody(resp) 120 if err != nil { 121 return nil, err 122 } 123 return resp, err 124 } 125 126 // 批量获取数据源 127 // 128 // - 批量获取创建的数据源信息 129 // 130 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/search-v2/data_source/list 131 // 132 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/searchv2/list_dataSource.go 133 func (d *dataSource) List(ctx context.Context, req *ListDataSourceReq, options ...larkcore.RequestOptionFunc) (*ListDataSourceResp, error) { 134 // 发起请求 135 apiReq := req.apiReq 136 apiReq.ApiPath = "/open-apis/search/v2/data_sources" 137 apiReq.HttpMethod = http.MethodGet 138 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant} 139 apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...) 140 if err != nil { 141 return nil, err 142 } 143 // 反序列响应结果 144 resp := &ListDataSourceResp{ApiResp: apiResp} 145 err = apiResp.JSONUnmarshalBody(resp) 146 if err != nil { 147 return nil, err 148 } 149 return resp, err 150 } 151 func (d *dataSource) ListByIterator(ctx context.Context, req *ListDataSourceReq, options ...larkcore.RequestOptionFunc) (*ListDataSourceIterator, error) { 152 return &ListDataSourceIterator{ 153 ctx: ctx, 154 req: req, 155 listFunc: d.List, 156 options: options, 157 limit: req.Limit}, nil 158 } 159 160 // 修改数据源 161 // 162 // - 更新一个已经存在的数据源 163 // 164 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/search-v2/data_source/patch 165 // 166 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/searchv2/patch_dataSource.go 167 func (d *dataSource) Patch(ctx context.Context, req *PatchDataSourceReq, options ...larkcore.RequestOptionFunc) (*PatchDataSourceResp, error) { 168 // 发起请求 169 apiReq := req.apiReq 170 apiReq.ApiPath = "/open-apis/search/v2/data_sources/:data_source_id" 171 apiReq.HttpMethod = http.MethodPatch 172 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant} 173 apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...) 174 if err != nil { 175 return nil, err 176 } 177 // 反序列响应结果 178 resp := &PatchDataSourceResp{ApiResp: apiResp} 179 err = apiResp.JSONUnmarshalBody(resp) 180 if err != nil { 181 return nil, err 182 } 183 return resp, err 184 } 185 186 // 索引数据项 187 // 188 // - 索引一条数据记录 189 // 190 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/search-v2/data_source-item/create 191 // 192 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/searchv2/create_dataSourceItem.go 193 func (d *dataSourceItem) Create(ctx context.Context, req *CreateDataSourceItemReq, options ...larkcore.RequestOptionFunc) (*CreateDataSourceItemResp, error) { 194 // 发起请求 195 apiReq := req.apiReq 196 apiReq.ApiPath = "/open-apis/search/v2/data_sources/:data_source_id/items" 197 apiReq.HttpMethod = http.MethodPost 198 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant} 199 apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...) 200 if err != nil { 201 return nil, err 202 } 203 // 反序列响应结果 204 resp := &CreateDataSourceItemResp{ApiResp: apiResp} 205 err = apiResp.JSONUnmarshalBody(resp) 206 if err != nil { 207 return nil, err 208 } 209 return resp, err 210 } 211 212 // 删除数据项 213 // 214 // - 删除数据项 215 // 216 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/search-v2/data_source-item/delete 217 // 218 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/searchv2/delete_dataSourceItem.go 219 func (d *dataSourceItem) Delete(ctx context.Context, req *DeleteDataSourceItemReq, options ...larkcore.RequestOptionFunc) (*DeleteDataSourceItemResp, error) { 220 // 发起请求 221 apiReq := req.apiReq 222 apiReq.ApiPath = "/open-apis/search/v2/data_sources/:data_source_id/items/:item_id" 223 apiReq.HttpMethod = http.MethodDelete 224 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant} 225 apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...) 226 if err != nil { 227 return nil, err 228 } 229 // 反序列响应结果 230 resp := &DeleteDataSourceItemResp{ApiResp: apiResp} 231 err = apiResp.JSONUnmarshalBody(resp) 232 if err != nil { 233 return nil, err 234 } 235 return resp, err 236 } 237 238 // 获取数据项 239 // 240 // - 获取单个数据记录 241 // 242 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/search-v2/data_source-item/get 243 // 244 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/searchv2/get_dataSourceItem.go 245 func (d *dataSourceItem) Get(ctx context.Context, req *GetDataSourceItemReq, options ...larkcore.RequestOptionFunc) (*GetDataSourceItemResp, error) { 246 // 发起请求 247 apiReq := req.apiReq 248 apiReq.ApiPath = "/open-apis/search/v2/data_sources/:data_source_id/items/:item_id" 249 apiReq.HttpMethod = http.MethodGet 250 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant} 251 apiResp, err := larkcore.Request(ctx, apiReq, d.service.config, options...) 252 if err != nil { 253 return nil, err 254 } 255 // 反序列响应结果 256 resp := &GetDataSourceItemResp{ApiResp: apiResp} 257 err = apiResp.JSONUnmarshalBody(resp) 258 if err != nil { 259 return nil, err 260 } 261 return resp, err 262 } 263 264 // 创建数据范式 265 // 266 // - 创建一个数据源 267 // 268 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/search-v2/schema/create 269 // 270 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/searchv2/create_schema.go 271 func (s *schema) Create(ctx context.Context, req *CreateSchemaReq, options ...larkcore.RequestOptionFunc) (*CreateSchemaResp, error) { 272 // 发起请求 273 apiReq := req.apiReq 274 apiReq.ApiPath = "/open-apis/search/v2/schemas" 275 apiReq.HttpMethod = http.MethodPost 276 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant} 277 apiResp, err := larkcore.Request(ctx, apiReq, s.service.config, options...) 278 if err != nil { 279 return nil, err 280 } 281 // 反序列响应结果 282 resp := &CreateSchemaResp{ApiResp: apiResp} 283 err = apiResp.JSONUnmarshalBody(resp) 284 if err != nil { 285 return nil, err 286 } 287 return resp, err 288 } 289 290 // 删除数据范式 291 // 292 // - 删除已存在的数据范式 293 // 294 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/search-v2/schema/delete 295 // 296 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/searchv2/delete_schema.go 297 func (s *schema) Delete(ctx context.Context, req *DeleteSchemaReq, options ...larkcore.RequestOptionFunc) (*DeleteSchemaResp, error) { 298 // 发起请求 299 apiReq := req.apiReq 300 apiReq.ApiPath = "/open-apis/search/v2/schemas/:schema_id" 301 apiReq.HttpMethod = http.MethodDelete 302 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant} 303 apiResp, err := larkcore.Request(ctx, apiReq, s.service.config, options...) 304 if err != nil { 305 return nil, err 306 } 307 // 反序列响应结果 308 resp := &DeleteSchemaResp{ApiResp: apiResp} 309 err = apiResp.JSONUnmarshalBody(resp) 310 if err != nil { 311 return nil, err 312 } 313 return resp, err 314 } 315 316 // 获取数据范式 317 // 318 // - 获取单个数据范式 319 // 320 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/search-v2/schema/get 321 // 322 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/searchv2/get_schema.go 323 func (s *schema) Get(ctx context.Context, req *GetSchemaReq, options ...larkcore.RequestOptionFunc) (*GetSchemaResp, error) { 324 // 发起请求 325 apiReq := req.apiReq 326 apiReq.ApiPath = "/open-apis/search/v2/schemas/:schema_id" 327 apiReq.HttpMethod = http.MethodGet 328 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant} 329 apiResp, err := larkcore.Request(ctx, apiReq, s.service.config, options...) 330 if err != nil { 331 return nil, err 332 } 333 // 反序列响应结果 334 resp := &GetSchemaResp{ApiResp: apiResp} 335 err = apiResp.JSONUnmarshalBody(resp) 336 if err != nil { 337 return nil, err 338 } 339 return resp, err 340 } 341 342 // 修改数据范式 343 // 344 // - 修改数据范式 345 // 346 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/search-v2/schema/patch 347 // 348 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/searchv2/patch_schema.go 349 func (s *schema) Patch(ctx context.Context, req *PatchSchemaReq, options ...larkcore.RequestOptionFunc) (*PatchSchemaResp, error) { 350 // 发起请求 351 apiReq := req.apiReq 352 apiReq.ApiPath = "/open-apis/search/v2/schemas/:schema_id" 353 apiReq.HttpMethod = http.MethodPatch 354 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant} 355 apiResp, err := larkcore.Request(ctx, apiReq, s.service.config, options...) 356 if err != nil { 357 return nil, err 358 } 359 // 反序列响应结果 360 resp := &PatchSchemaResp{ApiResp: apiResp} 361 err = apiResp.JSONUnmarshalBody(resp) 362 if err != nil { 363 return nil, err 364 } 365 return resp, err 366 }