├── .github ├── dependabot.yml └── workflows │ ├── ci.yml │ ├── client-tests.yml │ └── tag.yml ├── .gitignore ├── LICENSE ├── README.md ├── client.go ├── client_test.go ├── docarray ├── docarray.pb.go ├── json.go ├── v0.16.5 │ ├── docarray.pb.go │ └── json.go ├── v0.17.0 │ ├── docarray.pb.go │ └── json.go ├── v0.18.1 │ ├── docarray.pb.go │ └── json.go ├── v0.19.0 │ ├── docarray.pb.go │ └── json.go ├── v0.19.1 │ ├── docarray.pb.go │ └── json.go ├── v0.20.1 │ ├── docarray.pb.go │ └── json.go ├── v0.21.0 │ ├── docarray.pb.go │ └── json.go └── v0.21.1 │ ├── docarray.pb.go │ └── json.go ├── examples ├── grpc │ ├── README.md │ ├── flow.yml │ └── main.go ├── healthcheck │ ├── grpc │ │ ├── README.md │ │ ├── flow.yml │ │ └── main.go │ ├── http │ │ ├── README.md │ │ ├── flow.yml │ │ └── main.go │ └── websocket │ │ ├── README.md │ │ ├── flow.yml │ │ └── main.go ├── http │ ├── README.md │ ├── flow.yml │ └── main.go ├── info │ ├── grpc │ │ ├── README.md │ │ ├── flow.yml │ │ └── main.go │ ├── http │ │ ├── README.md │ │ ├── flow.yml │ │ └── main.go │ └── websocket │ │ ├── README.md │ │ ├── flow.yml │ │ └── main.go └── websocket │ ├── README.md │ ├── flow.yml │ └── main.go ├── go.mod ├── go.sum ├── grpc.go ├── grpc_test.go ├── http.go ├── http_test.go ├── jina ├── jina.pb.go ├── jina_grpc.pb.go ├── json.go ├── v3.10.0 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.11.0 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.11.2 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.12.0 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.13.0 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.13.1 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.13.2 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.14.0 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.14.1 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.18.0 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.19.1 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.20.1 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.20.2 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.21.1 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.22.0 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.22.1 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.22.2 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.22.4 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.23.0 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── v3.23.1 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go └── v3.9.0 │ ├── jina.pb.go │ ├── jina_grpc.pb.go │ └── json.go ├── protos ├── docarray.proto └── jina.proto ├── requirements.txt ├── scripts ├── fetchProtos.sh └── protogen.sh ├── websocket.go └── websocket_test.go /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "pip" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | open-pull-requests-limit: 1 8 | allow: 9 | - dependency-name: "jina" 10 | # ignore: 11 | # # ignore jina patch updates 12 | # - dependency-name: "jina" 13 | # update-types: ["version-update:semver-patch"] 14 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Version Update 2 | 3 | on: 4 | pull_request_target: 5 | paths: 6 | - requirements.txt 7 | pull_request: 8 | paths: 9 | - requirements.txt 10 | 11 | permissions: 12 | contents: write 13 | issues: write 14 | pull-requests: write 15 | 16 | concurrency: 17 | group: ${{ github.head_ref }} 18 | cancel-in-progress: true 19 | 20 | jobs: 21 | version-update: 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Checkout Repo 25 | uses: actions/checkout@v2 26 | with: 27 | ref: ${{ github.head_ref }} 28 | 29 | - name: Setup Python 30 | uses: actions/setup-python@v2 31 | with: 32 | python-version: 3.8 33 | 34 | - name: Setup Golang 35 | uses: actions/setup-go@v2 36 | with: 37 | go-version: 1.18 38 | 39 | - name: Install Dependencies 40 | run: | 41 | go mod tidy -v 42 | pip install -r requirements.txt 43 | pip install pydantic==1.10.2 44 | sudo apt-get update 45 | 46 | # https://grpc.io/docs/protoc-installation/#install-pre-compiled-binaries-any-os 47 | wget https://github.com/protocolbuffers/protobuf/releases/download/v21.7/protoc-21.7-linux-x86_64.zip 48 | unzip protoc-21.7-linux-x86_64.zip -d $HOME/.local 49 | rm protoc-21.7-linux-x86_64.zip 50 | 51 | # https://stackoverflow.com/a/62872353/15683245 52 | go get -u google.golang.org/protobuf/cmd/protoc-gen-go 53 | go install google.golang.org/protobuf/cmd/protoc-gen-go 54 | go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc 55 | go install google.golang.org/grpc/cmd/protoc-gen-go-grpc 56 | 57 | - name: Get Jina & Docarray Versions 58 | id: versions 59 | run: | 60 | echo "::set-output name=JINA_VERSION::$(jina -v)" 61 | echo "::set-output name=DOCARRAY_VERSION::$(python -c "import docarray; print(docarray.__version__)")" 62 | 63 | - name: Download proto files 64 | run: | 65 | bash scripts/fetchProtos.sh ${{ steps.versions.outputs.JINA_VERSION }} ${{ steps.versions.outputs.DOCARRAY_VERSION }} 66 | 67 | - name: Generate Golang Code from protos 68 | run: | 69 | export GOROOT=/usr/local/go 70 | export GOPATH=$HOME/go 71 | export GOBIN=$GOPATH/bin 72 | export PATH="$PATH:$GOROOT:$GOPATH:$GOBIN:$HOME/.local/bin" 73 | bash scripts/protogen.sh ${{ steps.versions.outputs.JINA_VERSION }} ${{ steps.versions.outputs.DOCARRAY_VERSION }} 74 | 75 | - name: Run Tests 76 | run: | 77 | go mod tidy -v 78 | go get github.com/onsi/ginkgo/v2/ginkgo/generators@v2.1.6 79 | go get github.com/onsi/ginkgo/v2/ginkgo/internal@v2.1.6 80 | go get github.com/onsi/ginkgo/v2/ginkgo/labels@v2.1.6 81 | go install github.com/onsi/ginkgo/v2/ginkgo 82 | go get github.com/onsi/gomega/... 83 | go mod tidy -v 84 | ginkgo --progress -v . 85 | 86 | - name: Commit & Push 87 | uses: stefanzweifel/git-auto-commit-action@v4 88 | with: 89 | commit_message: "chore: update protos for jina ${{ steps.versions.outputs.JINA_VERSION }} and docarray ${{ steps.versions.outputs.DOCARRAY_VERSION }}" 90 | commit_options: "--signoff" 91 | branch: ${{ github.head_ref }} 92 | commit_user_name: "Jina Dev Bot" 93 | commit_user_email: "dev-bot@jina.ai" 94 | 95 | - name: Setup tmate session for debugging 96 | if: ${{ failure() }} 97 | uses: mxschmitt/action-tmate@v3 98 | timeout-minutes: 30 99 | -------------------------------------------------------------------------------- /.github/workflows/client-tests.yml: -------------------------------------------------------------------------------- 1 | name: Integration Tests 2 | 3 | on: 4 | pull_request: 5 | 6 | jobs: 7 | core-tests: 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | python-version: [3.7] 13 | steps: 14 | - name: Checkout Repo 15 | uses: actions/checkout@v2 16 | 17 | - name: Set up Python ${{ matrix.python-version }} 18 | uses: actions/setup-python@v2 19 | with: 20 | python-version: ${{ matrix.python-version }} 21 | 22 | - name: Install jina 23 | run: | 24 | python -m pip install --upgrade pip 25 | python -m pip install wheel 26 | pip install -r requirements.txt 27 | 28 | - name: Setup Golang 1.18 29 | uses: actions/setup-go@v3 30 | with: 31 | go-version: 1.18 32 | 33 | - name: Install Dependencies 34 | run: | 35 | go mod tidy -v 36 | go get github.com/onsi/ginkgo/v2/ginkgo/generators@v2.1.6 37 | go get github.com/onsi/ginkgo/v2/ginkgo/internal@v2.1.6 38 | go get github.com/onsi/ginkgo/v2/ginkgo/labels@v2.1.6 39 | go install github.com/onsi/ginkgo/v2/ginkgo 40 | go get github.com/onsi/gomega/... 41 | go mod tidy -v 42 | 43 | - name: Run Client Tests 44 | run: ginkgo --vv --progress 45 | env: 46 | ACK_GINKGO_RC: true 47 | ACK_GINKGO_DEPRECATIONS: 1.16.5 48 | -------------------------------------------------------------------------------- /.github/workflows/tag.yml: -------------------------------------------------------------------------------- 1 | name: Tag & Release 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: 7 | - main 8 | paths: 9 | - requirements.txt 10 | 11 | jobs: 12 | tag: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout Repo 16 | uses: actions/checkout@v2 17 | 18 | - name: Setup Python 19 | uses: actions/setup-python@v2 20 | with: 21 | python-version: 3.8 22 | 23 | - name: Install Dependencies 24 | run: | 25 | pip install -r requirements.txt 26 | 27 | - name: Get Jina & Docarray Versions 28 | id: versions 29 | run: | 30 | echo "::set-output name=JINA_VERSION::$(jina -v)" 31 | echo "::set-output name=DOCARRAY_VERSION::$(python -c "import docarray; print(docarray.__version__)")" 32 | 33 | - name: Create a GitHub release 34 | uses: ncipollo/release-action@v1 35 | with: 36 | tag: "v${{ steps.versions.outputs.JINA_VERSION }}" 37 | name: "Release v${{ steps.versions.outputs.JINA_VERSION }}" 38 | body: "Automated release for jina v${{ steps.versions.outputs.JINA_VERSION }} with docarray v${{ steps.versions.outputs.DOCARRAY_VERSION }}" 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ 16 | 17 | play/ 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jina Golang Client 2 | 3 | ### Install 4 | 5 | ```bash 6 | go get github.com/jina-ai/client-go 7 | ``` 8 | 9 | ### Basic Usage 10 | 11 | ```go 12 | package main 13 | 14 | import ( 15 | "fmt" 16 | 17 | "github.com/jina-ai/client-go" 18 | "github.com/jina-ai/client-go/docarray" 19 | "github.com/jina-ai/client-go/jina" 20 | ) 21 | 22 | // Create a Document 23 | func getDoc(id string) *docarray.DocumentProto { 24 | return &docarray.DocumentProto{ 25 | Id: id, 26 | Content: &docarray.DocumentProto_Text{ 27 | Text: "Hello world. This is a test document with id:" + id, 28 | }, 29 | } 30 | } 31 | 32 | // Create a DocumentArray with 3 Documents 33 | func getDocarray() *docarray.DocumentArrayProto { 34 | return &docarray.DocumentArrayProto{ 35 | Docs: []*docarray.DocumentProto{getDoc("1"), getDoc("2"), getDoc("3")}, 36 | } 37 | } 38 | 39 | // Create DataRequest with a DocumentArray 40 | func getDataRequest() *jina.DataRequestProto { 41 | return &jina.DataRequestProto{ 42 | Data: &jina.DataRequestProto_DataContentProto{ 43 | Documents: &jina.DataRequestProto_DataContentProto_Docs{ 44 | Docs: getDocarray(), 45 | }, 46 | }, 47 | } 48 | } 49 | 50 | // Generate `DataRequest`s with random DocumentArrays 51 | func generateDataRequests() <-chan *jina.DataRequestProto { 52 | requests := make(chan *jina.DataRequestProto) 53 | go func() { 54 | // Generate 10 requests 55 | for i := 0; i < 10; i++ { 56 | requests <- getDataRequest() 57 | } 58 | defer close(requests) 59 | }() 60 | return requests 61 | } 62 | 63 | // Custom OnDone callback 64 | func OnDone(resp *jina.DataRequestProto) { 65 | fmt.Println("Got a successful response!") 66 | } 67 | 68 | // Custom OnError callback 69 | func OnError(resp *jina.DataRequestProto) { 70 | fmt.Println("Got an error in response!") 71 | } 72 | 73 | func main() { 74 | // Create a HTTP client (expects a Jina Flow with http protocol running on localhost:12345) 75 | HTTPClient, err := client.NewHTTPClient("http://localhost:12345") 76 | if err != nil { 77 | panic(err) 78 | } 79 | 80 | // Send requests to the Flow 81 | HTTPClient.POST(generateDataRequests(), OnDone, OnError, nil) 82 | } 83 | 84 | ``` 85 | 86 | 87 | 88 | ### Examples 89 | 90 | 91 | | Example | | 92 | | :--- | ---: | 93 | | [gRPC](examples/grpc/) | Stream requests using gRPC Client | 94 | | [HTTP](examples/http/) | Stream requests using HTTP Client | 95 | | [WebSocket](examples/websocket/) | Stream requests using WebSocket Client | 96 | | [gRPC Healthcheck](examples/healthcheck/grpc/) | Check if the gRPC Flow is healthy | 97 | | [HTTP Healthcheck](examples/healthcheck/http/) | Check if the HTTP Flow is healthy | 98 | | [WebSocket Healthcheck](examples/healthcheck/websocket/) | Check if the WebSocket Flow is healthy | 99 | | [gRPC Info](examples/info/grpc/) | Get info about the gRPC Flow | 100 | | [HTTP Info](examples/info/http/) | Get info about the HTTP Flow | 101 | | [WebSocket Info](examples/info/websocket/) | Get info about the WebSocket Flow | 102 | | DocArray usage | Example usage of DocArray (TODO) | 103 | | Concurrent requests | Send concurrent requests to Jina Gateway (TODO) | 104 | 105 | 106 | 107 | ### Gotchas 108 | 109 | ##### Directory structure 110 | 111 | ```bash 112 | . 113 | ├── protos 114 | │ ├── docarray.proto # proto file for DocArray 115 | │ └── jina.proto # proto file for Jina 116 | ├── docarray # docarray package 117 | │ ├── docarray.pb.go # generated from docarray.proto 118 | │ └── json.go # custom json (un)marshaler for few fields in docarray.proto 119 | ├── jina # jina package 120 | │ ├── jina_grpc.pb.go # generated from jina.proto 121 | │ ├── jina.pb.go # generated from jina.proto 122 | │ └── json.go # custom json (un)marshaler for few fields in jina.proto 123 | ├── client.go # Client interface 124 | ├── grpc.go # gRPC client 125 | ├── http.go # HTTP client 126 | ├── websocket.go # WebSocket client 127 | ├── scripts 128 | └ └── protogen.sh # script to Golang code from proto files 129 | ``` 130 | 131 | - `scripts/protogen.sh` generates the Golang code from the protos. Each proto generates code in a separate package. This is to avoid name clashes. 132 | 133 | - `jina/json.go` and `docarray/json.go` are custom json (un)marshalers for few fields in `jina.proto` and `docarray.proto` respectively. 134 | 135 | - `client.go` defines the `Client` & `HealthCheckClient` interface. This is implemented by `grpc.go`, `http.go` and `websocket.go`. 136 | 137 | 138 | #### Jina/Docarray Version Compatibility 139 | 140 | Current jina version is mentioned in the [requirements.txt](requirements.txt) file. Every time, there's a PR that bumps the jina version (managed using [Dependabot](.github/dependabot.yml)) , [Version Update](.github/workflows/ci.yml) workflow, 141 | - Downloads the right protos for jina & docarray. 142 | - Generates the Golang code from the protos. 143 | - Runs integration tests. 144 | - If all tests pass, it commits the latest code into the same branch. 145 | 146 | Once the PR is merged, a release is created with the new Jina version via [Tag & Release](.github/workflows/tag.yml) workflow. 147 | 148 | --- 149 | 150 | Another (better?) approach for keeping all docarray/jina versions compatible would be, 151 | 152 | - For all docarray versions, generate the Golang code from the protos under `docarray/v1`, `docarray/v2` packages. 153 | - For all jina versions, generate the Golang code from the protos under `jina/v1`, `jina/v2` packages. 154 | - Skip re-releasing the client-go package for every jina version, rather user can pick the right version of jina/docarray package. 155 | -------------------------------------------------------------------------------- /client.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | "net" 7 | "net/http" 8 | "strings" 9 | "time" 10 | 11 | "github.com/jina-ai/client-go/jina" 12 | "github.com/viki-org/dnscache" 13 | ) 14 | 15 | var Resolver = dnscache.New(10 * time.Second) 16 | var HttpClient *http.Client 17 | 18 | type CallbackType func(*jina.DataRequestProto) 19 | 20 | type Client interface { 21 | POST(requests <-chan *jina.DataRequestProto, onDone, onError, onAlways CallbackType) error 22 | SequentialPOST(requests <-chan *jina.DataRequestProto, onDone, onError, onAlways CallbackType) error 23 | } 24 | 25 | type HealthCheckClient interface { 26 | HealthCheck() (bool, error) 27 | } 28 | 29 | // Clint & resolver taken from https://github.com/juicedata/juicefs/blob/main/pkg/object/restful.go 30 | func updateHTTPClient() { 31 | HttpClient = &http.Client{ 32 | Transport: &http.Transport{ 33 | Proxy: http.ProxyFromEnvironment, 34 | TLSHandshakeTimeout: time.Second * 20, 35 | ResponseHeaderTimeout: time.Second * 300, 36 | IdleConnTimeout: time.Second * 300, 37 | MaxIdleConnsPerHost: 50, 38 | Dial: func(network string, address string) (net.Conn, error) { 39 | separator := strings.LastIndex(address, ":") 40 | host := address[:separator] 41 | port := address[separator:] 42 | ips, err := Resolver.Fetch(host) 43 | if err != nil { 44 | return nil, err 45 | } 46 | if len(ips) == 0 { 47 | return nil, fmt.Errorf("no such host: %s", host) 48 | } 49 | var conn net.Conn 50 | n := len(ips) 51 | first := rand.Intn(n) 52 | dialer := &net.Dialer{Timeout: time.Second * 10} 53 | for i := 0; i < n; i++ { 54 | ip := ips[(first+i)%n] 55 | address = ip.String() 56 | if port != "" { 57 | address = net.JoinHostPort(address, port[1:]) 58 | } 59 | conn, err = dialer.Dial(network, address) 60 | if err == nil { 61 | return conn, nil 62 | } 63 | } 64 | return nil, err 65 | }, 66 | DisableCompression: true, 67 | }, 68 | Timeout: time.Hour, 69 | } 70 | } 71 | 72 | func init() { 73 | updateHTTPClient() 74 | } 75 | -------------------------------------------------------------------------------- /client_test.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "fmt" 5 | "os/exec" 6 | "path/filepath" 7 | "runtime" 8 | "testing" 9 | 10 | "github.com/jina-ai/client-go/docarray" 11 | "github.com/jina-ai/client-go/jina" 12 | . "github.com/onsi/ginkgo/v2" 13 | . "github.com/onsi/gomega" 14 | "github.com/shirou/gopsutil/v3/process" 15 | ) 16 | 17 | func TestClients(t *testing.T) { 18 | RegisterFailHandler(Fail) 19 | 20 | RunSpecsWithDefaultAndCustomReporters(t, "Client Suite", []Reporter{}) 21 | } 22 | 23 | func execCommand(name string, arg ...string) func() { 24 | cmd := exec.Command(name, arg...) 25 | if err := cmd.Start(); err != nil { 26 | fmt.Println("Error starting command", err) 27 | } 28 | return func() { 29 | jina := "jina" 30 | processes, _ := process.Pids() 31 | for _, element := range processes { 32 | pro, _ := process.NewProcess(element) 33 | pro_name, _ := pro.Name() 34 | if pro_name == jina { 35 | pro.Kill() 36 | } 37 | } 38 | } 39 | } 40 | 41 | func startFlow(path string) func() { 42 | return execCommand("jina", "flow", "--uses", filepath.Join(curDir(), path)) 43 | } 44 | 45 | func curDir() string { 46 | _, filename, _, _ := runtime.Caller(1) 47 | return filepath.Dir(filename) 48 | } 49 | 50 | // Create a Document 51 | func getDoc(id string) *docarray.DocumentProto { 52 | return &docarray.DocumentProto{ 53 | Id: id, 54 | Content: &docarray.DocumentProto_Text{ 55 | Text: "Hello world. This is a test document with id:" + id, 56 | }, 57 | } 58 | } 59 | 60 | // Create a DocumentArray with 3 Documents 61 | func getDocarrays(numDocs int) *docarray.DocumentArrayProto { 62 | var docs []*docarray.DocumentProto 63 | for i := 0; i < numDocs; i++ { 64 | docs = append(docs, getDoc(fmt.Sprint(i))) 65 | } 66 | return &docarray.DocumentArrayProto{ 67 | Docs: docs, 68 | } 69 | } 70 | 71 | // Create DataRequest with a DocumentArray 72 | func getDataRequest(numDocs int) *jina.DataRequestProto { 73 | return &jina.DataRequestProto{ 74 | Data: &jina.DataRequestProto_DataContentProto{ 75 | Documents: &jina.DataRequestProto_DataContentProto_Docs{ 76 | Docs: getDocarrays(numDocs), 77 | }, 78 | }, 79 | } 80 | } 81 | 82 | // Generate a stream of requests 83 | func generateDataRequests(numRequests int) <-chan *jina.DataRequestProto { 84 | defer GinkgoRecover() 85 | requests := make(chan *jina.DataRequestProto) 86 | go func() { 87 | for i := 0; i < numRequests; i++ { 88 | requests <- getDataRequest(3) 89 | } 90 | defer close(requests) 91 | }() 92 | return requests 93 | } 94 | 95 | func OnDone(resp *jina.DataRequestProto) { 96 | defer GinkgoRecover() 97 | switch docs := resp.Data.Documents.(type) { 98 | case *jina.DataRequestProto_DataContentProto_Docs: 99 | By("should have the correct number of documents") 100 | Expect(len(docs.Docs.Docs)).To(Equal(3)) 101 | 102 | for docidx, doc := range docs.Docs.Docs { 103 | By(fmt.Sprintf("should have the correct id for document %d", docidx)) 104 | Expect(doc.Id).To(Equal(fmt.Sprint(docidx))) 105 | 106 | By(fmt.Sprintf("should have the correct text for document %d", docidx)) 107 | Expect(doc.Chunks).To(HaveLen(2)) 108 | Expect(doc.Chunks[0].Content.(*docarray.DocumentProto_Text).Text).To(Equal("Hello world.")) 109 | Expect(doc.Chunks[1].Content.(*docarray.DocumentProto_Text).Text).To(Equal("This is a test document with id:" + doc.Id)) 110 | 111 | } 112 | } 113 | } 114 | 115 | func OnError(resp *jina.DataRequestProto) { 116 | defer GinkgoRecover() 117 | fmt.Println("Got an error for request", resp) 118 | } 119 | -------------------------------------------------------------------------------- /docarray/json.go: -------------------------------------------------------------------------------- 1 | package docarray 2 | 3 | import ( 4 | "google.golang.org/protobuf/encoding/protojson" 5 | ) 6 | 7 | // Custom JSON marshalling for DocumentProto 8 | func (x *DocumentProto) MarshalJSON() ([]byte, error) { 9 | return protojson.Marshal(x) 10 | } 11 | 12 | // Custom JSON unmarshalling for DocumentProto 13 | func (x *DocumentProto) UnmarshalJSON(data []byte) error { 14 | return protojson.Unmarshal(data, x) 15 | } 16 | -------------------------------------------------------------------------------- /docarray/v0.16.5/json.go: -------------------------------------------------------------------------------- 1 | package docarray 2 | 3 | import ( 4 | "google.golang.org/protobuf/encoding/protojson" 5 | ) 6 | 7 | // Custom JSON marshalling for DocumentProto 8 | func (x *DocumentProto) MarshalJSON() ([]byte, error) { 9 | return protojson.Marshal(x) 10 | } 11 | 12 | // Custom JSON unmarshalling for DocumentProto 13 | func (x *DocumentProto) UnmarshalJSON(data []byte) error { 14 | return protojson.Unmarshal(data, x) 15 | } 16 | -------------------------------------------------------------------------------- /docarray/v0.17.0/json.go: -------------------------------------------------------------------------------- 1 | package docarray 2 | 3 | import ( 4 | "google.golang.org/protobuf/encoding/protojson" 5 | ) 6 | 7 | // Custom JSON marshalling for DocumentProto 8 | func (x *DocumentProto) MarshalJSON() ([]byte, error) { 9 | return protojson.Marshal(x) 10 | } 11 | 12 | // Custom JSON unmarshalling for DocumentProto 13 | func (x *DocumentProto) UnmarshalJSON(data []byte) error { 14 | return protojson.Unmarshal(data, x) 15 | } 16 | -------------------------------------------------------------------------------- /docarray/v0.18.1/json.go: -------------------------------------------------------------------------------- 1 | package docarray 2 | 3 | import ( 4 | "google.golang.org/protobuf/encoding/protojson" 5 | ) 6 | 7 | // Custom JSON marshalling for DocumentProto 8 | func (x *DocumentProto) MarshalJSON() ([]byte, error) { 9 | return protojson.Marshal(x) 10 | } 11 | 12 | // Custom JSON unmarshalling for DocumentProto 13 | func (x *DocumentProto) UnmarshalJSON(data []byte) error { 14 | return protojson.Unmarshal(data, x) 15 | } 16 | -------------------------------------------------------------------------------- /docarray/v0.19.0/json.go: -------------------------------------------------------------------------------- 1 | package docarray 2 | 3 | import ( 4 | "google.golang.org/protobuf/encoding/protojson" 5 | ) 6 | 7 | // Custom JSON marshalling for DocumentProto 8 | func (x *DocumentProto) MarshalJSON() ([]byte, error) { 9 | return protojson.Marshal(x) 10 | } 11 | 12 | // Custom JSON unmarshalling for DocumentProto 13 | func (x *DocumentProto) UnmarshalJSON(data []byte) error { 14 | return protojson.Unmarshal(data, x) 15 | } 16 | -------------------------------------------------------------------------------- /docarray/v0.19.1/json.go: -------------------------------------------------------------------------------- 1 | package docarray 2 | 3 | import ( 4 | "google.golang.org/protobuf/encoding/protojson" 5 | ) 6 | 7 | // Custom JSON marshalling for DocumentProto 8 | func (x *DocumentProto) MarshalJSON() ([]byte, error) { 9 | return protojson.Marshal(x) 10 | } 11 | 12 | // Custom JSON unmarshalling for DocumentProto 13 | func (x *DocumentProto) UnmarshalJSON(data []byte) error { 14 | return protojson.Unmarshal(data, x) 15 | } 16 | -------------------------------------------------------------------------------- /docarray/v0.20.1/json.go: -------------------------------------------------------------------------------- 1 | package docarray 2 | 3 | import ( 4 | "google.golang.org/protobuf/encoding/protojson" 5 | ) 6 | 7 | // Custom JSON marshalling for DocumentProto 8 | func (x *DocumentProto) MarshalJSON() ([]byte, error) { 9 | return protojson.Marshal(x) 10 | } 11 | 12 | // Custom JSON unmarshalling for DocumentProto 13 | func (x *DocumentProto) UnmarshalJSON(data []byte) error { 14 | return protojson.Unmarshal(data, x) 15 | } 16 | -------------------------------------------------------------------------------- /docarray/v0.21.0/json.go: -------------------------------------------------------------------------------- 1 | package docarray 2 | 3 | import ( 4 | "google.golang.org/protobuf/encoding/protojson" 5 | ) 6 | 7 | // Custom JSON marshalling for DocumentProto 8 | func (x *DocumentProto) MarshalJSON() ([]byte, error) { 9 | return protojson.Marshal(x) 10 | } 11 | 12 | // Custom JSON unmarshalling for DocumentProto 13 | func (x *DocumentProto) UnmarshalJSON(data []byte) error { 14 | return protojson.Unmarshal(data, x) 15 | } 16 | -------------------------------------------------------------------------------- /docarray/v0.21.1/json.go: -------------------------------------------------------------------------------- 1 | package docarray 2 | 3 | import ( 4 | "google.golang.org/protobuf/encoding/protojson" 5 | ) 6 | 7 | // Custom JSON marshalling for DocumentProto 8 | func (x *DocumentProto) MarshalJSON() ([]byte, error) { 9 | return protojson.Marshal(x) 10 | } 11 | 12 | // Custom JSON unmarshalling for DocumentProto 13 | func (x *DocumentProto) UnmarshalJSON(data []byte) error { 14 | return protojson.Unmarshal(data, x) 15 | } 16 | -------------------------------------------------------------------------------- /examples/grpc/README.md: -------------------------------------------------------------------------------- 1 | ## gRPC Client 2 | 3 | #### Start a Flow with gRPC protocol 4 | 5 | ```bash 6 | jina flow --uses flow.yml 7 | ``` 8 | 9 | #### Send `DataRequest`s to the Flow 10 | 11 | ```bash 12 | go run main.go --host grpc://localhost:12345 13 | ``` 14 | ```text 15 | Total 3 docs received. 16 | DocID: 0 17 | Chunk 0 text: Hello world. 18 | Chunk 1 text: This is a test document with id:0 19 | DocID: 1 20 | Chunk 0 text: Hello world. 21 | Chunk 1 text: This is a test document with id:1 22 | DocID: 2 23 | Chunk 0 text: Hello world. 24 | Chunk 1 text: This is a test document with id:2 25 | ``` 26 | -------------------------------------------------------------------------------- /examples/grpc/flow.yml: -------------------------------------------------------------------------------- 1 | jtype: Flow 2 | with: 3 | protocol: grpc 4 | port: 12345 5 | env: 6 | JINA_LOG_LEVEL: DEBUG 7 | executors: 8 | - name: sentencizer 9 | uses: jinahub://Sentencizer 10 | -------------------------------------------------------------------------------- /examples/grpc/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | 7 | "github.com/jina-ai/client-go" 8 | "github.com/jina-ai/client-go/docarray" 9 | "github.com/jina-ai/client-go/jina" 10 | ) 11 | 12 | // Create a Document 13 | func getDoc(id string) *docarray.DocumentProto { 14 | return &docarray.DocumentProto{ 15 | Id: id, 16 | Content: &docarray.DocumentProto_Text{ 17 | Text: "Hello world. This is a test document with id:" + id, 18 | }, 19 | } 20 | } 21 | 22 | // Create a DocumentArray with 3 Documents 23 | func getDocarrays(numDocs int) *docarray.DocumentArrayProto { 24 | var docs []*docarray.DocumentProto 25 | for i := 0; i < numDocs; i++ { 26 | docs = append(docs, getDoc(fmt.Sprint(i))) 27 | } 28 | return &docarray.DocumentArrayProto{ 29 | Docs: docs, 30 | } 31 | } 32 | 33 | // Create DataRequest with a DocumentArray 34 | func getDataRequest(numDocs int) *jina.DataRequestProto { 35 | return &jina.DataRequestProto{ 36 | Data: &jina.DataRequestProto_DataContentProto{ 37 | Documents: &jina.DataRequestProto_DataContentProto_Docs{ 38 | Docs: getDocarrays(numDocs), 39 | }, 40 | }, 41 | } 42 | } 43 | 44 | // Generate a stream of requests 45 | func generateDataRequests(numRequests int) <-chan *jina.DataRequestProto { 46 | requests := make(chan *jina.DataRequestProto) 47 | go func() { 48 | for i := 0; i < numRequests; i++ { 49 | requests <- getDataRequest(3) 50 | } 51 | defer close(requests) 52 | }() 53 | return requests 54 | } 55 | 56 | func OnDone(resp *jina.DataRequestProto) { 57 | switch docs := resp.Data.Documents.(type) { 58 | case *jina.DataRequestProto_DataContentProto_Docs: 59 | fmt.Printf("\n\nTotal %d docs received.", len(docs.Docs.Docs)) 60 | for docidx, doc := range docs.Docs.Docs { 61 | fmt.Printf("\nDocID: %d", docidx) 62 | for i, chunk := range doc.Chunks { 63 | fmt.Printf("\n\tChunk %d text: %s ", i, chunk.Content.(*docarray.DocumentProto_Text).Text) 64 | } 65 | } 66 | } 67 | } 68 | 69 | func OnError(resp *jina.DataRequestProto) { 70 | fmt.Println("Got an error for request", resp) 71 | } 72 | 73 | func main() { 74 | host := flag.String("host", "", "host of the gateway") 75 | flag.Parse() 76 | 77 | if *host == "" { 78 | panic("Please pass a host to check the health of") 79 | } 80 | 81 | GRPCClient, err := client.NewGRPCClient(*host) 82 | if err != nil { 83 | panic(err) 84 | } 85 | GRPCClient.POST(generateDataRequests(5), OnDone, OnError, nil) 86 | } 87 | -------------------------------------------------------------------------------- /examples/healthcheck/grpc/README.md: -------------------------------------------------------------------------------- 1 | ## Healthcheck for gRPC Flow 2 | 3 | ### Start a Flow with gRPC protocol 4 | 5 | ```bash 6 | jina flow --uses flow.yml 7 | ``` 8 | 9 | ### Check if the Flow is healthy 10 | 11 | ##### Healthy Flow 12 | ```bash 13 | go run main.go --host localhost:12345 14 | ``` 15 | ```text 16 | Flow running at localhost:12345 is healthy! 17 | ``` 18 | 19 | ##### Unhealthy Flow 20 | ```bash 21 | go run main.go --host localhost:12346 22 | ``` 23 | ```text 24 | panic: failed to check health: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 127.0.0.1:12345: connect: connection refused" 25 | ``` 26 | -------------------------------------------------------------------------------- /examples/healthcheck/grpc/flow.yml: -------------------------------------------------------------------------------- 1 | jtype: Flow 2 | with: 3 | protocol: grpc 4 | port: 12345 5 | executors: 6 | - name: e1 7 | -------------------------------------------------------------------------------- /examples/healthcheck/grpc/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | 7 | "github.com/jina-ai/client-go" 8 | ) 9 | 10 | func main() { 11 | host := flag.String("host", "", "host of the gateway") 12 | flag.Parse() 13 | 14 | if *host == "" { 15 | panic("Please pass a host to check the health of") 16 | } 17 | 18 | hcClient, err := client.NewGRPCHealthCheckClient(*host) 19 | if err != nil { 20 | panic(fmt.Errorf("unsuccessful healthcheck: %w", err)) 21 | } 22 | 23 | status, err := hcClient.HealthCheck() 24 | if err != nil { 25 | panic(fmt.Errorf("failed to check health: %w", err)) 26 | } 27 | if status { 28 | fmt.Println("Flow running at", *host, "is healthy!") 29 | } else { 30 | panic(fmt.Errorf("unsuccessful healthcheck")) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /examples/healthcheck/http/README.md: -------------------------------------------------------------------------------- 1 | ## Healthcheck for HTTP Flow 2 | 3 | ### Start a Flow with HTTP protocol 4 | 5 | ```bash 6 | jina flow --uses flow.yml 7 | ``` 8 | 9 | ### Check if the Flow is healthy 10 | 11 | ##### Healthy Flow 12 | ```bash 13 | go run main.go --host localhost:12345 14 | ``` 15 | ```text 16 | Flow running at localhost:12345 is healthy! 17 | ``` 18 | 19 | ##### Unhealthy Flow 20 | ```bash 21 | go run main.go --host localhost:12346 22 | ``` 23 | ```text 24 | panic: failed to check health: Get "http://localhost:12346": dial tcp 127.0.0.1:12346: connect: connection refused 25 | ``` 26 | -------------------------------------------------------------------------------- /examples/healthcheck/http/flow.yml: -------------------------------------------------------------------------------- 1 | jtype: Flow 2 | with: 3 | protocol: http 4 | port: 12345 5 | executors: 6 | - name: e1 7 | -------------------------------------------------------------------------------- /examples/healthcheck/http/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | 7 | "github.com/jina-ai/client-go" 8 | ) 9 | 10 | func main() { 11 | host := flag.String("host", "", "host of the gateway") 12 | flag.Parse() 13 | 14 | if *host == "" { 15 | panic("Please pass a host to check the health of") 16 | } 17 | 18 | hcClient, err := client.NewHTTPHealthCheckClient(*host) 19 | if err != nil { 20 | panic(fmt.Errorf("unsuccessful healthcheck: %w", err)) 21 | } 22 | 23 | status, err := hcClient.HealthCheck() 24 | if err != nil { 25 | panic(fmt.Errorf("failed to check health: %w", err)) 26 | } 27 | if status { 28 | fmt.Println("Flow running at", *host, "is healthy!") 29 | } else { 30 | panic(fmt.Errorf("unsuccessful healthcheck")) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /examples/healthcheck/websocket/README.md: -------------------------------------------------------------------------------- 1 | ## Healthcheck for WebSocket Flow 2 | 3 | ### Start a Flow with WebSocket protocol 4 | 5 | ```bash 6 | jina flow --uses flow.yml 7 | ``` 8 | 9 | ### Check if the Flow is healthy 10 | 11 | ##### Healthy Flow 12 | ```bash 13 | go run main.go --host localhost:12345 14 | ``` 15 | ```text 16 | Flow running at localhost:12345 is healthy! 17 | ``` 18 | 19 | ##### Unhealthy Flow 20 | ```bash 21 | go run main.go --host localhost:12346 22 | ``` 23 | ```text 24 | panic: failed to check health: Get "http://localhost:12346": dial tcp 127.0.0.1:12346: connect: connection refused 25 | ``` 26 | -------------------------------------------------------------------------------- /examples/healthcheck/websocket/flow.yml: -------------------------------------------------------------------------------- 1 | jtype: Flow 2 | with: 3 | protocol: websocket 4 | port: 12345 5 | executors: 6 | - name: e1 7 | -------------------------------------------------------------------------------- /examples/healthcheck/websocket/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | 7 | "github.com/jina-ai/client-go" 8 | ) 9 | 10 | func main() { 11 | host := flag.String("host", "", "host of the gateway") 12 | flag.Parse() 13 | 14 | if *host == "" { 15 | panic("Please pass a host to check the health of") 16 | } 17 | 18 | hcClient, err := client.NewWebSocketHealthCheckClient(*host) 19 | if err != nil { 20 | panic(fmt.Errorf("unsuccessful healthcheck: %w", err)) 21 | } 22 | 23 | status, err := hcClient.HealthCheck() 24 | if err != nil { 25 | panic(fmt.Errorf("failed to check health: %w", err)) 26 | } 27 | if status { 28 | fmt.Println("Flow running at", *host, "is healthy!") 29 | } else { 30 | panic(fmt.Errorf("unsuccessful healthcheck")) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /examples/http/README.md: -------------------------------------------------------------------------------- 1 | ## HTTP Client 2 | 3 | #### Start a Flow with HTTP protocol 4 | 5 | ```bash 6 | jina flow --uses flow.yml 7 | ``` 8 | 9 | #### Send `DataRequest`s to the Flow 10 | 11 | ```bash 12 | go run main.go --host http://localhost:12345 13 | ``` 14 | ```text 15 | Total 3 docs received. 16 | DocID: 0 17 | Chunk 0 text: Hello world. 18 | Chunk 1 text: This is a test document with id:0 19 | DocID: 1 20 | Chunk 0 text: Hello world. 21 | Chunk 1 text: This is a test document with id:1 22 | DocID: 2 23 | Chunk 0 text: Hello world. 24 | Chunk 1 text: This is a test document with id:2 25 | ``` 26 | -------------------------------------------------------------------------------- /examples/http/flow.yml: -------------------------------------------------------------------------------- 1 | jtype: Flow 2 | with: 3 | protocol: http 4 | port: 12345 5 | env: 6 | JINA_LOG_LEVEL: DEBUG 7 | executors: 8 | - name: sentencizer 9 | uses: jinahub://Sentencizer 10 | -------------------------------------------------------------------------------- /examples/http/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | 7 | "github.com/jina-ai/client-go" 8 | "github.com/jina-ai/client-go/docarray" 9 | "github.com/jina-ai/client-go/jina" 10 | ) 11 | 12 | // Create a Document 13 | func getDoc(id string) *docarray.DocumentProto { 14 | return &docarray.DocumentProto{ 15 | Id: id, 16 | Content: &docarray.DocumentProto_Text{ 17 | Text: "Hello world. This is a test document with id:" + id, 18 | }, 19 | } 20 | } 21 | 22 | // Create a DocumentArray with 3 Documents 23 | func getDocarrays(numDocs int) *docarray.DocumentArrayProto { 24 | var docs []*docarray.DocumentProto 25 | for i := 0; i < numDocs; i++ { 26 | docs = append(docs, getDoc(fmt.Sprint(i))) 27 | } 28 | return &docarray.DocumentArrayProto{ 29 | Docs: docs, 30 | } 31 | } 32 | 33 | // Create DataRequest with a DocumentArray 34 | func getDataRequest(numDocs int) *jina.DataRequestProto { 35 | return &jina.DataRequestProto{ 36 | Data: &jina.DataRequestProto_DataContentProto{ 37 | Documents: &jina.DataRequestProto_DataContentProto_Docs{ 38 | Docs: getDocarrays(numDocs), 39 | }, 40 | }, 41 | } 42 | } 43 | 44 | // Generate a stream of requests 45 | func generateDataRequests(numRequests int) <-chan *jina.DataRequestProto { 46 | requests := make(chan *jina.DataRequestProto) 47 | go func() { 48 | for i := 0; i < numRequests; i++ { 49 | requests <- getDataRequest(3) 50 | } 51 | defer close(requests) 52 | }() 53 | return requests 54 | } 55 | 56 | func OnDone(resp *jina.DataRequestProto) { 57 | switch docs := resp.Data.Documents.(type) { 58 | case *jina.DataRequestProto_DataContentProto_Docs: 59 | fmt.Printf("\n\nTotal %d docs received.", len(docs.Docs.Docs)) 60 | for docidx, doc := range docs.Docs.Docs { 61 | fmt.Printf("\nDocID: %d, Chunks: %d", docidx, len(doc.Chunks)) 62 | for i, chunk := range doc.Chunks { 63 | fmt.Printf("\n\tChunk %d text: %s ", i, chunk.Content.(*docarray.DocumentProto_Text).Text) 64 | } 65 | } 66 | } 67 | } 68 | 69 | func OnError(resp *jina.DataRequestProto) { 70 | fmt.Println("Got an error for request", resp) 71 | } 72 | 73 | func main() { 74 | host := flag.String("host", "", "host of the gateway") 75 | flag.Parse() 76 | 77 | if *host == "" { 78 | panic("Please pass a host to check the health of") 79 | } 80 | 81 | HTTPClient, err := client.NewHTTPClient(*host) 82 | if err != nil { 83 | panic(err) 84 | } 85 | HTTPClient.POST(generateDataRequests(5), OnDone, OnError, nil) 86 | } 87 | -------------------------------------------------------------------------------- /examples/info/grpc/README.md: -------------------------------------------------------------------------------- 1 | ## Get Info for gRPC Flow 2 | 3 | ### Start a Flow with gRPC protocol 4 | 5 | ```bash 6 | jina flow --uses flow.yml 7 | ``` 8 | 9 | ### Fetch Info 10 | 11 | ```bash 12 | go run main.go --host grpc://localhost:12345 13 | ``` 14 | ```json 15 | { 16 | "jina": { 17 | "jina": "3.10.0", 18 | "docarray": "0.16.5", 19 | "jcloud": "0.0.37", 20 | "jina-hubble-sdk": "0.18.0", 21 | "jina-proto": "0.1.13", 22 | "protobuf": "4.21.6", 23 | "proto-backend": "upb", 24 | "grpcio": "1.46.0", 25 | "pyyaml": "5.4.1", 26 | "python": "3.7.2", 27 | "platform": "Linux", 28 | "platform-release": "5.15.0-48-generic", 29 | "platform-version": "#54~20.04.1-Ubuntu SMP Thu Sep 1 16:17:26 UTC 2022", 30 | "architecture": "x86_64", 31 | "processor": "x86_64", 32 | "uid": "153855726454644", 33 | "session-id": "734b24c4-4560-11ed-973f-8bee53ec0774", 34 | "uptime": "2022-10-06T15:47:55.642813", 35 | "ci-vendor": "(unset)", 36 | "internal": "False" 37 | }, 38 | "envs": { 39 | "JINA_DEFAULT_HOST": "(unset)", 40 | "JINA_DEFAULT_TIMEOUT_CTRL": "(unset)", 41 | "JINA_DEPLOYMENT_NAME": "(unset)", 42 | "JINA_DISABLE_UVLOOP": "(unset)", 43 | "JINA_EARLY_STOP": "(unset)", 44 | "JINA_FULL_CLI": "(unset)", 45 | "JINA_GATEWAY_IMAGE": "(unset)", 46 | "JINA_GRPC_RECV_BYTES": "(unset)", 47 | "JINA_GRPC_SEND_BYTES": "(unset)", 48 | "JINA_HUB_NO_IMAGE_REBUILD": "(unset)", 49 | "JINA_LOG_CONFIG": "(unset)", 50 | "JINA_LOG_LEVEL": "(unset)", 51 | "JINA_LOG_NO_COLOR": "(unset)", 52 | "JINA_MP_START_METHOD": "(unset)", 53 | "JINA_OPTOUT_TELEMETRY": "(unset)", 54 | "JINA_RANDOM_PORT_MAX": "(unset)", 55 | "JINA_RANDOM_PORT_MIN": "(unset)" 56 | } 57 | } 58 | ``` 59 | -------------------------------------------------------------------------------- /examples/info/grpc/flow.yml: -------------------------------------------------------------------------------- 1 | jtype: Flow 2 | with: 3 | protocol: grpc 4 | port: 12345 5 | executors: 6 | - name: e1 7 | -------------------------------------------------------------------------------- /examples/info/grpc/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | 7 | "github.com/jina-ai/client-go" 8 | ) 9 | 10 | func main() { 11 | host := flag.String("host", "", "host of the gateway") 12 | flag.Parse() 13 | 14 | if *host == "" { 15 | panic("Please pass a host to check the health of") 16 | } 17 | infoClient, err := client.NewGRPCInfoClient(*host) 18 | if err != nil { 19 | panic(fmt.Errorf("unsuccessful info: %w", err)) 20 | } 21 | 22 | info, err := infoClient.InfoJSON() 23 | if err != nil { 24 | panic(fmt.Errorf("failed to check info: %w", err)) 25 | } 26 | fmt.Println(string(info)) 27 | } 28 | -------------------------------------------------------------------------------- /examples/info/http/README.md: -------------------------------------------------------------------------------- 1 | ## Get Info for HTTP Flow 2 | 3 | ### Start a Flow with HTTP protocol 4 | 5 | ```bash 6 | jina flow --uses flow.yml 7 | ``` 8 | 9 | ### Fetch Info 10 | 11 | ```bash 12 | go run main.go --host http://localhost:12345 13 | ``` 14 | ```json 15 | { 16 | "jina": { 17 | "jina": "3.10.0", 18 | "docarray": "0.16.5", 19 | "jcloud": "0.0.37", 20 | "jina-hubble-sdk": "0.18.0", 21 | "jina-proto": "0.1.13", 22 | "protobuf": "4.21.6", 23 | "proto-backend": "upb", 24 | "grpcio": "1.46.0", 25 | "pyyaml": "5.4.1", 26 | "python": "3.7.2", 27 | "platform": "Linux", 28 | "platform-release": "5.15.0-48-generic", 29 | "platform-version": "#54~20.04.1-Ubuntu SMP Thu Sep 1 16:17:26 UTC 2022", 30 | "architecture": "x86_64", 31 | "processor": "x86_64", 32 | "uid": "153855726454644", 33 | "session-id": "734b24c4-4560-11ed-973f-8bee53ec0774", 34 | "uptime": "2022-10-06T15:47:55.642813", 35 | "ci-vendor": "(unset)", 36 | "internal": "False" 37 | }, 38 | "envs": { 39 | "JINA_DEFAULT_HOST": "(unset)", 40 | "JINA_DEFAULT_TIMEOUT_CTRL": "(unset)", 41 | "JINA_DEPLOYMENT_NAME": "(unset)", 42 | "JINA_DISABLE_UVLOOP": "(unset)", 43 | "JINA_EARLY_STOP": "(unset)", 44 | "JINA_FULL_CLI": "(unset)", 45 | "JINA_GATEWAY_IMAGE": "(unset)", 46 | "JINA_GRPC_RECV_BYTES": "(unset)", 47 | "JINA_GRPC_SEND_BYTES": "(unset)", 48 | "JINA_HUB_NO_IMAGE_REBUILD": "(unset)", 49 | "JINA_LOG_CONFIG": "(unset)", 50 | "JINA_LOG_LEVEL": "(unset)", 51 | "JINA_LOG_NO_COLOR": "(unset)", 52 | "JINA_MP_START_METHOD": "(unset)", 53 | "JINA_OPTOUT_TELEMETRY": "(unset)", 54 | "JINA_RANDOM_PORT_MAX": "(unset)", 55 | "JINA_RANDOM_PORT_MIN": "(unset)" 56 | } 57 | } 58 | ``` 59 | -------------------------------------------------------------------------------- /examples/info/http/flow.yml: -------------------------------------------------------------------------------- 1 | jtype: Flow 2 | with: 3 | protocol: http 4 | port: 12345 5 | executors: 6 | - name: e1 7 | -------------------------------------------------------------------------------- /examples/info/http/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | 7 | "github.com/jina-ai/client-go" 8 | ) 9 | 10 | func main() { 11 | host := flag.String("host", "", "host of the gateway") 12 | flag.Parse() 13 | 14 | if *host == "" { 15 | panic("Please pass a host to check the health of") 16 | } 17 | infoClient, err := client.NewHTTPInfoClient(*host) 18 | if err != nil { 19 | panic(fmt.Errorf("unsuccessful info: %w", err)) 20 | } 21 | 22 | info, err := infoClient.InfoJSON() 23 | if err != nil { 24 | panic(fmt.Errorf("failed to check info: %w", err)) 25 | } 26 | fmt.Println(string(info)) 27 | } 28 | -------------------------------------------------------------------------------- /examples/info/websocket/README.md: -------------------------------------------------------------------------------- 1 | ## Get Info for WebSocket Flow 2 | 3 | ### Start a Flow with WebSocket protocol 4 | 5 | ```bash 6 | jina flow --uses flow.yml 7 | ``` 8 | 9 | ### Fetch Info 10 | 11 | ```bash 12 | go run main.go --host ws://localhost:12345 13 | ``` 14 | ```json 15 | { 16 | "jina": { 17 | "jina": "3.10.0", 18 | "docarray": "0.16.5", 19 | "jcloud": "0.0.37", 20 | "jina-hubble-sdk": "0.18.0", 21 | "jina-proto": "0.1.13", 22 | "protobuf": "4.21.6", 23 | "proto-backend": "upb", 24 | "grpcio": "1.46.0", 25 | "pyyaml": "5.4.1", 26 | "python": "3.7.2", 27 | "platform": "Linux", 28 | "platform-release": "5.15.0-48-generic", 29 | "platform-version": "#54~20.04.1-Ubuntu SMP Thu Sep 1 16:17:26 UTC 2022", 30 | "architecture": "x86_64", 31 | "processor": "x86_64", 32 | "uid": "153855726454644", 33 | "session-id": "734b24c4-4560-11ed-973f-8bee53ec0774", 34 | "uptime": "2022-10-06T15:47:55.642813", 35 | "ci-vendor": "(unset)", 36 | "internal": "False" 37 | }, 38 | "envs": { 39 | "JINA_DEFAULT_HOST": "(unset)", 40 | "JINA_DEFAULT_TIMEOUT_CTRL": "(unset)", 41 | "JINA_DEPLOYMENT_NAME": "(unset)", 42 | "JINA_DISABLE_UVLOOP": "(unset)", 43 | "JINA_EARLY_STOP": "(unset)", 44 | "JINA_FULL_CLI": "(unset)", 45 | "JINA_GATEWAY_IMAGE": "(unset)", 46 | "JINA_GRPC_RECV_BYTES": "(unset)", 47 | "JINA_GRPC_SEND_BYTES": "(unset)", 48 | "JINA_HUB_NO_IMAGE_REBUILD": "(unset)", 49 | "JINA_LOG_CONFIG": "(unset)", 50 | "JINA_LOG_LEVEL": "(unset)", 51 | "JINA_LOG_NO_COLOR": "(unset)", 52 | "JINA_MP_START_METHOD": "(unset)", 53 | "JINA_OPTOUT_TELEMETRY": "(unset)", 54 | "JINA_RANDOM_PORT_MAX": "(unset)", 55 | "JINA_RANDOM_PORT_MIN": "(unset)" 56 | } 57 | } 58 | ``` 59 | -------------------------------------------------------------------------------- /examples/info/websocket/flow.yml: -------------------------------------------------------------------------------- 1 | jtype: Flow 2 | with: 3 | protocol: websocket 4 | port: 12345 5 | executors: 6 | - name: e1 7 | -------------------------------------------------------------------------------- /examples/info/websocket/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | 7 | "github.com/jina-ai/client-go" 8 | ) 9 | 10 | func main() { 11 | host := flag.String("host", "", "host of the gateway") 12 | flag.Parse() 13 | 14 | if *host == "" { 15 | panic("Please pass a host to check the health of") 16 | } 17 | infoClient, err := client.NewWebSocketInfoClient(*host) 18 | if err != nil { 19 | panic(fmt.Errorf("unsuccessful info: %w", err)) 20 | } 21 | 22 | info, err := infoClient.InfoJSON() 23 | if err != nil { 24 | panic(fmt.Errorf("failed to check info: %w", err)) 25 | } 26 | fmt.Println(string(info)) 27 | } 28 | -------------------------------------------------------------------------------- /examples/websocket/README.md: -------------------------------------------------------------------------------- 1 | ## Websocket Client 2 | 3 | #### Start a Flow with WebSocket protocol 4 | 5 | ```bash 6 | jina flow --uses flow.yml 7 | ``` 8 | 9 | #### Send `DataRequest`s to the Flow 10 | 11 | ```bash 12 | go run main.go --host ws://localhost:12345 13 | ``` 14 | ```text 15 | Total 3 docs received. 16 | DocID: 0 17 | Chunk 0 text: Hello world. 18 | Chunk 1 text: This is a test document with id:0 19 | DocID: 1 20 | Chunk 0 text: Hello world. 21 | Chunk 1 text: This is a test document with id:1 22 | DocID: 2 23 | Chunk 0 text: Hello world. 24 | Chunk 1 text: This is a test document with id:2 25 | ``` 26 | -------------------------------------------------------------------------------- /examples/websocket/flow.yml: -------------------------------------------------------------------------------- 1 | jtype: Flow 2 | with: 3 | protocol: websocket 4 | port: 12345 5 | env: 6 | JINA_LOG_LEVEL: DEBUG 7 | executors: 8 | - name: sentencizer 9 | uses: jinahub://Sentencizer 10 | -------------------------------------------------------------------------------- /examples/websocket/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | 7 | "github.com/jina-ai/client-go" 8 | "github.com/jina-ai/client-go/docarray" 9 | "github.com/jina-ai/client-go/jina" 10 | ) 11 | 12 | // Create a Document 13 | func getDoc(id string) *docarray.DocumentProto { 14 | return &docarray.DocumentProto{ 15 | Id: id, 16 | Content: &docarray.DocumentProto_Text{ 17 | Text: "Hello world. This is a test document with id:" + id, 18 | }, 19 | } 20 | } 21 | 22 | // Create a DocumentArray with 3 Documents 23 | func getDocarrays(numDocs int) *docarray.DocumentArrayProto { 24 | var docs []*docarray.DocumentProto 25 | for i := 0; i < numDocs; i++ { 26 | docs = append(docs, getDoc(fmt.Sprint(i))) 27 | } 28 | return &docarray.DocumentArrayProto{ 29 | Docs: docs, 30 | } 31 | } 32 | 33 | // Create DataRequest with a DocumentArray 34 | func getDataRequest(numDocs int) *jina.DataRequestProto { 35 | return &jina.DataRequestProto{ 36 | Data: &jina.DataRequestProto_DataContentProto{ 37 | Documents: &jina.DataRequestProto_DataContentProto_Docs{ 38 | Docs: getDocarrays(numDocs), 39 | }, 40 | }, 41 | } 42 | } 43 | 44 | // Generate a stream of requests 45 | func generateDataRequests(numRequests int) <-chan *jina.DataRequestProto { 46 | requests := make(chan *jina.DataRequestProto) 47 | go func() { 48 | for i := 0; i < numRequests; i++ { 49 | requests <- getDataRequest(3) 50 | } 51 | defer close(requests) 52 | }() 53 | return requests 54 | } 55 | 56 | func OnDone(resp *jina.DataRequestProto) { 57 | switch docs := resp.Data.Documents.(type) { 58 | case *jina.DataRequestProto_DataContentProto_Docs: 59 | fmt.Printf("\n\nTotal %d docs received.", len(docs.Docs.Docs)) 60 | for docidx, doc := range docs.Docs.Docs { 61 | fmt.Printf("\nDocID: %d", docidx) 62 | for i, chunk := range doc.Chunks { 63 | fmt.Printf("\n\tChunk %d text: %s ", i, chunk.Content.(*docarray.DocumentProto_Text).Text) 64 | } 65 | } 66 | } 67 | } 68 | 69 | func OnError(resp *jina.DataRequestProto) { 70 | fmt.Println("Got an error for request", resp) 71 | } 72 | 73 | func main() { 74 | host := flag.String("host", "", "host of the gateway") 75 | flag.Parse() 76 | 77 | if *host == "" { 78 | panic("Please pass a host to check the health of") 79 | } 80 | 81 | WSClient, err := client.NewWebSocketClient(*host) 82 | if err != nil { 83 | panic(fmt.Errorf("unsuccessful connection: %w", err)) 84 | } 85 | WSClient.POST(generateDataRequests(5), OnDone, OnError, nil) 86 | } 87 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/jina-ai/client-go 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/gorilla/websocket v1.5.0 7 | github.com/onsi/ginkgo/v2 v2.13.0 8 | github.com/onsi/gomega v1.30.0 9 | github.com/shirou/gopsutil/v3 v3.22.9 10 | github.com/viki-org/dnscache v0.0.0-20130720023526-c70c1f23c5d8 11 | google.golang.org/grpc v1.50.1 12 | google.golang.org/protobuf v1.31.0 13 | ) 14 | 15 | require ( 16 | github.com/go-logr/logr v1.2.4 // indirect 17 | github.com/go-ole/go-ole v1.2.6 // indirect 18 | github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect 19 | github.com/golang/protobuf v1.5.3 // indirect 20 | github.com/google/go-cmp v0.6.0 // indirect 21 | github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect 22 | github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c // indirect 23 | github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect 24 | github.com/tklauser/go-sysconf v0.3.10 // indirect 25 | github.com/tklauser/numcpus v0.5.0 // indirect 26 | github.com/yusufpapurcu/wmi v1.2.2 // indirect 27 | golang.org/x/net v0.17.0 // indirect 28 | golang.org/x/sys v0.13.0 // indirect 29 | golang.org/x/text v0.13.0 // indirect 30 | golang.org/x/tools v0.12.0 // indirect 31 | google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a // indirect 32 | gopkg.in/yaml.v3 v3.0.1 // indirect 33 | ) 34 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= 2 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= 3 | github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= 4 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 5 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 6 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 7 | github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= 8 | github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= 9 | github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= 10 | github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= 11 | github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= 12 | github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= 13 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 14 | github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= 15 | github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 16 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 17 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 18 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 19 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 20 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 21 | github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE= 22 | github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= 23 | github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= 24 | github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 25 | github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= 26 | github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= 27 | github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c h1:VtwQ41oftZwlMnOEbMWQtSEUgU64U4s+GHk7hZK+jtY= 28 | github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c/go.mod h1:JKx41uQRwqlTZabZc+kILPrO/3jlKnQ2Z8b7YiVw5cE= 29 | github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= 30 | github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= 31 | github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= 32 | github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= 33 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 34 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 35 | github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= 36 | github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c h1:NRoLoZvkBTKvR5gQLgA3e0hqjkY9u1wm+iOL45VN/qI= 37 | github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= 38 | github.com/shirou/gopsutil/v3 v3.22.9 h1:yibtJhIVEMcdw+tCTbOPiF1VcsuDeTE4utJ8Dm4c5eA= 39 | github.com/shirou/gopsutil/v3 v3.22.9/go.mod h1:bBYl1kjgEJpWpxeHmLI+dVHWtyAwfcmSBLDsp2TNT8A= 40 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 41 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 42 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 43 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 44 | github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= 45 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 46 | github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw= 47 | github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= 48 | github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= 49 | github.com/tklauser/numcpus v0.5.0 h1:ooe7gN0fg6myJ0EKoTAf5hebTZrH52px3New/D9iJ+A= 50 | github.com/tklauser/numcpus v0.5.0/go.mod h1:OGzpTxpcIMNGYQdit2BYL1pvk/dSOaJWjKoflh+RQjo= 51 | github.com/viki-org/dnscache v0.0.0-20130720023526-c70c1f23c5d8 h1:EVObHAr8DqpoJCVv6KYTle8FEImKhtkfcZetNqxDoJQ= 52 | github.com/viki-org/dnscache v0.0.0-20130720023526-c70c1f23c5d8/go.mod h1:dniwbG03GafCjFohMDmz6Zc6oCuiqgH6tGNyXTkHzXE= 53 | github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= 54 | github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= 55 | golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= 56 | golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= 57 | golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= 58 | golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 59 | golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 60 | golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 61 | golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 62 | golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 63 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 64 | golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= 65 | golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 66 | golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= 67 | golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= 68 | golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss= 69 | golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM= 70 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 71 | google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a h1:GH6UPn3ixhWcKDhpnEC55S75cerLPdpp3hrhfKYjZgw= 72 | google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a/go.mod h1:1vXfmgAz9N9Jx0QA82PqRVauvCz1SGSz739p0f183jM= 73 | google.golang.org/grpc v1.50.1 h1:DS/BukOZWp8s6p4Dt/tOaJaTQyPyOoCcrjroHuCeLzY= 74 | google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= 75 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 76 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 77 | google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= 78 | google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= 79 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 80 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 81 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 82 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 83 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 84 | -------------------------------------------------------------------------------- /grpc.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "context" 5 | "crypto/tls" 6 | "encoding/json" 7 | "fmt" 8 | "strings" 9 | "sync" 10 | 11 | "github.com/jina-ai/client-go/jina" 12 | "google.golang.org/grpc" 13 | "google.golang.org/grpc/credentials" 14 | "google.golang.org/grpc/credentials/insecure" 15 | "google.golang.org/protobuf/types/known/emptypb" 16 | ) 17 | 18 | type GRPCClient struct { 19 | Host string 20 | conn *grpc.ClientConn 21 | rpcClient jina.JinaRPCClient 22 | ctx context.Context 23 | } 24 | 25 | func getSecureDialOptions() grpc.DialOption { 26 | return grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{InsecureSkipVerify: false})) 27 | } 28 | 29 | func getInsecureDialOptions() grpc.DialOption { 30 | return grpc.WithTransportCredentials(insecure.NewCredentials()) 31 | } 32 | 33 | func getHostAndDialOptions(host string) (string, grpc.DialOption) { 34 | if strings.HasPrefix(host, "grpcs://") { 35 | host = strings.TrimPrefix(host, "grpcs://") 36 | return fmt.Sprint(host + ":443"), getSecureDialOptions() 37 | } 38 | if strings.HasPrefix(host, "grpc://") { 39 | host = strings.TrimPrefix(host, "grpc://") 40 | return host, getInsecureDialOptions() 41 | } 42 | return host, getInsecureDialOptions() 43 | } 44 | 45 | func NewGRPCClient(host string) (*GRPCClient, error) { 46 | host, dialOptions := getHostAndDialOptions(host) 47 | conn, err := grpc.Dial(host, dialOptions) 48 | if err != nil { 49 | fmt.Println("Error in grpc dial", err) 50 | return nil, err 51 | } 52 | return &GRPCClient{ 53 | Host: host, 54 | conn: conn, 55 | rpcClient: jina.NewJinaRPCClient(conn), 56 | ctx: context.Background(), 57 | }, nil 58 | } 59 | 60 | func (c GRPCClient) POST(requests <-chan *jina.DataRequestProto, onDone, onError, onAlways CallbackType) error { 61 | var wg sync.WaitGroup 62 | 63 | stream, err := c.rpcClient.Call(c.ctx) 64 | if err != nil { 65 | return err 66 | } 67 | 68 | go func() { 69 | for { 70 | resp, err := stream.Recv() 71 | if resp == nil { 72 | break 73 | } 74 | if err != nil { 75 | fmt.Println("Error in receiving response", err) 76 | if onError != nil { 77 | onError(resp) 78 | } 79 | } else if onDone != nil { 80 | onDone(resp) 81 | } 82 | if onAlways != nil { 83 | onAlways(resp) 84 | } 85 | wg.Done() 86 | } 87 | }() 88 | 89 | for { 90 | req, ok := <-requests 91 | if !ok { 92 | break 93 | } 94 | if err := stream.Send(req); err != nil { 95 | panic(err) 96 | } 97 | wg.Add(1) 98 | } 99 | wg.Wait() 100 | stream.CloseSend() 101 | return nil 102 | } 103 | 104 | func (c GRPCClient) SequentialPOST(requests <-chan *jina.DataRequestProto, onDone, onError, onAlways CallbackType) error { 105 | stream, err := c.rpcClient.Call(c.ctx) 106 | if err != nil { 107 | return err 108 | } 109 | 110 | for { 111 | req, ok := <-requests 112 | if !ok { 113 | break 114 | } 115 | if err := stream.Send(req); err != nil { 116 | panic(err) 117 | } 118 | resp, err := stream.Recv() 119 | if resp == nil { 120 | break 121 | } 122 | if err != nil { 123 | fmt.Println("Error in receiving response", err) 124 | if onError != nil { 125 | onError(resp) 126 | } 127 | } else if onDone != nil { 128 | onDone(resp) 129 | } 130 | if onAlways != nil { 131 | onAlways(resp) 132 | } 133 | } 134 | stream.CloseSend() 135 | return nil 136 | } 137 | 138 | type GRPCHealthCheckClient struct { 139 | Host string 140 | conn *grpc.ClientConn 141 | rpcClient jina.JinaGatewayDryRunRPCClient 142 | ctx context.Context 143 | } 144 | 145 | func NewGRPCHealthCheckClient(host string) (*GRPCHealthCheckClient, error) { 146 | host, dialOptions := getHostAndDialOptions(host) 147 | conn, err := grpc.Dial(host, dialOptions) 148 | if err != nil { 149 | return nil, err 150 | } 151 | return &GRPCHealthCheckClient{ 152 | Host: host, 153 | conn: conn, 154 | rpcClient: jina.NewJinaGatewayDryRunRPCClient(conn), 155 | ctx: context.Background(), 156 | }, nil 157 | } 158 | 159 | func (c *GRPCHealthCheckClient) HealthCheck() (bool, error) { 160 | status, err := c.rpcClient.DryRun(c.ctx, &emptypb.Empty{}) 161 | if err != nil { 162 | return false, err 163 | } 164 | if status.Code == jina.StatusProto_SUCCESS { 165 | return true, nil 166 | } 167 | return false, nil 168 | } 169 | 170 | type GRPCInfoClient struct { 171 | Host string 172 | conn *grpc.ClientConn 173 | rpcClient jina.JinaInfoRPCClient 174 | ctx context.Context 175 | } 176 | 177 | func NewGRPCInfoClient(host string) (*GRPCInfoClient, error) { 178 | host, dialOptions := getHostAndDialOptions(host) 179 | conn, err := grpc.Dial(host, dialOptions) 180 | if err != nil { 181 | return nil, err 182 | } 183 | return &GRPCInfoClient{ 184 | Host: host, 185 | conn: conn, 186 | rpcClient: jina.NewJinaInfoRPCClient(conn), 187 | ctx: context.Background(), 188 | }, nil 189 | } 190 | 191 | func (c *GRPCInfoClient) Info() (*jina.JinaInfoProto, error) { 192 | return c.rpcClient.XStatus(c.ctx, &emptypb.Empty{}) 193 | } 194 | 195 | func (c *GRPCInfoClient) InfoJSON() ([]byte, error) { 196 | info, err := c.Info() 197 | if err != nil { 198 | return nil, err 199 | } 200 | return json.MarshalIndent(info, "", " ") 201 | } 202 | -------------------------------------------------------------------------------- /grpc_test.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "time" 5 | 6 | . "github.com/onsi/ginkgo/v2" 7 | . "github.com/onsi/gomega" 8 | ) 9 | 10 | var _ = Describe("GRPC Client", Ordered, func() { 11 | var c *GRPCClient 12 | var hc *GRPCHealthCheckClient 13 | var err error 14 | 15 | BeforeEach(func() { 16 | cleanUp := startFlow("examples/grpc/flow.yml") 17 | time.Sleep(2 * time.Second) 18 | DeferCleanup(func() { 19 | *c = GRPCClient{} 20 | cleanUp() 21 | }) 22 | }) 23 | 24 | Describe("Create the Client and stream requests", func() { 25 | It("should create a new GRPCClient & stream requests", func() { 26 | Eventually(func() error { 27 | c, err = NewGRPCClient("grpc://localhost:12345") 28 | return err 29 | }, 10*time.Second, 1*time.Second).Should(BeNil()) 30 | Expect(c).NotTo(BeNil()) 31 | c.POST(generateDataRequests(3), OnDone, OnError, nil) 32 | }) 33 | }) 34 | 35 | Describe("Create the Client and stream requests sequentially", func() { 36 | It("should create a new GRPCClient & stream requests", func() { 37 | Eventually(func() error { 38 | c, err = NewGRPCClient("grpc://localhost:12345") 39 | return err 40 | }, 10*time.Second, 1*time.Second).Should(BeNil()) 41 | Expect(c).NotTo(BeNil()) 42 | c.SequentialPOST(generateDataRequests(3), OnDone, OnError, nil) 43 | }) 44 | }) 45 | 46 | Describe("Perform healthchecks on the client", func() { 47 | It("should create a new GRPCHealthCheckClient & perform a successful healthcheck", func() { 48 | Eventually(func() error { 49 | hc, err = NewGRPCHealthCheckClient("grpc://localhost:12345") 50 | return err 51 | }, 10*time.Second, 1*time.Second).Should(BeNil()) 52 | Expect(hc).NotTo(BeNil()) 53 | 54 | Eventually(func() bool { 55 | status, _ := hc.HealthCheck() 56 | return status 57 | }, 10*time.Second, 1*time.Second).Should(BeTrue()) 58 | }) 59 | }) 60 | }) 61 | -------------------------------------------------------------------------------- /http.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "encoding/json" 7 | "fmt" 8 | "io" 9 | "net/http" 10 | "strings" 11 | "sync" 12 | 13 | "github.com/jina-ai/client-go/jina" 14 | ) 15 | 16 | type HTTPClient struct { 17 | Host string 18 | ctx context.Context 19 | } 20 | 21 | func NewHTTPClient(host string) (*HTTPClient, error) { 22 | if !strings.HasSuffix(host, "/post") { 23 | host = host + "/post" 24 | } 25 | return &HTTPClient{ 26 | Host: host, 27 | ctx: context.Background(), 28 | }, nil 29 | } 30 | 31 | func (c HTTPClient) POST(requests <-chan *jina.DataRequestProto, onDone, onError, onAlways CallbackType) error { 32 | var wg sync.WaitGroup 33 | 34 | handleRequest := func(request *jina.DataRequestProto) { 35 | reqJSON, err := json.Marshal(request) 36 | if err != nil { 37 | fmt.Println("error marshalling request", err) 38 | if onError != nil { 39 | onError(request) 40 | } 41 | if onAlways != nil { 42 | onAlways(request) 43 | } 44 | } 45 | 46 | req, err := http.NewRequest("POST", c.Host, bytes.NewBuffer(reqJSON)) 47 | if err != nil { 48 | fmt.Println("error creating request", err) 49 | } 50 | req.Header.Set("Content-Type", "application/json") 51 | 52 | httpResp, err := HttpClient.Do(req) 53 | if err != nil { 54 | fmt.Println("error sending request", err) 55 | if onError != nil { 56 | onError(request) 57 | } 58 | if onAlways != nil { 59 | onAlways(request) 60 | } 61 | } 62 | 63 | if httpResp != nil { 64 | defer httpResp.Body.Close() 65 | 66 | if httpResp.StatusCode != http.StatusOK { 67 | fmt.Println("Got non 200 status code", httpResp.StatusCode) 68 | if onError != nil { 69 | onError(request) 70 | } 71 | if onAlways != nil { 72 | onAlways(request) 73 | } 74 | } 75 | 76 | body, err := io.ReadAll(httpResp.Body) 77 | if err != nil { 78 | fmt.Println("error reading response body", err) 79 | if onError != nil { 80 | onError(request) 81 | } 82 | if onAlways != nil { 83 | onAlways(request) 84 | } 85 | } 86 | 87 | var res jina.DataRequestProto 88 | if err := json.Unmarshal(body, &res); err != nil { 89 | fmt.Println("error unmarshalling response", err) 90 | if onError != nil { 91 | onError(request) 92 | } 93 | if onAlways != nil { 94 | onAlways(request) 95 | } 96 | } else { 97 | if onDone != nil { 98 | onDone(&res) 99 | } 100 | if onAlways != nil { 101 | onAlways(&res) 102 | } 103 | } 104 | } 105 | wg.Done() 106 | } 107 | 108 | for { 109 | req, ok := <-requests 110 | if !ok { 111 | break 112 | } 113 | go handleRequest(req) 114 | wg.Add(1) 115 | } 116 | wg.Wait() 117 | return nil 118 | } 119 | 120 | func (c HTTPClient) SequentialPOST(requests <-chan *jina.DataRequestProto, onDone, onError, onAlways CallbackType) error { 121 | for { 122 | request, ok := <-requests 123 | if !ok { 124 | break 125 | } 126 | 127 | reqJSON, err := json.Marshal(request) 128 | if err != nil { 129 | fmt.Println("error marshalling request", err) 130 | if onError != nil { 131 | onError(request) 132 | } 133 | if onAlways != nil { 134 | onAlways(request) 135 | } 136 | } 137 | 138 | req, err := http.NewRequest("POST", c.Host, bytes.NewBuffer(reqJSON)) 139 | if err != nil { 140 | fmt.Println("error creating request", err) 141 | } 142 | req.Header.Set("Content-Type", "application/json") 143 | 144 | httpResp, err := HttpClient.Do(req) 145 | if err != nil { 146 | fmt.Println("error sending request", err) 147 | if onError != nil { 148 | onError(request) 149 | } 150 | if onAlways != nil { 151 | onAlways(request) 152 | } 153 | } 154 | 155 | if httpResp != nil { 156 | defer httpResp.Body.Close() 157 | 158 | if httpResp.StatusCode != http.StatusOK { 159 | fmt.Println("Got non 200 status code", httpResp.StatusCode) 160 | if onError != nil { 161 | onError(request) 162 | } 163 | if onAlways != nil { 164 | onAlways(request) 165 | } 166 | } 167 | 168 | body, err := io.ReadAll(httpResp.Body) 169 | if err != nil { 170 | fmt.Println("error reading response body", err) 171 | if onError != nil { 172 | onError(request) 173 | } 174 | if onAlways != nil { 175 | onAlways(request) 176 | } 177 | } 178 | 179 | var res jina.DataRequestProto 180 | if err := json.Unmarshal(body, &res); err != nil { 181 | fmt.Println("error unmarshalling response", err) 182 | if onError != nil { 183 | onError(request) 184 | } 185 | if onAlways != nil { 186 | onAlways(request) 187 | } 188 | } else { 189 | if onDone != nil { 190 | onDone(&res) 191 | } 192 | if onAlways != nil { 193 | onAlways(&res) 194 | } 195 | } 196 | } 197 | } 198 | return nil 199 | } 200 | 201 | type HTTPHealthCheckClient struct { 202 | Host string 203 | ctx context.Context 204 | } 205 | 206 | func NewHTTPHealthCheckClient(host string) (*HTTPHealthCheckClient, error) { 207 | if !strings.HasPrefix(host, "http") { 208 | host = "http://" + host 209 | } 210 | 211 | if !strings.HasSuffix(host, "/dry_run") { 212 | host = host + "/dry_run" 213 | } 214 | return &HTTPHealthCheckClient{ 215 | Host: host, 216 | ctx: context.Background(), 217 | }, nil 218 | } 219 | 220 | func (c HTTPHealthCheckClient) HealthCheck() (bool, error) { 221 | req, err := http.NewRequest("GET", c.Host, nil) 222 | if err != nil { 223 | fmt.Println("Failed to create HTTP request", "host", c.Host, "err", err) 224 | return false, err 225 | } 226 | 227 | httpResp, err := HttpClient.Do(req) 228 | if err != nil { 229 | return false, err 230 | } 231 | if httpResp.StatusCode != http.StatusOK { 232 | return false, fmt.Errorf("got non 200 status code %d", httpResp.StatusCode) 233 | } 234 | defer httpResp.Body.Close() 235 | 236 | var resp map[string]interface{} 237 | if err := json.NewDecoder(httpResp.Body).Decode(&resp); err != nil { 238 | return false, fmt.Errorf("error decoding response: %w", err) 239 | } 240 | 241 | code := int(resp["code"].(float64)) 242 | if code != 0 { 243 | return false, fmt.Errorf("got non 0 code %s", resp["description"]) 244 | } else { 245 | return true, nil 246 | } 247 | } 248 | 249 | type HTTPInfoClient struct { 250 | Host string 251 | ctx context.Context 252 | } 253 | 254 | func NewHTTPInfoClient(host string) (HTTPInfoClient, error) { 255 | if !strings.HasPrefix(host, "http") { 256 | host = "http://" + host 257 | } 258 | 259 | if !strings.HasSuffix(host, "/status") { 260 | host = host + "/status" 261 | } 262 | return HTTPInfoClient{ 263 | Host: host, 264 | ctx: context.Background(), 265 | }, nil 266 | } 267 | 268 | func (c HTTPInfoClient) InfoJSON() ([]byte, error) { 269 | req, err := http.NewRequest("GET", c.Host, nil) 270 | if err != nil { 271 | fmt.Println("Failed to create HTTP request", "host", c.Host, "err", err) 272 | return nil, err 273 | } 274 | 275 | httpResp, err := HttpClient.Do(req) 276 | if err != nil { 277 | return nil, err 278 | } 279 | defer httpResp.Body.Close() 280 | if httpResp.StatusCode != http.StatusOK { 281 | return nil, fmt.Errorf("got non 200 status code %d", httpResp.StatusCode) 282 | } 283 | body, err := io.ReadAll(httpResp.Body) 284 | if err != nil { 285 | return nil, err 286 | } 287 | var buf bytes.Buffer 288 | if err := json.Indent(&buf, body, "", " "); err != nil { 289 | return nil, err 290 | } 291 | return buf.Bytes(), nil 292 | } 293 | 294 | func (c HTTPInfoClient) Info() (*jina.JinaInfoProto, error) { 295 | body, err := c.InfoJSON() 296 | if err != nil { 297 | return nil, err 298 | } 299 | 300 | var res jina.JinaInfoProto 301 | if err := json.Unmarshal(body, &res); err != nil { 302 | return nil, err 303 | } 304 | return &res, nil 305 | } 306 | -------------------------------------------------------------------------------- /http_test.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "time" 5 | 6 | . "github.com/onsi/ginkgo/v2" 7 | . "github.com/onsi/gomega" 8 | ) 9 | 10 | var _ = Describe("HTTP Client", Ordered, func() { 11 | var c *HTTPClient 12 | var hc *HTTPHealthCheckClient 13 | var err error 14 | 15 | BeforeEach(func() { 16 | cleanUp := startFlow("examples/http/flow.yml") 17 | time.Sleep(2 * time.Second) 18 | DeferCleanup(func() { 19 | *c = HTTPClient{} 20 | cleanUp() 21 | }) 22 | }) 23 | 24 | Describe("Create the Client and stream requests", func() { 25 | It("should create a new HTTPClient & stream requests", func() { 26 | Eventually(func() error { 27 | c, err = NewHTTPClient("http://localhost:12345") 28 | return err 29 | }, 10*time.Second, 1*time.Second).Should(BeNil()) 30 | Expect(c).NotTo(BeNil()) 31 | c.POST(generateDataRequests(3), OnDone, OnError, nil) 32 | }) 33 | }) 34 | 35 | Describe("Create the Client and stream requests sequentially", func() { 36 | It("should create a new HTTPClient & stream requests", func() { 37 | Eventually(func() error { 38 | c, err = NewHTTPClient("http://localhost:12345") 39 | return err 40 | }, 10*time.Second, 1*time.Second).Should(BeNil()) 41 | Expect(c).NotTo(BeNil()) 42 | c.SequentialPOST(generateDataRequests(3), OnDone, OnError, nil) 43 | }) 44 | }) 45 | 46 | Describe("Perform healthchecks on the client", func() { 47 | It("should create a new HTTPHealthCheckClient & perform a successful healthcheck", func() { 48 | Eventually(func() error { 49 | hc, err = NewHTTPHealthCheckClient("http://localhost:12345") 50 | return err 51 | }, 10*time.Second, 1*time.Second).Should(BeNil()) 52 | Expect(hc).NotTo(BeNil()) 53 | 54 | Eventually(func() bool { 55 | status, _ := hc.HealthCheck() 56 | return status 57 | }, 10*time.Second, 1*time.Second).Should(BeTrue()) 58 | }) 59 | }) 60 | }) 61 | -------------------------------------------------------------------------------- /jina/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.10.0/jina_grpc.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-grpc. DO NOT EDIT. 2 | // versions: 3 | // - protoc-gen-go-grpc v1.2.0 4 | // - protoc v3.21.7 5 | // source: jina.proto 6 | 7 | package jina 8 | 9 | import ( 10 | context "context" 11 | grpc "google.golang.org/grpc" 12 | codes "google.golang.org/grpc/codes" 13 | status "google.golang.org/grpc/status" 14 | emptypb "google.golang.org/protobuf/types/known/emptypb" 15 | ) 16 | 17 | // This is a compile-time assertion to ensure that this generated file 18 | // is compatible with the grpc package it is being compiled against. 19 | // Requires gRPC-Go v1.32.0 or later. 20 | const _ = grpc.SupportPackageIsVersion7 21 | 22 | // JinaDataRequestRPCClient is the client API for JinaDataRequestRPC service. 23 | // 24 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 25 | type JinaDataRequestRPCClient interface { 26 | // Used for passing DataRequests to the Executors 27 | ProcessData(ctx context.Context, in *DataRequestListProto, opts ...grpc.CallOption) (*DataRequestProto, error) 28 | } 29 | 30 | type jinaDataRequestRPCClient struct { 31 | cc grpc.ClientConnInterface 32 | } 33 | 34 | func NewJinaDataRequestRPCClient(cc grpc.ClientConnInterface) JinaDataRequestRPCClient { 35 | return &jinaDataRequestRPCClient{cc} 36 | } 37 | 38 | func (c *jinaDataRequestRPCClient) ProcessData(ctx context.Context, in *DataRequestListProto, opts ...grpc.CallOption) (*DataRequestProto, error) { 39 | out := new(DataRequestProto) 40 | err := c.cc.Invoke(ctx, "/jina.JinaDataRequestRPC/process_data", in, out, opts...) 41 | if err != nil { 42 | return nil, err 43 | } 44 | return out, nil 45 | } 46 | 47 | // JinaDataRequestRPCServer is the server API for JinaDataRequestRPC service. 48 | // All implementations must embed UnimplementedJinaDataRequestRPCServer 49 | // for forward compatibility 50 | type JinaDataRequestRPCServer interface { 51 | // Used for passing DataRequests to the Executors 52 | ProcessData(context.Context, *DataRequestListProto) (*DataRequestProto, error) 53 | mustEmbedUnimplementedJinaDataRequestRPCServer() 54 | } 55 | 56 | // UnimplementedJinaDataRequestRPCServer must be embedded to have forward compatible implementations. 57 | type UnimplementedJinaDataRequestRPCServer struct { 58 | } 59 | 60 | func (UnimplementedJinaDataRequestRPCServer) ProcessData(context.Context, *DataRequestListProto) (*DataRequestProto, error) { 61 | return nil, status.Errorf(codes.Unimplemented, "method ProcessData not implemented") 62 | } 63 | func (UnimplementedJinaDataRequestRPCServer) mustEmbedUnimplementedJinaDataRequestRPCServer() {} 64 | 65 | // UnsafeJinaDataRequestRPCServer may be embedded to opt out of forward compatibility for this service. 66 | // Use of this interface is not recommended, as added methods to JinaDataRequestRPCServer will 67 | // result in compilation errors. 68 | type UnsafeJinaDataRequestRPCServer interface { 69 | mustEmbedUnimplementedJinaDataRequestRPCServer() 70 | } 71 | 72 | func RegisterJinaDataRequestRPCServer(s grpc.ServiceRegistrar, srv JinaDataRequestRPCServer) { 73 | s.RegisterService(&JinaDataRequestRPC_ServiceDesc, srv) 74 | } 75 | 76 | func _JinaDataRequestRPC_ProcessData_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 77 | in := new(DataRequestListProto) 78 | if err := dec(in); err != nil { 79 | return nil, err 80 | } 81 | if interceptor == nil { 82 | return srv.(JinaDataRequestRPCServer).ProcessData(ctx, in) 83 | } 84 | info := &grpc.UnaryServerInfo{ 85 | Server: srv, 86 | FullMethod: "/jina.JinaDataRequestRPC/process_data", 87 | } 88 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 89 | return srv.(JinaDataRequestRPCServer).ProcessData(ctx, req.(*DataRequestListProto)) 90 | } 91 | return interceptor(ctx, in, info, handler) 92 | } 93 | 94 | // JinaDataRequestRPC_ServiceDesc is the grpc.ServiceDesc for JinaDataRequestRPC service. 95 | // It's only intended for direct use with grpc.RegisterService, 96 | // and not to be introspected or modified (even as a copy) 97 | var JinaDataRequestRPC_ServiceDesc = grpc.ServiceDesc{ 98 | ServiceName: "jina.JinaDataRequestRPC", 99 | HandlerType: (*JinaDataRequestRPCServer)(nil), 100 | Methods: []grpc.MethodDesc{ 101 | { 102 | MethodName: "process_data", 103 | Handler: _JinaDataRequestRPC_ProcessData_Handler, 104 | }, 105 | }, 106 | Streams: []grpc.StreamDesc{}, 107 | Metadata: "jina.proto", 108 | } 109 | 110 | // JinaSingleDataRequestRPCClient is the client API for JinaSingleDataRequestRPC service. 111 | // 112 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 113 | type JinaSingleDataRequestRPCClient interface { 114 | // Used for passing DataRequests to the Executors 115 | ProcessSingleData(ctx context.Context, in *DataRequestProto, opts ...grpc.CallOption) (*DataRequestProto, error) 116 | } 117 | 118 | type jinaSingleDataRequestRPCClient struct { 119 | cc grpc.ClientConnInterface 120 | } 121 | 122 | func NewJinaSingleDataRequestRPCClient(cc grpc.ClientConnInterface) JinaSingleDataRequestRPCClient { 123 | return &jinaSingleDataRequestRPCClient{cc} 124 | } 125 | 126 | func (c *jinaSingleDataRequestRPCClient) ProcessSingleData(ctx context.Context, in *DataRequestProto, opts ...grpc.CallOption) (*DataRequestProto, error) { 127 | out := new(DataRequestProto) 128 | err := c.cc.Invoke(ctx, "/jina.JinaSingleDataRequestRPC/process_single_data", in, out, opts...) 129 | if err != nil { 130 | return nil, err 131 | } 132 | return out, nil 133 | } 134 | 135 | // JinaSingleDataRequestRPCServer is the server API for JinaSingleDataRequestRPC service. 136 | // All implementations must embed UnimplementedJinaSingleDataRequestRPCServer 137 | // for forward compatibility 138 | type JinaSingleDataRequestRPCServer interface { 139 | // Used for passing DataRequests to the Executors 140 | ProcessSingleData(context.Context, *DataRequestProto) (*DataRequestProto, error) 141 | mustEmbedUnimplementedJinaSingleDataRequestRPCServer() 142 | } 143 | 144 | // UnimplementedJinaSingleDataRequestRPCServer must be embedded to have forward compatible implementations. 145 | type UnimplementedJinaSingleDataRequestRPCServer struct { 146 | } 147 | 148 | func (UnimplementedJinaSingleDataRequestRPCServer) ProcessSingleData(context.Context, *DataRequestProto) (*DataRequestProto, error) { 149 | return nil, status.Errorf(codes.Unimplemented, "method ProcessSingleData not implemented") 150 | } 151 | func (UnimplementedJinaSingleDataRequestRPCServer) mustEmbedUnimplementedJinaSingleDataRequestRPCServer() { 152 | } 153 | 154 | // UnsafeJinaSingleDataRequestRPCServer may be embedded to opt out of forward compatibility for this service. 155 | // Use of this interface is not recommended, as added methods to JinaSingleDataRequestRPCServer will 156 | // result in compilation errors. 157 | type UnsafeJinaSingleDataRequestRPCServer interface { 158 | mustEmbedUnimplementedJinaSingleDataRequestRPCServer() 159 | } 160 | 161 | func RegisterJinaSingleDataRequestRPCServer(s grpc.ServiceRegistrar, srv JinaSingleDataRequestRPCServer) { 162 | s.RegisterService(&JinaSingleDataRequestRPC_ServiceDesc, srv) 163 | } 164 | 165 | func _JinaSingleDataRequestRPC_ProcessSingleData_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 166 | in := new(DataRequestProto) 167 | if err := dec(in); err != nil { 168 | return nil, err 169 | } 170 | if interceptor == nil { 171 | return srv.(JinaSingleDataRequestRPCServer).ProcessSingleData(ctx, in) 172 | } 173 | info := &grpc.UnaryServerInfo{ 174 | Server: srv, 175 | FullMethod: "/jina.JinaSingleDataRequestRPC/process_single_data", 176 | } 177 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 178 | return srv.(JinaSingleDataRequestRPCServer).ProcessSingleData(ctx, req.(*DataRequestProto)) 179 | } 180 | return interceptor(ctx, in, info, handler) 181 | } 182 | 183 | // JinaSingleDataRequestRPC_ServiceDesc is the grpc.ServiceDesc for JinaSingleDataRequestRPC service. 184 | // It's only intended for direct use with grpc.RegisterService, 185 | // and not to be introspected or modified (even as a copy) 186 | var JinaSingleDataRequestRPC_ServiceDesc = grpc.ServiceDesc{ 187 | ServiceName: "jina.JinaSingleDataRequestRPC", 188 | HandlerType: (*JinaSingleDataRequestRPCServer)(nil), 189 | Methods: []grpc.MethodDesc{ 190 | { 191 | MethodName: "process_single_data", 192 | Handler: _JinaSingleDataRequestRPC_ProcessSingleData_Handler, 193 | }, 194 | }, 195 | Streams: []grpc.StreamDesc{}, 196 | Metadata: "jina.proto", 197 | } 198 | 199 | // JinaRPCClient is the client API for JinaRPC service. 200 | // 201 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 202 | type JinaRPCClient interface { 203 | // Pass in a Request and a filled Request with matches will be returned. 204 | Call(ctx context.Context, opts ...grpc.CallOption) (JinaRPC_CallClient, error) 205 | } 206 | 207 | type jinaRPCClient struct { 208 | cc grpc.ClientConnInterface 209 | } 210 | 211 | func NewJinaRPCClient(cc grpc.ClientConnInterface) JinaRPCClient { 212 | return &jinaRPCClient{cc} 213 | } 214 | 215 | func (c *jinaRPCClient) Call(ctx context.Context, opts ...grpc.CallOption) (JinaRPC_CallClient, error) { 216 | stream, err := c.cc.NewStream(ctx, &JinaRPC_ServiceDesc.Streams[0], "/jina.JinaRPC/Call", opts...) 217 | if err != nil { 218 | return nil, err 219 | } 220 | x := &jinaRPCCallClient{stream} 221 | return x, nil 222 | } 223 | 224 | type JinaRPC_CallClient interface { 225 | Send(*DataRequestProto) error 226 | Recv() (*DataRequestProto, error) 227 | grpc.ClientStream 228 | } 229 | 230 | type jinaRPCCallClient struct { 231 | grpc.ClientStream 232 | } 233 | 234 | func (x *jinaRPCCallClient) Send(m *DataRequestProto) error { 235 | return x.ClientStream.SendMsg(m) 236 | } 237 | 238 | func (x *jinaRPCCallClient) Recv() (*DataRequestProto, error) { 239 | m := new(DataRequestProto) 240 | if err := x.ClientStream.RecvMsg(m); err != nil { 241 | return nil, err 242 | } 243 | return m, nil 244 | } 245 | 246 | // JinaRPCServer is the server API for JinaRPC service. 247 | // All implementations must embed UnimplementedJinaRPCServer 248 | // for forward compatibility 249 | type JinaRPCServer interface { 250 | // Pass in a Request and a filled Request with matches will be returned. 251 | Call(JinaRPC_CallServer) error 252 | mustEmbedUnimplementedJinaRPCServer() 253 | } 254 | 255 | // UnimplementedJinaRPCServer must be embedded to have forward compatible implementations. 256 | type UnimplementedJinaRPCServer struct { 257 | } 258 | 259 | func (UnimplementedJinaRPCServer) Call(JinaRPC_CallServer) error { 260 | return status.Errorf(codes.Unimplemented, "method Call not implemented") 261 | } 262 | func (UnimplementedJinaRPCServer) mustEmbedUnimplementedJinaRPCServer() {} 263 | 264 | // UnsafeJinaRPCServer may be embedded to opt out of forward compatibility for this service. 265 | // Use of this interface is not recommended, as added methods to JinaRPCServer will 266 | // result in compilation errors. 267 | type UnsafeJinaRPCServer interface { 268 | mustEmbedUnimplementedJinaRPCServer() 269 | } 270 | 271 | func RegisterJinaRPCServer(s grpc.ServiceRegistrar, srv JinaRPCServer) { 272 | s.RegisterService(&JinaRPC_ServiceDesc, srv) 273 | } 274 | 275 | func _JinaRPC_Call_Handler(srv interface{}, stream grpc.ServerStream) error { 276 | return srv.(JinaRPCServer).Call(&jinaRPCCallServer{stream}) 277 | } 278 | 279 | type JinaRPC_CallServer interface { 280 | Send(*DataRequestProto) error 281 | Recv() (*DataRequestProto, error) 282 | grpc.ServerStream 283 | } 284 | 285 | type jinaRPCCallServer struct { 286 | grpc.ServerStream 287 | } 288 | 289 | func (x *jinaRPCCallServer) Send(m *DataRequestProto) error { 290 | return x.ServerStream.SendMsg(m) 291 | } 292 | 293 | func (x *jinaRPCCallServer) Recv() (*DataRequestProto, error) { 294 | m := new(DataRequestProto) 295 | if err := x.ServerStream.RecvMsg(m); err != nil { 296 | return nil, err 297 | } 298 | return m, nil 299 | } 300 | 301 | // JinaRPC_ServiceDesc is the grpc.ServiceDesc for JinaRPC service. 302 | // It's only intended for direct use with grpc.RegisterService, 303 | // and not to be introspected or modified (even as a copy) 304 | var JinaRPC_ServiceDesc = grpc.ServiceDesc{ 305 | ServiceName: "jina.JinaRPC", 306 | HandlerType: (*JinaRPCServer)(nil), 307 | Methods: []grpc.MethodDesc{}, 308 | Streams: []grpc.StreamDesc{ 309 | { 310 | StreamName: "Call", 311 | Handler: _JinaRPC_Call_Handler, 312 | ServerStreams: true, 313 | ClientStreams: true, 314 | }, 315 | }, 316 | Metadata: "jina.proto", 317 | } 318 | 319 | // JinaDiscoverEndpointsRPCClient is the client API for JinaDiscoverEndpointsRPC service. 320 | // 321 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 322 | type JinaDiscoverEndpointsRPCClient interface { 323 | EndpointDiscovery(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*EndpointsProto, error) 324 | } 325 | 326 | type jinaDiscoverEndpointsRPCClient struct { 327 | cc grpc.ClientConnInterface 328 | } 329 | 330 | func NewJinaDiscoverEndpointsRPCClient(cc grpc.ClientConnInterface) JinaDiscoverEndpointsRPCClient { 331 | return &jinaDiscoverEndpointsRPCClient{cc} 332 | } 333 | 334 | func (c *jinaDiscoverEndpointsRPCClient) EndpointDiscovery(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*EndpointsProto, error) { 335 | out := new(EndpointsProto) 336 | err := c.cc.Invoke(ctx, "/jina.JinaDiscoverEndpointsRPC/endpoint_discovery", in, out, opts...) 337 | if err != nil { 338 | return nil, err 339 | } 340 | return out, nil 341 | } 342 | 343 | // JinaDiscoverEndpointsRPCServer is the server API for JinaDiscoverEndpointsRPC service. 344 | // All implementations must embed UnimplementedJinaDiscoverEndpointsRPCServer 345 | // for forward compatibility 346 | type JinaDiscoverEndpointsRPCServer interface { 347 | EndpointDiscovery(context.Context, *emptypb.Empty) (*EndpointsProto, error) 348 | mustEmbedUnimplementedJinaDiscoverEndpointsRPCServer() 349 | } 350 | 351 | // UnimplementedJinaDiscoverEndpointsRPCServer must be embedded to have forward compatible implementations. 352 | type UnimplementedJinaDiscoverEndpointsRPCServer struct { 353 | } 354 | 355 | func (UnimplementedJinaDiscoverEndpointsRPCServer) EndpointDiscovery(context.Context, *emptypb.Empty) (*EndpointsProto, error) { 356 | return nil, status.Errorf(codes.Unimplemented, "method EndpointDiscovery not implemented") 357 | } 358 | func (UnimplementedJinaDiscoverEndpointsRPCServer) mustEmbedUnimplementedJinaDiscoverEndpointsRPCServer() { 359 | } 360 | 361 | // UnsafeJinaDiscoverEndpointsRPCServer may be embedded to opt out of forward compatibility for this service. 362 | // Use of this interface is not recommended, as added methods to JinaDiscoverEndpointsRPCServer will 363 | // result in compilation errors. 364 | type UnsafeJinaDiscoverEndpointsRPCServer interface { 365 | mustEmbedUnimplementedJinaDiscoverEndpointsRPCServer() 366 | } 367 | 368 | func RegisterJinaDiscoverEndpointsRPCServer(s grpc.ServiceRegistrar, srv JinaDiscoverEndpointsRPCServer) { 369 | s.RegisterService(&JinaDiscoverEndpointsRPC_ServiceDesc, srv) 370 | } 371 | 372 | func _JinaDiscoverEndpointsRPC_EndpointDiscovery_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 373 | in := new(emptypb.Empty) 374 | if err := dec(in); err != nil { 375 | return nil, err 376 | } 377 | if interceptor == nil { 378 | return srv.(JinaDiscoverEndpointsRPCServer).EndpointDiscovery(ctx, in) 379 | } 380 | info := &grpc.UnaryServerInfo{ 381 | Server: srv, 382 | FullMethod: "/jina.JinaDiscoverEndpointsRPC/endpoint_discovery", 383 | } 384 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 385 | return srv.(JinaDiscoverEndpointsRPCServer).EndpointDiscovery(ctx, req.(*emptypb.Empty)) 386 | } 387 | return interceptor(ctx, in, info, handler) 388 | } 389 | 390 | // JinaDiscoverEndpointsRPC_ServiceDesc is the grpc.ServiceDesc for JinaDiscoverEndpointsRPC service. 391 | // It's only intended for direct use with grpc.RegisterService, 392 | // and not to be introspected or modified (even as a copy) 393 | var JinaDiscoverEndpointsRPC_ServiceDesc = grpc.ServiceDesc{ 394 | ServiceName: "jina.JinaDiscoverEndpointsRPC", 395 | HandlerType: (*JinaDiscoverEndpointsRPCServer)(nil), 396 | Methods: []grpc.MethodDesc{ 397 | { 398 | MethodName: "endpoint_discovery", 399 | Handler: _JinaDiscoverEndpointsRPC_EndpointDiscovery_Handler, 400 | }, 401 | }, 402 | Streams: []grpc.StreamDesc{}, 403 | Metadata: "jina.proto", 404 | } 405 | 406 | // JinaGatewayDryRunRPCClient is the client API for JinaGatewayDryRunRPC service. 407 | // 408 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 409 | type JinaGatewayDryRunRPCClient interface { 410 | DryRun(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*StatusProto, error) 411 | } 412 | 413 | type jinaGatewayDryRunRPCClient struct { 414 | cc grpc.ClientConnInterface 415 | } 416 | 417 | func NewJinaGatewayDryRunRPCClient(cc grpc.ClientConnInterface) JinaGatewayDryRunRPCClient { 418 | return &jinaGatewayDryRunRPCClient{cc} 419 | } 420 | 421 | func (c *jinaGatewayDryRunRPCClient) DryRun(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*StatusProto, error) { 422 | out := new(StatusProto) 423 | err := c.cc.Invoke(ctx, "/jina.JinaGatewayDryRunRPC/dry_run", in, out, opts...) 424 | if err != nil { 425 | return nil, err 426 | } 427 | return out, nil 428 | } 429 | 430 | // JinaGatewayDryRunRPCServer is the server API for JinaGatewayDryRunRPC service. 431 | // All implementations must embed UnimplementedJinaGatewayDryRunRPCServer 432 | // for forward compatibility 433 | type JinaGatewayDryRunRPCServer interface { 434 | DryRun(context.Context, *emptypb.Empty) (*StatusProto, error) 435 | mustEmbedUnimplementedJinaGatewayDryRunRPCServer() 436 | } 437 | 438 | // UnimplementedJinaGatewayDryRunRPCServer must be embedded to have forward compatible implementations. 439 | type UnimplementedJinaGatewayDryRunRPCServer struct { 440 | } 441 | 442 | func (UnimplementedJinaGatewayDryRunRPCServer) DryRun(context.Context, *emptypb.Empty) (*StatusProto, error) { 443 | return nil, status.Errorf(codes.Unimplemented, "method DryRun not implemented") 444 | } 445 | func (UnimplementedJinaGatewayDryRunRPCServer) mustEmbedUnimplementedJinaGatewayDryRunRPCServer() {} 446 | 447 | // UnsafeJinaGatewayDryRunRPCServer may be embedded to opt out of forward compatibility for this service. 448 | // Use of this interface is not recommended, as added methods to JinaGatewayDryRunRPCServer will 449 | // result in compilation errors. 450 | type UnsafeJinaGatewayDryRunRPCServer interface { 451 | mustEmbedUnimplementedJinaGatewayDryRunRPCServer() 452 | } 453 | 454 | func RegisterJinaGatewayDryRunRPCServer(s grpc.ServiceRegistrar, srv JinaGatewayDryRunRPCServer) { 455 | s.RegisterService(&JinaGatewayDryRunRPC_ServiceDesc, srv) 456 | } 457 | 458 | func _JinaGatewayDryRunRPC_DryRun_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 459 | in := new(emptypb.Empty) 460 | if err := dec(in); err != nil { 461 | return nil, err 462 | } 463 | if interceptor == nil { 464 | return srv.(JinaGatewayDryRunRPCServer).DryRun(ctx, in) 465 | } 466 | info := &grpc.UnaryServerInfo{ 467 | Server: srv, 468 | FullMethod: "/jina.JinaGatewayDryRunRPC/dry_run", 469 | } 470 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 471 | return srv.(JinaGatewayDryRunRPCServer).DryRun(ctx, req.(*emptypb.Empty)) 472 | } 473 | return interceptor(ctx, in, info, handler) 474 | } 475 | 476 | // JinaGatewayDryRunRPC_ServiceDesc is the grpc.ServiceDesc for JinaGatewayDryRunRPC service. 477 | // It's only intended for direct use with grpc.RegisterService, 478 | // and not to be introspected or modified (even as a copy) 479 | var JinaGatewayDryRunRPC_ServiceDesc = grpc.ServiceDesc{ 480 | ServiceName: "jina.JinaGatewayDryRunRPC", 481 | HandlerType: (*JinaGatewayDryRunRPCServer)(nil), 482 | Methods: []grpc.MethodDesc{ 483 | { 484 | MethodName: "dry_run", 485 | Handler: _JinaGatewayDryRunRPC_DryRun_Handler, 486 | }, 487 | }, 488 | Streams: []grpc.StreamDesc{}, 489 | Metadata: "jina.proto", 490 | } 491 | 492 | // JinaInfoRPCClient is the client API for JinaInfoRPC service. 493 | // 494 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 495 | type JinaInfoRPCClient interface { 496 | XStatus(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*JinaInfoProto, error) 497 | } 498 | 499 | type jinaInfoRPCClient struct { 500 | cc grpc.ClientConnInterface 501 | } 502 | 503 | func NewJinaInfoRPCClient(cc grpc.ClientConnInterface) JinaInfoRPCClient { 504 | return &jinaInfoRPCClient{cc} 505 | } 506 | 507 | func (c *jinaInfoRPCClient) XStatus(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*JinaInfoProto, error) { 508 | out := new(JinaInfoProto) 509 | err := c.cc.Invoke(ctx, "/jina.JinaInfoRPC/_status", in, out, opts...) 510 | if err != nil { 511 | return nil, err 512 | } 513 | return out, nil 514 | } 515 | 516 | // JinaInfoRPCServer is the server API for JinaInfoRPC service. 517 | // All implementations must embed UnimplementedJinaInfoRPCServer 518 | // for forward compatibility 519 | type JinaInfoRPCServer interface { 520 | XStatus(context.Context, *emptypb.Empty) (*JinaInfoProto, error) 521 | mustEmbedUnimplementedJinaInfoRPCServer() 522 | } 523 | 524 | // UnimplementedJinaInfoRPCServer must be embedded to have forward compatible implementations. 525 | type UnimplementedJinaInfoRPCServer struct { 526 | } 527 | 528 | func (UnimplementedJinaInfoRPCServer) XStatus(context.Context, *emptypb.Empty) (*JinaInfoProto, error) { 529 | return nil, status.Errorf(codes.Unimplemented, "method XStatus not implemented") 530 | } 531 | func (UnimplementedJinaInfoRPCServer) mustEmbedUnimplementedJinaInfoRPCServer() {} 532 | 533 | // UnsafeJinaInfoRPCServer may be embedded to opt out of forward compatibility for this service. 534 | // Use of this interface is not recommended, as added methods to JinaInfoRPCServer will 535 | // result in compilation errors. 536 | type UnsafeJinaInfoRPCServer interface { 537 | mustEmbedUnimplementedJinaInfoRPCServer() 538 | } 539 | 540 | func RegisterJinaInfoRPCServer(s grpc.ServiceRegistrar, srv JinaInfoRPCServer) { 541 | s.RegisterService(&JinaInfoRPC_ServiceDesc, srv) 542 | } 543 | 544 | func _JinaInfoRPC_XStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 545 | in := new(emptypb.Empty) 546 | if err := dec(in); err != nil { 547 | return nil, err 548 | } 549 | if interceptor == nil { 550 | return srv.(JinaInfoRPCServer).XStatus(ctx, in) 551 | } 552 | info := &grpc.UnaryServerInfo{ 553 | Server: srv, 554 | FullMethod: "/jina.JinaInfoRPC/_status", 555 | } 556 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 557 | return srv.(JinaInfoRPCServer).XStatus(ctx, req.(*emptypb.Empty)) 558 | } 559 | return interceptor(ctx, in, info, handler) 560 | } 561 | 562 | // JinaInfoRPC_ServiceDesc is the grpc.ServiceDesc for JinaInfoRPC service. 563 | // It's only intended for direct use with grpc.RegisterService, 564 | // and not to be introspected or modified (even as a copy) 565 | var JinaInfoRPC_ServiceDesc = grpc.ServiceDesc{ 566 | ServiceName: "jina.JinaInfoRPC", 567 | HandlerType: (*JinaInfoRPCServer)(nil), 568 | Methods: []grpc.MethodDesc{ 569 | { 570 | MethodName: "_status", 571 | Handler: _JinaInfoRPC_XStatus_Handler, 572 | }, 573 | }, 574 | Streams: []grpc.StreamDesc{}, 575 | Metadata: "jina.proto", 576 | } 577 | -------------------------------------------------------------------------------- /jina/v3.10.0/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.11.0/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.11.2/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.12.0/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.13.0/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.13.1/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.13.2/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.14.0/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.14.1/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.18.0/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.19.1/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.20.1/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.20.2/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.21.1/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.22.0/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.22.1/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.22.2/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.22.4/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.23.0/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.23.1/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /jina/v3.9.0/jina_grpc.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-grpc. DO NOT EDIT. 2 | // versions: 3 | // - protoc-gen-go-grpc v1.2.0 4 | // - protoc v3.21.7 5 | // source: jina.proto 6 | 7 | package jina 8 | 9 | import ( 10 | context "context" 11 | grpc "google.golang.org/grpc" 12 | codes "google.golang.org/grpc/codes" 13 | status "google.golang.org/grpc/status" 14 | emptypb "google.golang.org/protobuf/types/known/emptypb" 15 | ) 16 | 17 | // This is a compile-time assertion to ensure that this generated file 18 | // is compatible with the grpc package it is being compiled against. 19 | // Requires gRPC-Go v1.32.0 or later. 20 | const _ = grpc.SupportPackageIsVersion7 21 | 22 | // JinaDataRequestRPCClient is the client API for JinaDataRequestRPC service. 23 | // 24 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 25 | type JinaDataRequestRPCClient interface { 26 | // Used for passing DataRequests to the Executors 27 | ProcessData(ctx context.Context, in *DataRequestListProto, opts ...grpc.CallOption) (*DataRequestProto, error) 28 | } 29 | 30 | type jinaDataRequestRPCClient struct { 31 | cc grpc.ClientConnInterface 32 | } 33 | 34 | func NewJinaDataRequestRPCClient(cc grpc.ClientConnInterface) JinaDataRequestRPCClient { 35 | return &jinaDataRequestRPCClient{cc} 36 | } 37 | 38 | func (c *jinaDataRequestRPCClient) ProcessData(ctx context.Context, in *DataRequestListProto, opts ...grpc.CallOption) (*DataRequestProto, error) { 39 | out := new(DataRequestProto) 40 | err := c.cc.Invoke(ctx, "/jina.JinaDataRequestRPC/process_data", in, out, opts...) 41 | if err != nil { 42 | return nil, err 43 | } 44 | return out, nil 45 | } 46 | 47 | // JinaDataRequestRPCServer is the server API for JinaDataRequestRPC service. 48 | // All implementations must embed UnimplementedJinaDataRequestRPCServer 49 | // for forward compatibility 50 | type JinaDataRequestRPCServer interface { 51 | // Used for passing DataRequests to the Executors 52 | ProcessData(context.Context, *DataRequestListProto) (*DataRequestProto, error) 53 | mustEmbedUnimplementedJinaDataRequestRPCServer() 54 | } 55 | 56 | // UnimplementedJinaDataRequestRPCServer must be embedded to have forward compatible implementations. 57 | type UnimplementedJinaDataRequestRPCServer struct { 58 | } 59 | 60 | func (UnimplementedJinaDataRequestRPCServer) ProcessData(context.Context, *DataRequestListProto) (*DataRequestProto, error) { 61 | return nil, status.Errorf(codes.Unimplemented, "method ProcessData not implemented") 62 | } 63 | func (UnimplementedJinaDataRequestRPCServer) mustEmbedUnimplementedJinaDataRequestRPCServer() {} 64 | 65 | // UnsafeJinaDataRequestRPCServer may be embedded to opt out of forward compatibility for this service. 66 | // Use of this interface is not recommended, as added methods to JinaDataRequestRPCServer will 67 | // result in compilation errors. 68 | type UnsafeJinaDataRequestRPCServer interface { 69 | mustEmbedUnimplementedJinaDataRequestRPCServer() 70 | } 71 | 72 | func RegisterJinaDataRequestRPCServer(s grpc.ServiceRegistrar, srv JinaDataRequestRPCServer) { 73 | s.RegisterService(&JinaDataRequestRPC_ServiceDesc, srv) 74 | } 75 | 76 | func _JinaDataRequestRPC_ProcessData_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 77 | in := new(DataRequestListProto) 78 | if err := dec(in); err != nil { 79 | return nil, err 80 | } 81 | if interceptor == nil { 82 | return srv.(JinaDataRequestRPCServer).ProcessData(ctx, in) 83 | } 84 | info := &grpc.UnaryServerInfo{ 85 | Server: srv, 86 | FullMethod: "/jina.JinaDataRequestRPC/process_data", 87 | } 88 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 89 | return srv.(JinaDataRequestRPCServer).ProcessData(ctx, req.(*DataRequestListProto)) 90 | } 91 | return interceptor(ctx, in, info, handler) 92 | } 93 | 94 | // JinaDataRequestRPC_ServiceDesc is the grpc.ServiceDesc for JinaDataRequestRPC service. 95 | // It's only intended for direct use with grpc.RegisterService, 96 | // and not to be introspected or modified (even as a copy) 97 | var JinaDataRequestRPC_ServiceDesc = grpc.ServiceDesc{ 98 | ServiceName: "jina.JinaDataRequestRPC", 99 | HandlerType: (*JinaDataRequestRPCServer)(nil), 100 | Methods: []grpc.MethodDesc{ 101 | { 102 | MethodName: "process_data", 103 | Handler: _JinaDataRequestRPC_ProcessData_Handler, 104 | }, 105 | }, 106 | Streams: []grpc.StreamDesc{}, 107 | Metadata: "jina.proto", 108 | } 109 | 110 | // JinaSingleDataRequestRPCClient is the client API for JinaSingleDataRequestRPC service. 111 | // 112 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 113 | type JinaSingleDataRequestRPCClient interface { 114 | // Used for passing DataRequests to the Executors 115 | ProcessSingleData(ctx context.Context, in *DataRequestProto, opts ...grpc.CallOption) (*DataRequestProto, error) 116 | } 117 | 118 | type jinaSingleDataRequestRPCClient struct { 119 | cc grpc.ClientConnInterface 120 | } 121 | 122 | func NewJinaSingleDataRequestRPCClient(cc grpc.ClientConnInterface) JinaSingleDataRequestRPCClient { 123 | return &jinaSingleDataRequestRPCClient{cc} 124 | } 125 | 126 | func (c *jinaSingleDataRequestRPCClient) ProcessSingleData(ctx context.Context, in *DataRequestProto, opts ...grpc.CallOption) (*DataRequestProto, error) { 127 | out := new(DataRequestProto) 128 | err := c.cc.Invoke(ctx, "/jina.JinaSingleDataRequestRPC/process_single_data", in, out, opts...) 129 | if err != nil { 130 | return nil, err 131 | } 132 | return out, nil 133 | } 134 | 135 | // JinaSingleDataRequestRPCServer is the server API for JinaSingleDataRequestRPC service. 136 | // All implementations must embed UnimplementedJinaSingleDataRequestRPCServer 137 | // for forward compatibility 138 | type JinaSingleDataRequestRPCServer interface { 139 | // Used for passing DataRequests to the Executors 140 | ProcessSingleData(context.Context, *DataRequestProto) (*DataRequestProto, error) 141 | mustEmbedUnimplementedJinaSingleDataRequestRPCServer() 142 | } 143 | 144 | // UnimplementedJinaSingleDataRequestRPCServer must be embedded to have forward compatible implementations. 145 | type UnimplementedJinaSingleDataRequestRPCServer struct { 146 | } 147 | 148 | func (UnimplementedJinaSingleDataRequestRPCServer) ProcessSingleData(context.Context, *DataRequestProto) (*DataRequestProto, error) { 149 | return nil, status.Errorf(codes.Unimplemented, "method ProcessSingleData not implemented") 150 | } 151 | func (UnimplementedJinaSingleDataRequestRPCServer) mustEmbedUnimplementedJinaSingleDataRequestRPCServer() { 152 | } 153 | 154 | // UnsafeJinaSingleDataRequestRPCServer may be embedded to opt out of forward compatibility for this service. 155 | // Use of this interface is not recommended, as added methods to JinaSingleDataRequestRPCServer will 156 | // result in compilation errors. 157 | type UnsafeJinaSingleDataRequestRPCServer interface { 158 | mustEmbedUnimplementedJinaSingleDataRequestRPCServer() 159 | } 160 | 161 | func RegisterJinaSingleDataRequestRPCServer(s grpc.ServiceRegistrar, srv JinaSingleDataRequestRPCServer) { 162 | s.RegisterService(&JinaSingleDataRequestRPC_ServiceDesc, srv) 163 | } 164 | 165 | func _JinaSingleDataRequestRPC_ProcessSingleData_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 166 | in := new(DataRequestProto) 167 | if err := dec(in); err != nil { 168 | return nil, err 169 | } 170 | if interceptor == nil { 171 | return srv.(JinaSingleDataRequestRPCServer).ProcessSingleData(ctx, in) 172 | } 173 | info := &grpc.UnaryServerInfo{ 174 | Server: srv, 175 | FullMethod: "/jina.JinaSingleDataRequestRPC/process_single_data", 176 | } 177 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 178 | return srv.(JinaSingleDataRequestRPCServer).ProcessSingleData(ctx, req.(*DataRequestProto)) 179 | } 180 | return interceptor(ctx, in, info, handler) 181 | } 182 | 183 | // JinaSingleDataRequestRPC_ServiceDesc is the grpc.ServiceDesc for JinaSingleDataRequestRPC service. 184 | // It's only intended for direct use with grpc.RegisterService, 185 | // and not to be introspected or modified (even as a copy) 186 | var JinaSingleDataRequestRPC_ServiceDesc = grpc.ServiceDesc{ 187 | ServiceName: "jina.JinaSingleDataRequestRPC", 188 | HandlerType: (*JinaSingleDataRequestRPCServer)(nil), 189 | Methods: []grpc.MethodDesc{ 190 | { 191 | MethodName: "process_single_data", 192 | Handler: _JinaSingleDataRequestRPC_ProcessSingleData_Handler, 193 | }, 194 | }, 195 | Streams: []grpc.StreamDesc{}, 196 | Metadata: "jina.proto", 197 | } 198 | 199 | // JinaRPCClient is the client API for JinaRPC service. 200 | // 201 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 202 | type JinaRPCClient interface { 203 | // Pass in a Request and a filled Request with matches will be returned. 204 | Call(ctx context.Context, opts ...grpc.CallOption) (JinaRPC_CallClient, error) 205 | } 206 | 207 | type jinaRPCClient struct { 208 | cc grpc.ClientConnInterface 209 | } 210 | 211 | func NewJinaRPCClient(cc grpc.ClientConnInterface) JinaRPCClient { 212 | return &jinaRPCClient{cc} 213 | } 214 | 215 | func (c *jinaRPCClient) Call(ctx context.Context, opts ...grpc.CallOption) (JinaRPC_CallClient, error) { 216 | stream, err := c.cc.NewStream(ctx, &JinaRPC_ServiceDesc.Streams[0], "/jina.JinaRPC/Call", opts...) 217 | if err != nil { 218 | return nil, err 219 | } 220 | x := &jinaRPCCallClient{stream} 221 | return x, nil 222 | } 223 | 224 | type JinaRPC_CallClient interface { 225 | Send(*DataRequestProto) error 226 | Recv() (*DataRequestProto, error) 227 | grpc.ClientStream 228 | } 229 | 230 | type jinaRPCCallClient struct { 231 | grpc.ClientStream 232 | } 233 | 234 | func (x *jinaRPCCallClient) Send(m *DataRequestProto) error { 235 | return x.ClientStream.SendMsg(m) 236 | } 237 | 238 | func (x *jinaRPCCallClient) Recv() (*DataRequestProto, error) { 239 | m := new(DataRequestProto) 240 | if err := x.ClientStream.RecvMsg(m); err != nil { 241 | return nil, err 242 | } 243 | return m, nil 244 | } 245 | 246 | // JinaRPCServer is the server API for JinaRPC service. 247 | // All implementations must embed UnimplementedJinaRPCServer 248 | // for forward compatibility 249 | type JinaRPCServer interface { 250 | // Pass in a Request and a filled Request with matches will be returned. 251 | Call(JinaRPC_CallServer) error 252 | mustEmbedUnimplementedJinaRPCServer() 253 | } 254 | 255 | // UnimplementedJinaRPCServer must be embedded to have forward compatible implementations. 256 | type UnimplementedJinaRPCServer struct { 257 | } 258 | 259 | func (UnimplementedJinaRPCServer) Call(JinaRPC_CallServer) error { 260 | return status.Errorf(codes.Unimplemented, "method Call not implemented") 261 | } 262 | func (UnimplementedJinaRPCServer) mustEmbedUnimplementedJinaRPCServer() {} 263 | 264 | // UnsafeJinaRPCServer may be embedded to opt out of forward compatibility for this service. 265 | // Use of this interface is not recommended, as added methods to JinaRPCServer will 266 | // result in compilation errors. 267 | type UnsafeJinaRPCServer interface { 268 | mustEmbedUnimplementedJinaRPCServer() 269 | } 270 | 271 | func RegisterJinaRPCServer(s grpc.ServiceRegistrar, srv JinaRPCServer) { 272 | s.RegisterService(&JinaRPC_ServiceDesc, srv) 273 | } 274 | 275 | func _JinaRPC_Call_Handler(srv interface{}, stream grpc.ServerStream) error { 276 | return srv.(JinaRPCServer).Call(&jinaRPCCallServer{stream}) 277 | } 278 | 279 | type JinaRPC_CallServer interface { 280 | Send(*DataRequestProto) error 281 | Recv() (*DataRequestProto, error) 282 | grpc.ServerStream 283 | } 284 | 285 | type jinaRPCCallServer struct { 286 | grpc.ServerStream 287 | } 288 | 289 | func (x *jinaRPCCallServer) Send(m *DataRequestProto) error { 290 | return x.ServerStream.SendMsg(m) 291 | } 292 | 293 | func (x *jinaRPCCallServer) Recv() (*DataRequestProto, error) { 294 | m := new(DataRequestProto) 295 | if err := x.ServerStream.RecvMsg(m); err != nil { 296 | return nil, err 297 | } 298 | return m, nil 299 | } 300 | 301 | // JinaRPC_ServiceDesc is the grpc.ServiceDesc for JinaRPC service. 302 | // It's only intended for direct use with grpc.RegisterService, 303 | // and not to be introspected or modified (even as a copy) 304 | var JinaRPC_ServiceDesc = grpc.ServiceDesc{ 305 | ServiceName: "jina.JinaRPC", 306 | HandlerType: (*JinaRPCServer)(nil), 307 | Methods: []grpc.MethodDesc{}, 308 | Streams: []grpc.StreamDesc{ 309 | { 310 | StreamName: "Call", 311 | Handler: _JinaRPC_Call_Handler, 312 | ServerStreams: true, 313 | ClientStreams: true, 314 | }, 315 | }, 316 | Metadata: "jina.proto", 317 | } 318 | 319 | // JinaDiscoverEndpointsRPCClient is the client API for JinaDiscoverEndpointsRPC service. 320 | // 321 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 322 | type JinaDiscoverEndpointsRPCClient interface { 323 | EndpointDiscovery(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*EndpointsProto, error) 324 | } 325 | 326 | type jinaDiscoverEndpointsRPCClient struct { 327 | cc grpc.ClientConnInterface 328 | } 329 | 330 | func NewJinaDiscoverEndpointsRPCClient(cc grpc.ClientConnInterface) JinaDiscoverEndpointsRPCClient { 331 | return &jinaDiscoverEndpointsRPCClient{cc} 332 | } 333 | 334 | func (c *jinaDiscoverEndpointsRPCClient) EndpointDiscovery(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*EndpointsProto, error) { 335 | out := new(EndpointsProto) 336 | err := c.cc.Invoke(ctx, "/jina.JinaDiscoverEndpointsRPC/endpoint_discovery", in, out, opts...) 337 | if err != nil { 338 | return nil, err 339 | } 340 | return out, nil 341 | } 342 | 343 | // JinaDiscoverEndpointsRPCServer is the server API for JinaDiscoverEndpointsRPC service. 344 | // All implementations must embed UnimplementedJinaDiscoverEndpointsRPCServer 345 | // for forward compatibility 346 | type JinaDiscoverEndpointsRPCServer interface { 347 | EndpointDiscovery(context.Context, *emptypb.Empty) (*EndpointsProto, error) 348 | mustEmbedUnimplementedJinaDiscoverEndpointsRPCServer() 349 | } 350 | 351 | // UnimplementedJinaDiscoverEndpointsRPCServer must be embedded to have forward compatible implementations. 352 | type UnimplementedJinaDiscoverEndpointsRPCServer struct { 353 | } 354 | 355 | func (UnimplementedJinaDiscoverEndpointsRPCServer) EndpointDiscovery(context.Context, *emptypb.Empty) (*EndpointsProto, error) { 356 | return nil, status.Errorf(codes.Unimplemented, "method EndpointDiscovery not implemented") 357 | } 358 | func (UnimplementedJinaDiscoverEndpointsRPCServer) mustEmbedUnimplementedJinaDiscoverEndpointsRPCServer() { 359 | } 360 | 361 | // UnsafeJinaDiscoverEndpointsRPCServer may be embedded to opt out of forward compatibility for this service. 362 | // Use of this interface is not recommended, as added methods to JinaDiscoverEndpointsRPCServer will 363 | // result in compilation errors. 364 | type UnsafeJinaDiscoverEndpointsRPCServer interface { 365 | mustEmbedUnimplementedJinaDiscoverEndpointsRPCServer() 366 | } 367 | 368 | func RegisterJinaDiscoverEndpointsRPCServer(s grpc.ServiceRegistrar, srv JinaDiscoverEndpointsRPCServer) { 369 | s.RegisterService(&JinaDiscoverEndpointsRPC_ServiceDesc, srv) 370 | } 371 | 372 | func _JinaDiscoverEndpointsRPC_EndpointDiscovery_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 373 | in := new(emptypb.Empty) 374 | if err := dec(in); err != nil { 375 | return nil, err 376 | } 377 | if interceptor == nil { 378 | return srv.(JinaDiscoverEndpointsRPCServer).EndpointDiscovery(ctx, in) 379 | } 380 | info := &grpc.UnaryServerInfo{ 381 | Server: srv, 382 | FullMethod: "/jina.JinaDiscoverEndpointsRPC/endpoint_discovery", 383 | } 384 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 385 | return srv.(JinaDiscoverEndpointsRPCServer).EndpointDiscovery(ctx, req.(*emptypb.Empty)) 386 | } 387 | return interceptor(ctx, in, info, handler) 388 | } 389 | 390 | // JinaDiscoverEndpointsRPC_ServiceDesc is the grpc.ServiceDesc for JinaDiscoverEndpointsRPC service. 391 | // It's only intended for direct use with grpc.RegisterService, 392 | // and not to be introspected or modified (even as a copy) 393 | var JinaDiscoverEndpointsRPC_ServiceDesc = grpc.ServiceDesc{ 394 | ServiceName: "jina.JinaDiscoverEndpointsRPC", 395 | HandlerType: (*JinaDiscoverEndpointsRPCServer)(nil), 396 | Methods: []grpc.MethodDesc{ 397 | { 398 | MethodName: "endpoint_discovery", 399 | Handler: _JinaDiscoverEndpointsRPC_EndpointDiscovery_Handler, 400 | }, 401 | }, 402 | Streams: []grpc.StreamDesc{}, 403 | Metadata: "jina.proto", 404 | } 405 | 406 | // JinaGatewayDryRunRPCClient is the client API for JinaGatewayDryRunRPC service. 407 | // 408 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 409 | type JinaGatewayDryRunRPCClient interface { 410 | DryRun(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*StatusProto, error) 411 | } 412 | 413 | type jinaGatewayDryRunRPCClient struct { 414 | cc grpc.ClientConnInterface 415 | } 416 | 417 | func NewJinaGatewayDryRunRPCClient(cc grpc.ClientConnInterface) JinaGatewayDryRunRPCClient { 418 | return &jinaGatewayDryRunRPCClient{cc} 419 | } 420 | 421 | func (c *jinaGatewayDryRunRPCClient) DryRun(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*StatusProto, error) { 422 | out := new(StatusProto) 423 | err := c.cc.Invoke(ctx, "/jina.JinaGatewayDryRunRPC/dry_run", in, out, opts...) 424 | if err != nil { 425 | return nil, err 426 | } 427 | return out, nil 428 | } 429 | 430 | // JinaGatewayDryRunRPCServer is the server API for JinaGatewayDryRunRPC service. 431 | // All implementations must embed UnimplementedJinaGatewayDryRunRPCServer 432 | // for forward compatibility 433 | type JinaGatewayDryRunRPCServer interface { 434 | DryRun(context.Context, *emptypb.Empty) (*StatusProto, error) 435 | mustEmbedUnimplementedJinaGatewayDryRunRPCServer() 436 | } 437 | 438 | // UnimplementedJinaGatewayDryRunRPCServer must be embedded to have forward compatible implementations. 439 | type UnimplementedJinaGatewayDryRunRPCServer struct { 440 | } 441 | 442 | func (UnimplementedJinaGatewayDryRunRPCServer) DryRun(context.Context, *emptypb.Empty) (*StatusProto, error) { 443 | return nil, status.Errorf(codes.Unimplemented, "method DryRun not implemented") 444 | } 445 | func (UnimplementedJinaGatewayDryRunRPCServer) mustEmbedUnimplementedJinaGatewayDryRunRPCServer() {} 446 | 447 | // UnsafeJinaGatewayDryRunRPCServer may be embedded to opt out of forward compatibility for this service. 448 | // Use of this interface is not recommended, as added methods to JinaGatewayDryRunRPCServer will 449 | // result in compilation errors. 450 | type UnsafeJinaGatewayDryRunRPCServer interface { 451 | mustEmbedUnimplementedJinaGatewayDryRunRPCServer() 452 | } 453 | 454 | func RegisterJinaGatewayDryRunRPCServer(s grpc.ServiceRegistrar, srv JinaGatewayDryRunRPCServer) { 455 | s.RegisterService(&JinaGatewayDryRunRPC_ServiceDesc, srv) 456 | } 457 | 458 | func _JinaGatewayDryRunRPC_DryRun_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 459 | in := new(emptypb.Empty) 460 | if err := dec(in); err != nil { 461 | return nil, err 462 | } 463 | if interceptor == nil { 464 | return srv.(JinaGatewayDryRunRPCServer).DryRun(ctx, in) 465 | } 466 | info := &grpc.UnaryServerInfo{ 467 | Server: srv, 468 | FullMethod: "/jina.JinaGatewayDryRunRPC/dry_run", 469 | } 470 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 471 | return srv.(JinaGatewayDryRunRPCServer).DryRun(ctx, req.(*emptypb.Empty)) 472 | } 473 | return interceptor(ctx, in, info, handler) 474 | } 475 | 476 | // JinaGatewayDryRunRPC_ServiceDesc is the grpc.ServiceDesc for JinaGatewayDryRunRPC service. 477 | // It's only intended for direct use with grpc.RegisterService, 478 | // and not to be introspected or modified (even as a copy) 479 | var JinaGatewayDryRunRPC_ServiceDesc = grpc.ServiceDesc{ 480 | ServiceName: "jina.JinaGatewayDryRunRPC", 481 | HandlerType: (*JinaGatewayDryRunRPCServer)(nil), 482 | Methods: []grpc.MethodDesc{ 483 | { 484 | MethodName: "dry_run", 485 | Handler: _JinaGatewayDryRunRPC_DryRun_Handler, 486 | }, 487 | }, 488 | Streams: []grpc.StreamDesc{}, 489 | Metadata: "jina.proto", 490 | } 491 | 492 | // JinaInfoRPCClient is the client API for JinaInfoRPC service. 493 | // 494 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 495 | type JinaInfoRPCClient interface { 496 | XStatus(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*JinaInfoProto, error) 497 | } 498 | 499 | type jinaInfoRPCClient struct { 500 | cc grpc.ClientConnInterface 501 | } 502 | 503 | func NewJinaInfoRPCClient(cc grpc.ClientConnInterface) JinaInfoRPCClient { 504 | return &jinaInfoRPCClient{cc} 505 | } 506 | 507 | func (c *jinaInfoRPCClient) XStatus(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*JinaInfoProto, error) { 508 | out := new(JinaInfoProto) 509 | err := c.cc.Invoke(ctx, "/jina.JinaInfoRPC/_status", in, out, opts...) 510 | if err != nil { 511 | return nil, err 512 | } 513 | return out, nil 514 | } 515 | 516 | // JinaInfoRPCServer is the server API for JinaInfoRPC service. 517 | // All implementations must embed UnimplementedJinaInfoRPCServer 518 | // for forward compatibility 519 | type JinaInfoRPCServer interface { 520 | XStatus(context.Context, *emptypb.Empty) (*JinaInfoProto, error) 521 | mustEmbedUnimplementedJinaInfoRPCServer() 522 | } 523 | 524 | // UnimplementedJinaInfoRPCServer must be embedded to have forward compatible implementations. 525 | type UnimplementedJinaInfoRPCServer struct { 526 | } 527 | 528 | func (UnimplementedJinaInfoRPCServer) XStatus(context.Context, *emptypb.Empty) (*JinaInfoProto, error) { 529 | return nil, status.Errorf(codes.Unimplemented, "method XStatus not implemented") 530 | } 531 | func (UnimplementedJinaInfoRPCServer) mustEmbedUnimplementedJinaInfoRPCServer() {} 532 | 533 | // UnsafeJinaInfoRPCServer may be embedded to opt out of forward compatibility for this service. 534 | // Use of this interface is not recommended, as added methods to JinaInfoRPCServer will 535 | // result in compilation errors. 536 | type UnsafeJinaInfoRPCServer interface { 537 | mustEmbedUnimplementedJinaInfoRPCServer() 538 | } 539 | 540 | func RegisterJinaInfoRPCServer(s grpc.ServiceRegistrar, srv JinaInfoRPCServer) { 541 | s.RegisterService(&JinaInfoRPC_ServiceDesc, srv) 542 | } 543 | 544 | func _JinaInfoRPC_XStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 545 | in := new(emptypb.Empty) 546 | if err := dec(in); err != nil { 547 | return nil, err 548 | } 549 | if interceptor == nil { 550 | return srv.(JinaInfoRPCServer).XStatus(ctx, in) 551 | } 552 | info := &grpc.UnaryServerInfo{ 553 | Server: srv, 554 | FullMethod: "/jina.JinaInfoRPC/_status", 555 | } 556 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 557 | return srv.(JinaInfoRPCServer).XStatus(ctx, req.(*emptypb.Empty)) 558 | } 559 | return interceptor(ctx, in, info, handler) 560 | } 561 | 562 | // JinaInfoRPC_ServiceDesc is the grpc.ServiceDesc for JinaInfoRPC service. 563 | // It's only intended for direct use with grpc.RegisterService, 564 | // and not to be introspected or modified (even as a copy) 565 | var JinaInfoRPC_ServiceDesc = grpc.ServiceDesc{ 566 | ServiceName: "jina.JinaInfoRPC", 567 | HandlerType: (*JinaInfoRPCServer)(nil), 568 | Methods: []grpc.MethodDesc{ 569 | { 570 | MethodName: "_status", 571 | Handler: _JinaInfoRPC_XStatus_Handler, 572 | }, 573 | }, 574 | Streams: []grpc.StreamDesc{}, 575 | Metadata: "jina.proto", 576 | } 577 | -------------------------------------------------------------------------------- /jina/v3.9.0/json.go: -------------------------------------------------------------------------------- 1 | package jina 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | docarray "github.com/jina-ai/client-go/docarray" 7 | "google.golang.org/protobuf/encoding/protojson" 8 | structpb "google.golang.org/protobuf/types/known/structpb" 9 | ) 10 | 11 | // Custom JSON marshalling for DataRequestProto 12 | func (x *DataRequestProto) MarshalJSON() ([]byte, error) { 13 | // JSON request to Jina Gateway 14 | type tmpDataRequestProto struct { 15 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 16 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 17 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 18 | Data *docarray.DocumentArrayProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 19 | } 20 | tmp := tmpDataRequestProto{ 21 | Header: x.Header, 22 | Parameters: x.Parameters, 23 | Routes: x.Routes, 24 | Data: x.Data.Documents.(*DataRequestProto_DataContentProto_Docs).Docs, 25 | } 26 | return json.Marshal(tmp) 27 | } 28 | 29 | // Custom JSON unmarshalling for DataRequestProto 30 | func (x *DataRequestProto) UnmarshalJSON(data []byte) error { 31 | // JSON response from Jina Gateway 32 | type tmpDataRequestProto struct { 33 | Header *HeaderProto `protobuf:"bytes,1,opt,name=header,proto3" json:"header,omitempty"` // header contains meta info defined by the user 34 | Parameters *structpb.Struct `protobuf:"bytes,2,opt,name=parameters,proto3" json:"parameters,omitempty"` // extra kwargs that will be used in executor 35 | Routes []*RouteProto `protobuf:"bytes,3,rep,name=routes,proto3" json:"routes,omitempty"` // status info on every routes 36 | Data []*docarray.DocumentProto `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` // container for docs and groundtruths 37 | } 38 | 39 | var tmp tmpDataRequestProto 40 | if err := json.Unmarshal(data, &tmp); err != nil { 41 | return err 42 | } 43 | 44 | x.Header = tmp.Header 45 | x.Parameters = tmp.Parameters 46 | x.Routes = tmp.Routes 47 | x.Data = &DataRequestProto_DataContentProto{ 48 | Documents: &DataRequestProto_DataContentProto_Docs{ 49 | Docs: &docarray.DocumentArrayProto{ 50 | Docs: tmp.Data, 51 | }, 52 | }, 53 | } 54 | return nil 55 | } 56 | 57 | // Custom JSON marshalling for RouteProto 58 | func (x *RouteProto) MarshalJSON() ([]byte, error) { 59 | return protojson.Marshal(x) 60 | } 61 | 62 | // Custom JSON unmarshalling for RouteProto 63 | func (x *RouteProto) UnmarshalJSON(data []byte) error { 64 | return protojson.Unmarshal(data, x) 65 | } 66 | -------------------------------------------------------------------------------- /protos/docarray.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | import "google/protobuf/struct.proto"; 3 | 4 | package docarray; 5 | option go_package = "github.com/jina-ai/client-go/docarray"; 6 | 7 | /** 8 | * Represents a (quantized) dense n-dim array 9 | */ 10 | message DenseNdArrayProto { 11 | // the actual array data, in bytes 12 | bytes buffer = 1; 13 | 14 | // the shape (dimensions) of the array 15 | repeated uint32 shape = 2; 16 | 17 | // the data type of the array 18 | string dtype = 3; 19 | } 20 | 21 | /** 22 | * Represents a general n-dim array, can be either dense or sparse 23 | */ 24 | message NdArrayProto { 25 | oneof content { 26 | DenseNdArrayProto dense = 1; // dense representation of the ndarray 27 | SparseNdArrayProto sparse = 2; // sparse representation of the ndarray 28 | } 29 | 30 | // the name of the ndarray class 31 | string cls_name = 3; 32 | 33 | google.protobuf.Struct parameters = 4; 34 | } 35 | 36 | /** 37 | * Represents a sparse ndarray 38 | */ 39 | message SparseNdArrayProto { 40 | // A 2-D int64 tensor of shape [N, ndims], which specifies the indices of the elements in the sparse tensor that contain nonzero values (elements are zero-indexed) 41 | DenseNdArrayProto indices = 1; 42 | 43 | // A 1-D tensor of any type and shape [N], which supplies the values for each element in indices. 44 | DenseNdArrayProto values = 2; 45 | 46 | // A 1-D int64 tensor of shape [ndims], which specifies the shape of the sparse tensor. 47 | repeated uint32 shape = 3; 48 | } 49 | 50 | /** 51 | * Represents the relevance model to `ref_id` 52 | */ 53 | message NamedScoreProto { 54 | float value = 1; // value 55 | string op_name = 2; // the name of the operator/score function 56 | string description = 3; // text description of the score 57 | string ref_id = 4; // the score is computed between doc `id` and `ref_id` 58 | } 59 | 60 | 61 | /** 62 | * Represents a Document 63 | */ 64 | message DocumentProto { 65 | // A hexdigest that represents a unique document ID 66 | string id = 1; 67 | 68 | oneof content { 69 | // the raw binary content of this document, which often represents the original document when comes into jina 70 | bytes blob = 2; 71 | 72 | // the ndarray of the image/audio/video document 73 | NdArrayProto tensor = 3; 74 | 75 | // a text document 76 | string text = 4; 77 | } 78 | 79 | // the depth of the recursive chunk structure 80 | uint32 granularity = 5; 81 | 82 | // the width of the recursive match structure 83 | uint32 adjacency = 6; 84 | 85 | // the parent id from the previous granularity 86 | string parent_id = 7; 87 | 88 | // The weight of this document 89 | float weight = 8; 90 | 91 | // a uri of the document could be: a local file path, a remote url starts with http or https or data URI scheme 92 | string uri = 9; 93 | 94 | // modality, an identifier to the modality this document belongs to. In the scope of multi/cross modal search 95 | string modality = 10; 96 | 97 | // mime type of this document, for buffer content, this is required; for other contents, this can be guessed 98 | string mime_type = 11; 99 | 100 | // the offset of the doc 101 | float offset = 12; 102 | 103 | // the position of the doc, could be start and end index of a string; could be x,y (top, left) coordinate of an image crop; could be timestamp of an audio clip 104 | repeated float location = 13; 105 | 106 | // list of the sub-documents of this document (recursive structure) 107 | repeated DocumentProto chunks = 14; 108 | 109 | // the matched documents on the same level (recursive structure) 110 | repeated DocumentProto matches = 15; 111 | 112 | // the embedding of this document 113 | NdArrayProto embedding = 16; 114 | 115 | // a structured data value, consisting of field which map to dynamically typed values. 116 | google.protobuf.Struct tags = 17; 117 | 118 | // Scores performed on the document, each element corresponds to a metric 119 | map scores = 18; 120 | 121 | // Evaluations performed on the document, each element corresponds to a metric 122 | map evaluations = 19; 123 | 124 | // system-defined meta attributes represented in a structured data value. 125 | google.protobuf.Struct _metadata = 20; 126 | 127 | } 128 | 129 | message DocumentArrayProto { 130 | repeated DocumentProto docs = 1; // a list of Documents 131 | } -------------------------------------------------------------------------------- /protos/jina.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | import "google/protobuf/timestamp.proto"; 3 | import "google/protobuf/struct.proto"; 4 | import "google/protobuf/empty.proto"; 5 | import "docarray.proto"; 6 | 7 | package jina; 8 | option go_package = "github.com/jina-ai/client-go/jina"; 9 | 10 | /** 11 | * Represents a the route paths of this message as perceived by the Gateway 12 | * start_time is set when the Gateway sends a message to a Pod 13 | * end_time is set when the Gateway receives a message from a Pod 14 | * thus end_time - start_time includes Executor computation, runtime overhead, serialization and network 15 | */ 16 | message RouteProto { 17 | string executor = 1; // the name of the BasePod 18 | google.protobuf.Timestamp start_time = 2; // time when the Gateway starts sending to the Pod 19 | google.protobuf.Timestamp end_time = 3; // time when the Gateway received it from the Pod 20 | StatusProto status = 4; // the status of the execution 21 | } 22 | 23 | message JinaInfoProto { 24 | map jina = 1; // information about the system running and package version information including jina 25 | map envs = 2; // the environment variable setting 26 | } 27 | 28 | 29 | /** 30 | * Represents a Header. 31 | * - The header's content will be defined by the user request. 32 | * - It will be copied to the envelope.header 33 | * - In-flow operations will modify the envelope.header 34 | * - While returning, copy envelope.header back to request.header 35 | */ 36 | message HeaderProto { 37 | string request_id = 1; // the unique ID of this request. Multiple requests with the same ID will be gathered 38 | 39 | StatusProto status = 2; // status info 40 | 41 | optional string exec_endpoint = 3; // the endpoint specified by `@requests(on='/abc')` 42 | 43 | optional string target_executor = 4; // if set, the request is targeted to certain executor, regex strings 44 | 45 | optional uint32 timeout = 5; // epoch time in seconds after which the request should be dropped 46 | } 47 | 48 | 49 | /** 50 | * Represents the set of Endpoints exposed by an Executor 51 | */ 52 | message EndpointsProto { 53 | 54 | // list of endpoints exposed by an Executor 55 | repeated string endpoints = 1; 56 | repeated string write_endpoints = 2; 57 | // Dictionary containing input and output schema per endpoint 58 | google.protobuf.Struct schemas = 3; // extra kwargs that will be used in executor 59 | } 60 | 61 | /** 62 | * Represents a Status 63 | */ 64 | message StatusProto { 65 | 66 | enum StatusCode { 67 | SUCCESS = 0; // success 68 | ERROR = 1; // error 69 | } 70 | 71 | // status code 72 | StatusCode code = 1; 73 | 74 | // error description of the very first exception 75 | string description = 2; 76 | 77 | message ExceptionProto { 78 | // the class name of the exception 79 | string name = 1; 80 | 81 | // the list of arguments given to the exception constructor. 82 | repeated string args = 2; 83 | 84 | // the exception traceback stacks 85 | repeated string stacks = 3; 86 | 87 | // the name of the executor bind to that Executor (if applicable) 88 | string executor = 4; 89 | } 90 | 91 | // the details of the error 92 | ExceptionProto exception = 3; 93 | } 94 | 95 | 96 | /** 97 | * Represents an entity (like an ExecutorRuntime) 98 | */ 99 | message RelatedEntity { 100 | string id = 1; // unique id of the entity, like the name of a pod 101 | string address = 2; // address of the entity, could be an IP address, domain name etc, does not include port 102 | uint32 port = 3; // port this entity is listening on 103 | optional uint32 shard_id = 4; // the id of the shard it belongs to, if it is a shard 104 | } 105 | 106 | 107 | /** 108 | * Represents a DataRequest 109 | */ 110 | message DataRequestProto { 111 | 112 | HeaderProto header = 1; // header contains meta info defined by the user 113 | 114 | google.protobuf.Struct parameters = 2; // extra kwargs that will be used in executor 115 | 116 | repeated RouteProto routes = 3; // status info on every routes 117 | 118 | message DataContentProto { 119 | oneof documents { 120 | docarray.DocumentArrayProto docs = 1; // the docs in this request 121 | bytes docs_bytes = 2; // the docs in this request as bytes 122 | } 123 | } 124 | 125 | DataContentProto data = 4; // container for docs and groundtruths 126 | } 127 | 128 | 129 | /** 130 | * Represents a Single Document DataRequest 131 | */ 132 | message SingleDocumentRequestProto { 133 | 134 | HeaderProto header = 1; // header contains meta info defined by the user 135 | 136 | google.protobuf.Struct parameters = 2; // extra kwargs that will be used in executor 137 | 138 | repeated RouteProto routes = 3; // status info on every routes 139 | 140 | docarray.DocumentProto document = 4; // the document in this request 141 | 142 | } 143 | 144 | message DataRequestProtoWoData { 145 | 146 | HeaderProto header = 1; // header contains meta info defined by the user 147 | 148 | google.protobuf.Struct parameters = 2; // extra kwargs that will be used in executor 149 | 150 | repeated RouteProto routes = 3; // status info on every routes 151 | 152 | } 153 | 154 | 155 | /** 156 | * Represents a list of data requests 157 | * This should be replaced by streaming 158 | */ 159 | message DataRequestListProto { 160 | repeated DataRequestProto requests = 1; // requests in this list 161 | } 162 | 163 | /** 164 | * jina gRPC service for DataRequests. 165 | */ 166 | service JinaDataRequestRPC { 167 | // Used for passing DataRequests to the Executors 168 | rpc process_data (DataRequestListProto) returns (DataRequestProto) { 169 | } 170 | } 171 | 172 | /** 173 | * jina gRPC service for DataRequests. 174 | * This is used to send requests to Executors when a list of requests is not needed 175 | */ 176 | service JinaSingleDataRequestRPC { 177 | // Used for passing DataRequests to the Executors 178 | rpc process_single_data (DataRequestProto) returns (DataRequestProto) { 179 | } 180 | } 181 | 182 | /** 183 | * jina gRPC service for DataRequests. 184 | * This is used to send requests to Executors when a list of requests is not needed 185 | */ 186 | service JinaSingleDocumentRequestRPC { 187 | // Used for streaming one document to the Executors 188 | rpc stream_doc (SingleDocumentRequestProto) returns (stream SingleDocumentRequestProto) { 189 | } 190 | } 191 | 192 | /** 193 | * jina streaming gRPC service. 194 | */ 195 | service JinaRPC { 196 | // Pass in a Request and a filled Request with matches will be returned. 197 | rpc Call (stream DataRequestProto) returns (stream DataRequestProto) { 198 | } 199 | } 200 | 201 | /** 202 | * jina gRPC service to expose Endpoints from Executors. 203 | */ 204 | service JinaDiscoverEndpointsRPC { 205 | rpc endpoint_discovery (google.protobuf.Empty) returns (EndpointsProto) { 206 | } 207 | } 208 | 209 | 210 | /** 211 | * jina gRPC service to expose Endpoints from Executors. 212 | */ 213 | service JinaGatewayDryRunRPC { 214 | rpc dry_run (google.protobuf.Empty) returns (StatusProto) { 215 | } 216 | } 217 | 218 | /** 219 | * jina gRPC service to expose information about running jina version and environment. 220 | */ 221 | service JinaInfoRPC { 222 | rpc _status (google.protobuf.Empty) returns (JinaInfoProto) { 223 | } 224 | } 225 | 226 | /** 227 | * An ID representation for the Snapshot Job 228 | */ 229 | message SnapshotId { 230 | string value = 1; 231 | } 232 | 233 | /** 234 | * An ID representation for the Restore Job 235 | */ 236 | message RestoreId { 237 | string value = 1; 238 | } 239 | 240 | 241 | /** 242 | * Represents the status of a Snapshot. 243 | */ 244 | message SnapshotStatusProto { 245 | 246 | SnapshotId id = 1; // An ID for the Snapshot Job. 247 | 248 | enum Status { 249 | STATE_UNSPECIFIED = 0; 250 | 251 | QUEUED = 1; // Snapshot Job is admitted (validated and persisted) and waiting for resources. 252 | 253 | SCHEDULED = 2; // Snapshot Job is scheduled to run as soon as resource allocation is ready. 254 | 255 | RUNNING = 3; // Resource allocation has been successful. Snapshot Job is RUNNING. 256 | 257 | SUCCEEDED = 4; // Snapshot Job has finished successfully. 258 | 259 | FAILED = 5; // Snapshot Job has failed. 260 | 261 | NOT_FOUND = 6; // If the specific snapshot id is unknown or not found 262 | } 263 | 264 | // status code 265 | Status status = 2; 266 | 267 | // snapshot file 268 | string snapshot_file = 3; 269 | } 270 | 271 | /** 272 | * jina gRPC service to trigger a snapshot at the Executor Runtime. 273 | */ 274 | service JinaExecutorSnapshot { 275 | rpc snapshot (google.protobuf.Empty) returns (SnapshotStatusProto) { 276 | } 277 | } 278 | 279 | /** 280 | * jina gRPC service to trigger a snapshot at the Executor Runtime. 281 | */ 282 | service JinaExecutorSnapshotProgress { 283 | rpc snapshot_status (SnapshotId) returns (SnapshotStatusProto) { 284 | } 285 | } 286 | 287 | /** 288 | * Represents the status of a Restore. 289 | */ 290 | message RestoreSnapshotStatusProto { 291 | 292 | RestoreId id = 1; // An ID for the Restore Job. 293 | 294 | enum Status { 295 | STATE_UNSPECIFIED = 0; 296 | 297 | RUNNING = 1; // Resource allocation has been successful. Restore Job is RUNNING. 298 | 299 | SUCCEEDED = 2; // Resource Job has finished successfully. 300 | 301 | FAILED = 3; // Resource Job has failed. 302 | 303 | NOT_FOUND = 6; // If the specific restore id is unknown or not found 304 | } 305 | 306 | // status code 307 | Status status = 2; 308 | } 309 | 310 | /** 311 | * Commands to restore an Executor from a snapshot file 312 | */ 313 | message RestoreSnapshotCommand { 314 | // snapshot file 315 | string snapshot_file = 1; 316 | } 317 | 318 | /** 319 | * jina gRPC service to trigger a restore at the Executor Runtime. 320 | */ 321 | service JinaExecutorRestore { 322 | rpc restore (RestoreSnapshotCommand) returns (RestoreSnapshotStatusProto) { 323 | } 324 | } 325 | 326 | /** 327 | * jina gRPC service to trigger a snapshot at the Executor Runtime. 328 | */ 329 | service JinaExecutorRestoreProgress { 330 | rpc restore_status (RestoreId) returns (RestoreSnapshotStatusProto) { 331 | } 332 | } 333 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | jina==3.23.1 2 | docarray==0.21.1 3 | pydantic==1.10.2 -------------------------------------------------------------------------------- /scripts/fetchProtos.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # This script fetches the latest protobuf files from the Jina/Docarray repository 6 | # and copies them to the `protos` directory. 7 | 8 | # The script is meant to be run from the root of the repository. 9 | 10 | JINA_VERSION=$1 11 | DOCARRAY_VERSION=$2 12 | 13 | if [ -z "$JINA_VERSION" ]; then 14 | echo "Please provide a Jina version as the first argument." 15 | exit 1 16 | fi 17 | 18 | if [[ $JINA_VERSION != "v*" ]]; then 19 | JINA_VERSION="v$JINA_VERSION" 20 | fi 21 | 22 | if [ -z "$DOCARRAY_VERSION" ]; then 23 | echo "Please provide a Docarray version as the second argument." 24 | exit 1 25 | fi 26 | 27 | if [[ $DOCARRAY_VERSION != "v*" ]]; then 28 | DOCARRAY_VERSION="v$DOCARRAY_VERSION" 29 | fi 30 | 31 | echo "Fetching protos for Jina version $JINA_VERSION" 32 | wget https://raw.githubusercontent.com/jina-ai/jina/$JINA_VERSION/jina/proto/docarray_v1/jina.proto -O protos/jina.proto 33 | 34 | echo "Fetching protos for Docarray version $DOCARRAY_VERSION" 35 | wget https://raw.githubusercontent.com/jina-ai/docarray/$DOCARRAY_VERSION/docarray/proto/docarray.proto -O protos/docarray.proto 36 | -------------------------------------------------------------------------------- /scripts/protogen.sh: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | 3 | set -e 4 | 5 | # This script is used to generate gRPC client stubs from the proto files. 6 | JINA_VERSION=$1 7 | DOCARRAY_VERSION=$2 8 | 9 | GO_MODULE="github.com/jina-ai/client-go" 10 | DOCARRAY_PROTO="docarray.proto" 11 | DOCARRAY_DIR="../docarray" 12 | DOCARRAY_PACKAGE="$GO_MODULE/docarray" 13 | 14 | JINA_PROTO="jina.proto" 15 | JINA_DIR="../jina" 16 | JINA_PACKAGE="$GO_MODULE/jina" 17 | 18 | cd protos 19 | 20 | [ -d $DOCARRAY_DIR/v$DOCARRAY_VERSION ] || mkdir $DOCARRAY_DIR/v$DOCARRAY_VERSION 21 | mkdir -p $JINA_DIR/v$JINA_VERSION 22 | 23 | grep -q '^option go_package = ' docarray.proto || sed -i '/package docarray;/aoption go_package = "'${DOCARRAY_PACKAGE}'";' docarray.proto 24 | protoc --go_out=${DOCARRAY_DIR} \ 25 | --go_opt=paths=source_relative \ 26 | --go_opt=M${DOCARRAY_PROTO}=${DOCARRAY_PACKAGE} \ 27 | --go-grpc_out=${DOCARRAY_DIR}/v${DOCARRAY_VERSION} \ 28 | --go-grpc_opt=paths=source_relative \ 29 | ${DOCARRAY_PROTO} 30 | 31 | cp $DOCARRAY_DIR/*.go $DOCARRAY_DIR/v$DOCARRAY_VERSION 32 | 33 | grep -q '^option go_package = ' jina.proto || sed -i '/package jina;/aoption go_package = "'${JINA_PACKAGE}'";' jina.proto 34 | protoc --go_out=${JINA_DIR} \ 35 | --go_opt=paths=source_relative \ 36 | --go_opt=M${JINA_PROTO}=${JINA_PACKAGE} \ 37 | --go-grpc_out=${JINA_DIR} \ 38 | --go-grpc_opt=paths=source_relative \ 39 | ${JINA_PROTO} 40 | 41 | cp $JINA_DIR/*.go $JINA_DIR/v$JINA_VERSION 42 | 43 | cd - 44 | -------------------------------------------------------------------------------- /websocket.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "bytes" 5 | "context" 6 | "encoding/json" 7 | "fmt" 8 | "io" 9 | "net/http" 10 | "net/url" 11 | "strings" 12 | "sync" 13 | 14 | "github.com/gorilla/websocket" 15 | "github.com/jina-ai/client-go/jina" 16 | ) 17 | 18 | type WebSocketClient struct { 19 | Host string 20 | conn *websocket.Conn 21 | ctx context.Context 22 | } 23 | 24 | func NewWebSocketClient(host string) (*WebSocketClient, error) { 25 | var u *url.URL 26 | if !strings.HasPrefix(host, "ws") { 27 | host = "ws://" + host 28 | } 29 | u, err := url.Parse(host) 30 | if err != nil { 31 | u = &url.URL{Scheme: "ws", Host: host, Path: "/"} 32 | } 33 | conn, _, err := websocket.DefaultDialer.Dial(u.String(), nil) 34 | if err != nil { 35 | return &WebSocketClient{}, err 36 | } 37 | client := &WebSocketClient{ 38 | Host: host, 39 | conn: conn, 40 | ctx: context.Background(), 41 | } 42 | return client, nil 43 | } 44 | 45 | func (client WebSocketClient) POST(requests <-chan *jina.DataRequestProto, onDone, onError, onAlways CallbackType) error { 46 | var wg sync.WaitGroup 47 | 48 | go func() { 49 | for { 50 | _, data, err := client.conn.ReadMessage() 51 | if err != nil { 52 | fmt.Println(err) 53 | break 54 | } 55 | var res jina.DataRequestProto 56 | if err := json.Unmarshal(data, &res); err != nil { 57 | // Unsure how to handle OnError here 58 | fmt.Println(err) 59 | } else if onDone != nil { 60 | onDone(&res) 61 | } 62 | if onAlways != nil { 63 | onAlways(&res) 64 | } 65 | wg.Done() 66 | } 67 | }() 68 | 69 | for { 70 | request, ok := <-requests 71 | if !ok { 72 | break 73 | } 74 | reqJSON, err := json.Marshal(request) 75 | if err != nil { 76 | if onError != nil { 77 | onError(request) 78 | } 79 | if onAlways != nil { 80 | onAlways(request) 81 | } 82 | } 83 | 84 | err = client.conn.WriteMessage(websocket.TextMessage, reqJSON) 85 | if err != nil { 86 | if onError != nil { 87 | onError(request) 88 | } 89 | if onAlways != nil { 90 | onAlways(request) 91 | } 92 | } 93 | wg.Add(1) 94 | } 95 | wg.Wait() 96 | return nil 97 | } 98 | 99 | func (client WebSocketClient) SequentialPOST(requests <-chan *jina.DataRequestProto, onDone, onError, onAlways CallbackType) error { 100 | for { 101 | request, ok := <-requests 102 | if !ok { 103 | break 104 | } 105 | reqJSON, err := json.Marshal(request) 106 | if err != nil { 107 | if onError != nil { 108 | onError(request) 109 | } 110 | if onAlways != nil { 111 | onAlways(request) 112 | } 113 | } 114 | 115 | err = client.conn.WriteMessage(websocket.TextMessage, reqJSON) 116 | if err != nil { 117 | if onError != nil { 118 | onError(request) 119 | } 120 | if onAlways != nil { 121 | onAlways(request) 122 | } 123 | } 124 | 125 | _, data, err := client.conn.ReadMessage() 126 | if err != nil { 127 | fmt.Println(err) 128 | break 129 | } 130 | var res jina.DataRequestProto 131 | if err := json.Unmarshal(data, &res); err != nil { 132 | // Unsure how to handle OnError here 133 | fmt.Println(err) 134 | } else if onDone != nil { 135 | onDone(&res) 136 | } 137 | if onAlways != nil { 138 | onAlways(&res) 139 | } 140 | } 141 | return nil 142 | } 143 | 144 | type WebSocketHealthCheckClient struct { 145 | Host string 146 | ctx context.Context 147 | } 148 | 149 | func NewWebSocketHealthCheckClient(host string) (*WebSocketHealthCheckClient, error) { 150 | if strings.HasPrefix(host, "ws") { 151 | host = strings.Replace(host, "ws", "http", 1) 152 | } 153 | if !strings.HasPrefix(host, "http") { 154 | host = "http://" + host 155 | } 156 | if !strings.HasSuffix(host, "/dry_run") { 157 | host = host + "/dry_run" 158 | } 159 | return &WebSocketHealthCheckClient{ 160 | Host: host, 161 | ctx: context.Background(), 162 | }, nil 163 | } 164 | 165 | func (c WebSocketHealthCheckClient) HealthCheck() (bool, error) { 166 | req, err := http.NewRequest("GET", c.Host, nil) 167 | if err != nil { 168 | fmt.Println("Failed to create HTTP request", "host", c.Host, "err", err) 169 | return false, err 170 | } 171 | 172 | httpResp, err := HttpClient.Do(req) 173 | if err != nil { 174 | return false, err 175 | } 176 | if httpResp.StatusCode != http.StatusOK { 177 | return false, fmt.Errorf("got non 200 status code %d", httpResp.StatusCode) 178 | } 179 | defer httpResp.Body.Close() 180 | 181 | var resp map[string]interface{} 182 | if err := json.NewDecoder(httpResp.Body).Decode(&resp); err != nil { 183 | return false, fmt.Errorf("error decoding response: %w", err) 184 | } 185 | 186 | code := int(resp["code"].(float64)) 187 | if code != 0 { 188 | return false, fmt.Errorf("got non 0 code %s", resp["description"]) 189 | } else { 190 | return true, nil 191 | } 192 | } 193 | 194 | type WebSocketInfoClient struct { 195 | Host string 196 | ctx context.Context 197 | } 198 | 199 | func NewWebSocketInfoClient(host string) (WebSocketInfoClient, error) { 200 | if strings.HasPrefix(host, "ws") { 201 | host = strings.Replace(host, "ws", "http", 1) 202 | } 203 | if !strings.HasPrefix(host, "http") { 204 | host = "http://" + host 205 | } 206 | 207 | if !strings.HasSuffix(host, "/status") { 208 | host = host + "/status" 209 | } 210 | return WebSocketInfoClient{ 211 | Host: host, 212 | ctx: context.Background(), 213 | }, nil 214 | } 215 | 216 | func (c WebSocketInfoClient) InfoJSON() ([]byte, error) { 217 | req, err := http.NewRequest("GET", c.Host, nil) 218 | if err != nil { 219 | fmt.Println("Failed to create HTTP request", "host", c.Host, "err", err) 220 | return nil, err 221 | } 222 | 223 | httpResp, err := HttpClient.Do(req) 224 | if err != nil { 225 | return nil, err 226 | } 227 | defer httpResp.Body.Close() 228 | if httpResp.StatusCode != http.StatusOK { 229 | return nil, fmt.Errorf("got non 200 status code: %d", httpResp.StatusCode) 230 | } 231 | body, err := io.ReadAll(httpResp.Body) 232 | if err != nil { 233 | return nil, err 234 | } 235 | var buf bytes.Buffer 236 | if err := json.Indent(&buf, body, "", " "); err != nil { 237 | return nil, err 238 | } 239 | return buf.Bytes(), nil 240 | } 241 | 242 | func (c WebSocketInfoClient) Info() (*jina.JinaInfoProto, error) { 243 | body, err := c.InfoJSON() 244 | if err != nil { 245 | return nil, err 246 | } 247 | 248 | var res jina.JinaInfoProto 249 | if err := json.Unmarshal(body, &res); err != nil { 250 | return nil, err 251 | } 252 | return &res, nil 253 | } 254 | -------------------------------------------------------------------------------- /websocket_test.go: -------------------------------------------------------------------------------- 1 | package client 2 | 3 | import ( 4 | "time" 5 | 6 | . "github.com/onsi/ginkgo/v2" 7 | . "github.com/onsi/gomega" 8 | ) 9 | 10 | var _ = Describe("Websocket Client", Ordered, func() { 11 | var c *WebSocketClient 12 | var hc *WebSocketHealthCheckClient 13 | var err error 14 | 15 | BeforeEach(func() { 16 | cleanUp := startFlow("examples/websocket/flow.yml") 17 | time.Sleep(2 * time.Second) 18 | DeferCleanup(func() { 19 | *c = WebSocketClient{} 20 | cleanUp() 21 | }) 22 | }) 23 | 24 | Describe("Create the Client and stream requests", func() { 25 | It("should create a new WebSocketClient & stream requests", func() { 26 | Eventually(func() error { 27 | c, err = NewWebSocketClient("ws://localhost:12345") 28 | return err 29 | }, 10*time.Second, 1*time.Second).Should(BeNil()) 30 | Expect(c).NotTo(BeNil()) 31 | c.POST(generateDataRequests(3), OnDone, OnError, nil) 32 | }) 33 | }) 34 | 35 | Describe("Create the Client and stream requests sequentially", func() { 36 | It("should create a new WebSocketClient & stream requests", func() { 37 | Eventually(func() error { 38 | c, err = NewWebSocketClient("ws://localhost:12345") 39 | return err 40 | }, 10*time.Second, 1*time.Second).Should(BeNil()) 41 | Expect(c).NotTo(BeNil()) 42 | c.SequentialPOST(generateDataRequests(3), OnDone, OnError, nil) 43 | }) 44 | }) 45 | 46 | Describe("Perform healthchecks on the client", func() { 47 | It("should create a new WebSocketHealthCheckClient & perform a successful healthcheck", func() { 48 | Eventually(func() error { 49 | hc, err = NewWebSocketHealthCheckClient("ws://localhost:12345") 50 | return err 51 | }, 10*time.Second, 1*time.Second).Should(BeNil()) 52 | Expect(hc).NotTo(BeNil()) 53 | 54 | Eventually(func() bool { 55 | status, _ := hc.HealthCheck() 56 | return status 57 | }, 10*time.Second, 1*time.Second).Should(BeTrue()) 58 | }) 59 | }) 60 | }) 61 | --------------------------------------------------------------------------------