├── .dockerignore ├── .github └── workflows │ └── build.yml ├── .gitignore ├── .goreleaser.yml ├── LICENSE.md ├── Makefile ├── README.md ├── disclaimer.txt ├── docker ├── Dockerfile └── ci.Dockerfile ├── docs ├── exchanges │ └── kucoin.md └── ops │ ├── freqtrade-docker-compose.yml │ └── freqtrade.md ├── go.mod ├── go.sum ├── main.go ├── model └── model.go ├── proxy ├── client.go ├── config.go ├── handler.go ├── kucoin │ ├── config.go │ ├── http.go │ ├── util.go │ ├── wire.go │ └── ws.go └── router.go └── store ├── candles_linked_list.go ├── candles_store.go └── ttl_cache.go /.dockerignore: -------------------------------------------------------------------------------- 1 | .idea 2 | dist/ 3 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout 13 | uses: actions/checkout@v2 14 | with: 15 | fetch-depth: 0 16 | 17 | - name: Set up Go 18 | uses: actions/setup-go@v2 19 | with: 20 | go-version: 1.21 21 | 22 | - name: Cache Go modules 23 | uses: actions/cache@v1 24 | with: 25 | path: ~/go/pkg/mod 26 | key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} 27 | restore-keys: | 28 | ${{ runner.os }}-go- 29 | 30 | - name: EasyJson 31 | run: | 32 | go get github.com/mailru/easyjson && go install github.com/mailru/easyjson/...@latest 33 | go mod tidy 34 | make generate 35 | 36 | - name: Lint 37 | run: | 38 | go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest 39 | make lint 40 | 41 | - name: Set up QEMU 42 | uses: docker/setup-qemu-action@v1 43 | 44 | - name: Set up Docker Buildx 45 | uses: docker/setup-buildx-action@v1 46 | 47 | - name: Docker Login 48 | uses: docker/login-action@v1 49 | with: 50 | username: ${{ secrets.DOCKER_HUB_USERNAME }} 51 | password: ${{ secrets.DOCKER_HUB_TOKEN }} 52 | 53 | - name: Run GoReleaser 54 | uses: goreleaser/goreleaser-action@v2 55 | if: success() && startsWith(github.ref, 'refs/tags/') 56 | with: 57 | version: latest 58 | args: release --clean 59 | env: 60 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 61 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | dist/ 3 | **/*_easyjson.go 4 | -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | # This is an example .goreleaser.yml file with some sensible defaults. 2 | # Make sure to check the documentation at https://goreleaser.com 3 | before: 4 | hooks: 5 | - go mod tidy 6 | builds: 7 | - env: 8 | - CGO_ENABLED=0 9 | ldflags: 10 | - -s -w -X main.version={{ .Version }} 11 | goos: 12 | - linux 13 | - windows 14 | - darwin 15 | goarch: 16 | - amd64 17 | - arm 18 | - arm64 19 | goarm: 20 | - 6 21 | - 7 22 | ignore: 23 | - goos: windows 24 | goarch: arm 25 | goarm: 7 26 | - goos: windows 27 | goarch: arm 28 | goarm: 6 29 | - goos: windows 30 | goarch: arm64 31 | changelog: 32 | sort: asc 33 | filters: 34 | exclude: 35 | - '^docs:' 36 | - '^test:' 37 | release: 38 | github: 39 | owner: mikekonan 40 | name: exchange-proxy 41 | draft: true 42 | name_template: "{{.ProjectName}}-v{{.Version}}" 43 | 44 | dockers: 45 | - image_templates: 46 | - mikekonan/exchange-proxy:latest-amd64 47 | - mikekonan/exchange-proxy:{{ .Version }}-amd64 48 | dockerfile: docker/ci.Dockerfile 49 | use: buildx 50 | goos: linux 51 | goarch: amd64 52 | build_flag_templates: 53 | - "--build-arg=VERSION={{ .Version }}" 54 | - "--platform=linux/amd64" 55 | 56 | - image_templates: 57 | - mikekonan/exchange-proxy:latest-arm64 58 | - mikekonan/exchange-proxy:{{ .Version }}-arm64 59 | dockerfile: docker/ci.Dockerfile 60 | use: buildx 61 | goos: linux 62 | goarch: arm64 63 | build_flag_templates: 64 | - "--build-arg=VERSION={{ .Version }}" 65 | - "--platform=linux/arm64" 66 | 67 | - image_templates: 68 | - mikekonan/exchange-proxy:latest-arm-v7 69 | - mikekonan/exchange-proxy:{{ .Version }}-arm-v7 70 | dockerfile: docker/ci.Dockerfile 71 | use: buildx 72 | goos: linux 73 | goarch: arm 74 | goarm: 7 75 | build_flag_templates: 76 | - "--build-arg=VERSION={{ .Version }}" 77 | - "--platform=linux/arm/v7" 78 | 79 | - image_templates: 80 | - mikekonan/exchange-proxy:latest-arm-v6 81 | - mikekonan/exchange-proxy:{{ .Version }}-arm-v6 82 | dockerfile: docker/ci.Dockerfile 83 | use: buildx 84 | goos: linux 85 | goarch: arm 86 | goarm: 6 87 | build_flag_templates: 88 | - "--build-arg=VERSION={{ .Version }}" 89 | - "--platform=linux/arm/v6" 90 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: help lint build clean clean-generated generate 2 | 3 | .DEFAULT_GOAL := help 4 | 5 | generate: clean-generated ## generate 6 | go generate ./... 7 | go fmt ./... 8 | 9 | build: generate ## build binaries 10 | go build -trimpath -o ./dist/exchange-proxy 11 | 12 | clean-generated: ## clean generated 13 | find . -name '*_easyjson.go' -delete 14 | 15 | clean: ## clean 16 | rm -rf ./dist/exchange-proxy* 17 | find . -name '*_easyjson.go' -delete 18 | 19 | lint: ## lint 20 | golangci-lint run --path-prefix $(PWD) 21 | 22 | help: 23 | @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # exchange-proxy 2 | 3 | Exchange proxy using WebSockets to maintain candlestick/klines data in memory, thus having great performance, reducing the number of API calls to the exchange API, decreases latency and CPU usage. 4 | There is no warranty of correct working. You take all risks of using this. 5 | All improvements are made by me on a voluntary basis in my spare time. 6 | 7 | ## OPS 8 | 9 | ### Usage 10 | ```shell 11 | Usage of ./dist/exchange-proxy: 12 | -bindaddr string 13 | bindable address (default "0.0.0.0") 14 | -cache-size int 15 | amount of candles to cache (default 1000) 16 | -client-timeout duration 17 | client timeout (default 15s) 18 | -concurrency-limit int 19 | server concurrency limit (default 262144) 20 | -kucoin-api-url string 21 | kucoin api address (default "https://openapi-v2.kucoin.com") 22 | -kucoin-topics-per-ws int 23 | amount of topics per ws connection [10-280] (default 200) 24 | -port string 25 | listen port (default "8080") 26 | -ttl-cache-timeout duration 27 | ttl of blobs of cached data (default 10m0s) 28 | -verbose int 29 | verbose level: 0 - info, 1 - debug, 2 - trace 30 | ``` 31 | 32 | #### Note 33 | All unforeseen connection errors or the inaccessibility of the exchange will lead to the proxy crash, which means that you have to handle it on your end 34 | 35 | ### Local 36 | ```shell 37 | ./exchange-proxy -port 8080 38 | ``` 39 | 40 | ### Docker (suggested way) 41 | 42 | ###### Use different tags for different platforms e.g. - latest-amd64, latest-arm-v6, latest-arm-v7, latest-arm64 43 | 44 | ```shell 45 | docker run --restart=always -p 127.0.0.1:8080:8080 --name exchange-proxy -d mikekonan/exchange-proxy:latest-amd64 46 | ``` 47 | 48 | #### Examples of usage: 49 | - [freqtrade](./docs/ops/freqtrade.md) 50 | 51 | # Supported exchanges: 52 | - [Kucoin](./docs/exchanges/kucoin.md) 53 | 54 | ## Donations 55 | 56 | Donations are appreciated and will make me motivated to support and improve the project. 57 | 58 | - USDT TRC20 - TYssA3EUfAagJ9afF6vfwJvwwueTafMbGY 59 | - XRP - rNFugeoj3ZN8Wv6xhuLegUBBPXKCyWLRkB 1869777767 60 | - DOGE - D6xwe5V9jRkvWksiHiajwZsJ3KJxBVqBUC 61 | - BTC - 35SrQDWAfwXcRGHaKbxNWwvHRNSLAbVjrk 62 | - ETH - 0x37c34bac13cf60f022be1bdea2dec1136cdc838a 63 | 64 | 65 | ### Referral links: 66 | - [Kucoin](https://www.kucoin.com/ucenter/signup?rcode=rJ327D3) 67 | 68 | - [Okex](https://www.okex.com/join/3941527) 69 | 70 | - [Gate.io](https://www.gate.io/signup/3325373) 71 | 72 | - [Currency.com](https://currency.com/trading/signup?c=ciqjuj5y&pid=referral) 73 | -------------------------------------------------------------------------------- /disclaimer.txt: -------------------------------------------------------------------------------- 1 | ############################################################################################################################## 2 | # You are running an exchange proxy that uses WebSockets to maintain candlestick/klines data in memory, # 3 | # thus having great performance, reducing the number of API calls to the exchange API, decreases latency and CPU usage. # 4 | # # 5 | # There is no warranty of correct working. You take all risks of using this. # 6 | # # 7 | # All improvements are made by me on a voluntary basis in my spare time. # 8 | # # 9 | # Consider donating to support the project: # 10 | # USDT TRC20 - TYssA3EUfAagJ9afF6vfwJvwwueTafMbGY # 11 | # XRP - rNFugeoj3ZN8Wv6xhuLegUBBPXKCyWLRkB 1869777767 # 12 | # DOGE - D6xwe5V9jRkvWksiHiajwZsJ3KJxBVqBUC # 13 | # BTC - 35SrQDWAfwXcRGHaKbxNWwvHRNSLAbVjrk # 14 | # ETH - 0x37c34bac13cf60f022be1bdea2dec1136cdc838a # 15 | # # 16 | # Referral links: # 17 | # Kucoin - https://www.kucoin.com/ucenter/signup?rcode=rJ327D3 # 18 | # Okex - https://www.okex.com/join/3941527 # 19 | # Gate.io - https://www.gate.io/signup/3325373 # 20 | # Currency.com - https://currency.com/trading/signup?c=ciqjuj5y&pid=referral # 21 | ############################################################################################################################## 22 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.21-alpine3.18 as builder 2 | 3 | RUN apk --no-cache add gcc musl-dev make && go get github.com/mailru/easyjson && go install github.com/mailru/easyjson/...@latest 4 | 5 | COPY . /src 6 | 7 | ARG VERSION=dev 8 | 9 | RUN cd /src && make generate && go build -o /src/bin/proxy -ldflags "-s -w -X main.version=$VERSION" 10 | 11 | FROM alpine:3.18 12 | 13 | RUN adduser -g "proxy" -D -H proxy proxy 14 | 15 | RUN apk --no-cache add ca-certificates \ 16 | && rm -rf /var/cache/apk/* 17 | 18 | COPY --from=builder /src/bin/proxy /bin/proxy 19 | 20 | USER proxy 21 | 22 | EXPOSE 8080 23 | 24 | ENTRYPOINT ["/bin/proxy"] 25 | -------------------------------------------------------------------------------- /docker/ci.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.15 2 | 3 | RUN adduser -g "proxy" -D -H proxy proxy 4 | 5 | RUN apk --no-cache add ca-certificates \ 6 | && rm -rf /var/cache/apk/* 7 | 8 | COPY exchange-proxy /bin/proxy 9 | 10 | USER proxy 11 | 12 | EXPOSE 8080 13 | 14 | ENTRYPOINT ["/bin/proxy"] 15 | -------------------------------------------------------------------------------- /docs/exchanges/kucoin.md: -------------------------------------------------------------------------------- 1 | # Kucoin 2 | 3 | API docs: 4 | 5 | - [Kucoin API docs](https://docs.kucoin.com) 6 | 7 | ## Proxy paths: 8 | 9 | | Path | Methods | Comment | 10 | |---------------------------|---------|---------------------------------------| 11 | | /api/v1/market/candles | GET | cached in application store in memory | 12 | | /api/v1/market/allTickers | GET | cached as blob in memory | 13 | | /api/v1/currencies | GET | cached as blob in memory | 14 | | /api/v1/symbols | GET | cached as blob in memory | 15 | | * | ANY | proxied transparently | 16 | 17 | ## Configuration 18 | 19 | | Param | Comment | 20 | |----------------------|----------------------------------------------------------------------------| 21 | | kucoin-api-url | kucoin api base URL | 22 | | kucoin-topics-per-ws | amount of topics per ws connection. **recommended value between 100-250 ** | 23 | | cache-size | number of candles in application memory per {pair_tf} | 24 | | ttl-cache-timeout | cache blobs ttl | 25 | -------------------------------------------------------------------------------- /docs/ops/freqtrade-docker-compose.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: '3' 3 | services: 4 | freqtrade: 5 | image: freqtradeorg/freqtrade:stable 6 | restart: unless-stopped 7 | container_name: freqtrade 8 | volumes: 9 | - "./user_data:/freqtrade/user_data" 10 | command: > 11 | trade 12 | --logfile /freqtrade/user_data/logs/freqtrade.log 13 | --db-url sqlite:////freqtrade/user_data/tradesv3.sqlite 14 | --config /freqtrade/user_data/config.json 15 | --strategy SampleStrategy 16 | 17 | exchange-proxy: 18 | image: mikekonan/exchange-proxy:latest-amd64 19 | restart: unless-stopped 20 | command: -verbose 1 21 | container_name: github.com/mikekonan/exchange-proxy-proxy 22 | -------------------------------------------------------------------------------- /docs/ops/freqtrade.md: -------------------------------------------------------------------------------- 1 | # Freqtrade OPS 2 | 3 | ### Local 4 | 5 | ```shell 6 | git clone https://github.com/mikekonan/exchange-proxy.git 7 | make build 8 | ./exchange-proxy -port 8080 -verbose 1 9 | ``` 10 | 11 | #### config.json 12 | 13 | ```json 14 | { 15 | "exchange": { 16 | "name": "kucoin", 17 | "key": "", 18 | "secret": "", 19 | "ccxt_config": { 20 | "enableRateLimit": false, 21 | "timeout": 60000, 22 | "urls": { 23 | "api": { 24 | "public": "http://127.0.0.1:8080/kucoin", 25 | "private": "http://127.0.0.1:8080/kucoin" 26 | } 27 | } 28 | }, 29 | "ccxt_async_config": { 30 | "enableRateLimit": false, 31 | "timeout": 60000 32 | } 33 | } 34 | } 35 | ``` 36 | 37 | ### Docker (suggested way) 38 | 39 | ###### Use different tags for different platforms e.g. - latest-amd64, latest-arm-v6, latest-arm-v7, latest-arm64 40 | 41 | ```shell 42 | docker run --restart=always -p 127.0.0.1:8080:8080 --name exchange-proxy -d mikekonan/exchange-proxy:latest-amd64 43 | ``` 44 | 45 | #### config.json 46 | 47 | ```json 48 | { 49 | "exchange": { 50 | "name": "kucoin", 51 | "key": "", 52 | "secret": "", 53 | "ccxt_config": { 54 | "enableRateLimit": false, 55 | "timeout": 60000, 56 | "urls": { 57 | "api": { 58 | "public": "http://127.0.0.1:8080/kucoin", 59 | "private": "http://127.0.0.1:8080/kucoin" 60 | } 61 | } 62 | }, 63 | "ccxt_async_config": { 64 | "enableRateLimit": false, 65 | "timeout": 60000 66 | } 67 | } 68 | } 69 | ``` 70 | 71 | ### Docker-compose (best way) 72 | 73 | ###### Use different tags for different platforms e.g. - latest-amd64, latest-arm-v6, latest-arm-v7, latest-arm64 74 | 75 | See example - [docker-compose.yml](freqtrade-docker-compose.yml) 76 | 77 | ```yaml 78 | exchange-proxy: 79 | image: mikekonan/exchange-proxy:latest-amd64 80 | restart: unless-stopped 81 | container_name: exchange-proxy 82 | command: -verbose 1 83 | ``` 84 | 85 | #### config.json 86 | 87 | ```json 88 | { 89 | "exchange": { 90 | "name": "kucoin", 91 | "key": "", 92 | "secret": "", 93 | "ccxt_config": { 94 | "enableRateLimit": false, 95 | "timeout": 60000, 96 | "urls": { 97 | "api": { 98 | "public": "http://exchange-proxy:8080/kucoin", 99 | "private": "http://exchange-proxy:8080/kucoin" 100 | } 101 | } 102 | }, 103 | "ccxt_async_config": { 104 | "enableRateLimit": false, 105 | "timeout": 60000 106 | } 107 | } 108 | } 109 | ``` 110 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/mikekonan/exchange-proxy 2 | 3 | go 1.21 4 | 5 | require ( 6 | github.com/Gurpartap/logrus-stack v0.0.0-20170710170904-89c00d8a28f4 7 | github.com/dgrr/websocket v0.1.1 8 | github.com/go-ozzo/ozzo-validation/v4 v4.3.0 9 | github.com/google/uuid v1.3.0 10 | github.com/jaffee/commandeer v0.5.0 11 | github.com/mailru/easyjson v0.7.7 12 | github.com/qiangxue/fasthttp-routing v0.0.0-20160225050629-6ccdc2a18d87 13 | github.com/sirupsen/logrus v1.4.1 14 | github.com/spf13/cast v1.3.0 15 | github.com/valyala/fasthttp v1.29.0 16 | go.uber.org/ratelimit v0.2.0 17 | ) 18 | 19 | require ( 20 | github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect 21 | github.com/andybalholm/brotli v1.0.2 // indirect 22 | github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 // indirect 23 | github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect 24 | github.com/go-ozzo/ozzo-routing v2.1.4+incompatible // indirect 25 | github.com/golang/gddo v0.0.0-20210115222349-20d68f94ee1f // indirect 26 | github.com/josharian/intern v1.0.0 // indirect 27 | github.com/klauspost/compress v1.13.4 // indirect 28 | github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect 29 | github.com/stretchr/testify v1.7.0 // indirect 30 | github.com/valyala/bytebufferpool v1.0.0 // indirect 31 | golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect 32 | ) 33 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.16.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 3 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 4 | github.com/Gurpartap/logrus-stack v0.0.0-20170710170904-89c00d8a28f4 h1:vdT7QwBhJJEVNFMBNhRSFDRCB6O16T28VhvqRgqFyn8= 5 | github.com/Gurpartap/logrus-stack v0.0.0-20170710170904-89c00d8a28f4/go.mod h1:SvXOG8ElV28oAiG9zv91SDe5+9PfIr7PPccpr8YyXNs= 6 | github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= 7 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 8 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 9 | github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 h1:MzBOUgng9orim59UnfUTLRjMpd09C5uEVQ6RPGeCaVI= 10 | github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129/go.mod h1:rFgpPQZYZ8vdbc+48xibu8ALc3yeyd64IhHS+PU6Yyg= 11 | github.com/andybalholm/brotli v1.0.2 h1:JKnhI/XQ75uFBTiuzXpzFrUriDPiZjlOSzh6wXogP0E= 12 | github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= 13 | github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= 14 | github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496 h1:zV3ejI06GQ59hwDQAvmK1qxOQGB3WuVTRoY0okPTAv0= 15 | github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496/go.mod h1:oGkLhpf+kjZl6xBf758TQhh5XrAeiJv/7FRz/2spLIg= 16 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 17 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 18 | github.com/bradfitz/gomemcache v0.0.0-20170208213004-1952afaa557d/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60= 19 | github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= 20 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 21 | github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= 22 | github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= 23 | github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= 24 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= 25 | github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= 26 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 27 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 28 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 29 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 30 | github.com/dgrr/websocket v0.1.1 h1:fg6irjiUyGRmqzJ1vwy3vRPv6PlIO7+eF4Q7oi+WDAo= 31 | github.com/dgrr/websocket v0.1.1/go.mod h1:d30hG8q3dQuz6eSwROXzIodSvPTNi52j1VvxrK7RWXc= 32 | github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= 33 | github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A= 34 | github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg= 35 | github.com/fsnotify/fsnotify v1.4.3-0.20170329110642-4da3e2cfbabc/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 36 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 37 | github.com/garyburd/redigo v1.1.1-0.20170914051019-70e1b1943d4f/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY= 38 | github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= 39 | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= 40 | github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= 41 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 42 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 43 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 44 | github.com/go-ozzo/ozzo-routing v2.1.4+incompatible h1:gQmNyAwMnBHr53Nma2gPTfVVc6i2BuAwCWPam2hIvKI= 45 | github.com/go-ozzo/ozzo-routing v2.1.4+incompatible/go.mod h1:hvoxy5M9SJaY0viZvcCsODidtUm5CzRbYKEWuQpr+2A= 46 | github.com/go-ozzo/ozzo-validation/v4 v4.3.0 h1:byhDUpfEwjsVQb1vBunvIjh2BHQ9ead57VkAEY4V+Es= 47 | github.com/go-ozzo/ozzo-validation/v4 v4.3.0/go.mod h1:2NKgrcHl3z6cJs+3Oo940FPRiTzuqKbvfrL2RxCj6Ew= 48 | github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= 49 | github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= 50 | github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= 51 | github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= 52 | github.com/go-stack/stack v1.6.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 53 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 54 | github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= 55 | github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= 56 | github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= 57 | github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= 58 | github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= 59 | github.com/gobwas/ws v1.0.4 h1:5eXU1CZhpQdq5kXbKb+sECH5Ia5KiO6CYzIzdlVx6Bs= 60 | github.com/gobwas/ws v1.0.4/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= 61 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 62 | github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= 63 | github.com/golang/gddo v0.0.0-20210115222349-20d68f94ee1f h1:16RtHeWGkJMc80Etb8RPCcKevXGldr57+LOyZt8zOlg= 64 | github.com/golang/gddo v0.0.0-20210115222349-20d68f94ee1f/go.mod h1:ijRvpgDJDI262hYq/IQVYgf8hd8IHUs93Ol0kvMBAx4= 65 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 66 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 67 | github.com/golang/lint v0.0.0-20170918230701-e5d664eb928e/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E= 68 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 69 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 70 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 71 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 72 | github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= 73 | github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= 74 | github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= 75 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 76 | github.com/google/go-cmp v0.1.1-0.20171103154506-982329095285/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 77 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 78 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 79 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 80 | github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= 81 | github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 82 | github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= 83 | github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= 84 | github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 85 | github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= 86 | github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 87 | github.com/gregjones/httpcache v0.0.0-20170920190843-316c5e0ff04e/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= 88 | github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= 89 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= 90 | github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= 91 | github.com/hashicorp/hcl v0.0.0-20170914154624-68e816d1c783/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w= 92 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 93 | github.com/inconshreveable/log15 v0.0.0-20170622235902-74a0988b5f80/go.mod h1:cOaXtrgN4ScfRrD9Bre7U1thNq5RtJ8ZoP4iXVGRj6o= 94 | github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= 95 | github.com/jaffee/commandeer v0.5.0 h1:241M9N+gHQmPyjIG+yy8GGcZPfzFuIyOmJHzm5ka92g= 96 | github.com/jaffee/commandeer v0.5.0/go.mod h1:kCwfuSvZ2T0NVEr3LDSo6fDUgi0xSBnAVDdkOKTtpLQ= 97 | github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= 98 | github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= 99 | github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= 100 | github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 101 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 102 | github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= 103 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 104 | github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= 105 | github.com/klauspost/compress v1.12.2/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= 106 | github.com/klauspost/compress v1.13.4 h1:0zhec2I8zGnjWcKyLl6i3gPqKANCCn5e9xmviEEeX6s= 107 | github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= 108 | github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= 109 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 110 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 111 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 112 | github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 113 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 114 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 115 | github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= 116 | github.com/magiconair/properties v1.7.4-0.20170902060319-8d7837e64d3c/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= 117 | github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= 118 | github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= 119 | github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= 120 | github.com/mattn/go-colorable v0.0.10-0.20170816031813-ad5389df28cd/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= 121 | github.com/mattn/go-isatty v0.0.2/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= 122 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 123 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 124 | github.com/mitchellh/mapstructure v0.0.0-20170523030023-d0303fe80992/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 125 | github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 126 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 127 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 128 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 129 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= 130 | github.com/pelletier/go-toml v1.0.1-0.20170904195809-1d6b12b7cb29/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 131 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 132 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 133 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 134 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 135 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 136 | github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= 137 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 138 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 139 | github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= 140 | github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 141 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 142 | github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 143 | github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= 144 | github.com/qiangxue/fasthttp-routing v0.0.0-20160225050629-6ccdc2a18d87 h1:u7uCM+HS2caoEKSPtSFQvvUDXQtqZdu3MYtF+QEw7vA= 145 | github.com/qiangxue/fasthttp-routing v0.0.0-20160225050629-6ccdc2a18d87/go.mod h1:zwr0xP4ZJxwCS/g2d+AUOUwfq/j2NC7a1rK3F0ZbVYM= 146 | github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= 147 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 148 | github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= 149 | github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= 150 | github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= 151 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= 152 | github.com/spf13/afero v0.0.0-20170901052352-ee1bd8ee15a1/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= 153 | github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= 154 | github.com/spf13/cast v1.1.0/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgKEg= 155 | github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= 156 | github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= 157 | github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= 158 | github.com/spf13/jwalterweatherman v0.0.0-20170901151539-12bd96e66386/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= 159 | github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= 160 | github.com/spf13/pflag v1.0.1-0.20170901120850-7aff26db30c1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 161 | github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= 162 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 163 | github.com/spf13/viper v1.0.0/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM= 164 | github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= 165 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 166 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 167 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 168 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 169 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 170 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 171 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 172 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 173 | github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= 174 | github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= 175 | github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= 176 | github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= 177 | github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= 178 | github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= 179 | github.com/valyala/fasthttp v1.28.0/go.mod h1:cmWIqlu99AO/RKcp1HWaViTqc57FswJOfYYdPJBl8BA= 180 | github.com/valyala/fasthttp v1.29.0 h1:F5GKpytwFk5OhCuRh6H+d4vZAcEeNAwPTdwQnm6IERY= 181 | github.com/valyala/fasthttp v1.29.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus= 182 | github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= 183 | github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= 184 | github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= 185 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= 186 | go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= 187 | go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= 188 | go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= 189 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= 190 | go.uber.org/ratelimit v0.2.0 h1:UQE2Bgi7p2B85uP5dC2bbRtig0C+OeNRnNEafLjsLPA= 191 | go.uber.org/ratelimit v0.2.0/go.mod h1:YYBV4e4naJvhpitQrWJu1vCpgB7CboMe0qhltKt6mUg= 192 | go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= 193 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 194 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 195 | golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= 196 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 197 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 198 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 199 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 200 | golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 201 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 202 | golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 203 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 204 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 205 | golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 206 | golang.org/x/oauth2 v0.0.0-20170912212905-13449ad91cb2/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 207 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 208 | golang.org/x/sync v0.0.0-20170517211232-f52d1811a629/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 209 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 210 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 211 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 212 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 213 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 214 | golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 215 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 216 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 217 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 218 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 219 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 220 | golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 221 | golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac h1:oN6lz7iLW/YC7un8pq+9bOLyXrprv2+DKfkJY+2LJJw= 222 | golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 223 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 224 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 225 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 226 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 227 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 228 | golang.org/x/time v0.0.0-20170424234030-8be79e1e0910/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 229 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 230 | golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 231 | golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 232 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 233 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 234 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 235 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 236 | google.golang.org/api v0.0.0-20170921000349-586095a6e407/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= 237 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 238 | google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= 239 | google.golang.org/genproto v0.0.0-20170918111702-1e559d0a00ee/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 240 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 241 | google.golang.org/grpc v1.2.1-0.20170921194603-d4b75ebd4f9f/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= 242 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 243 | google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 244 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 245 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 246 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 247 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 248 | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= 249 | gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= 250 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 251 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 252 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 253 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 254 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 255 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 256 | nhooyr.io/websocket v1.8.6 h1:s+C3xAMLwGmlI31Nyn/eAehUlZPwfYZu2JXM621Q5/k= 257 | nhooyr.io/websocket v1.8.6/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0= 258 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "embed" 5 | "fmt" 6 | "os" 7 | "time" 8 | 9 | logrusStack "github.com/Gurpartap/logrus-stack" 10 | "github.com/jaffee/commandeer" 11 | "github.com/mikekonan/exchange-proxy/proxy" 12 | "github.com/mikekonan/exchange-proxy/proxy/kucoin" 13 | "github.com/mikekonan/exchange-proxy/store" 14 | "github.com/sirupsen/logrus" 15 | "github.com/valyala/fasthttp" 16 | ) 17 | 18 | var ( 19 | //go:embed disclaimer.txt 20 | disclaimer string 21 | 22 | version = "dev" 23 | ) 24 | 25 | type app struct { 26 | Verbose int `help:"verbose level: 0 - info, 1 - debug, 2 - trace"` 27 | CacheSize int `help:"amount of candles to cache"` 28 | TTLCacheTimeout time.Duration `help:"ttl of blobs of cached data"` 29 | ClientTimeout time.Duration `help:"client timeout"` 30 | 31 | ProxyConfig proxy.Config `flag:"!embed"` 32 | KucoinConfig kucoin.Config `flag:"!embed"` 33 | } 34 | 35 | func newApp() *app { 36 | return &app{ 37 | Verbose: 0, 38 | CacheSize: 1000, 39 | TTLCacheTimeout: time.Minute * 10, 40 | ClientTimeout: time.Second * 15, 41 | KucoinConfig: kucoin.Config{ 42 | KucoinTopicsPerWs: 200, 43 | KucoinApiURL: "https://openapi-v2.kucoin.com", 44 | }, 45 | ProxyConfig: proxy.Config{ 46 | Port: "8080", 47 | Bindaddr: "0.0.0.0", 48 | ConcurrencyLimit: fasthttp.DefaultConcurrency, 49 | }, 50 | } 51 | } 52 | 53 | func (app *app) configure() { 54 | switch app.Verbose { 55 | case 0: 56 | logrus.SetLevel(logrus.InfoLevel) 57 | case 1: 58 | logrus.SetLevel(logrus.DebugLevel) 59 | case 2: 60 | logrus.SetLevel(logrus.TraceLevel) 61 | } 62 | } 63 | 64 | func (app *app) Run() error { 65 | logrus.SetOutput(os.Stdout) 66 | logrus.AddHook(logrusStack.StandardHook()) 67 | 68 | fmt.Println(disclaimer) 69 | 70 | logrus.Infof("starting exchange-proxy: version - '%s'... ", version) 71 | 72 | if app.Verbose > 2 { 73 | return fmt.Errorf("wrong verbose level '%d'", app.Verbose) 74 | } 75 | 76 | app.configure() 77 | 78 | if err := app.ProxyConfig.Validate(); err != nil { 79 | return err 80 | } 81 | 82 | if err := app.KucoinConfig.Validate(); err != nil { 83 | return err 84 | } 85 | 86 | client := &proxy.Client{ 87 | Client: fasthttp.Client{ 88 | ReadTimeout: app.ClientTimeout, 89 | WriteTimeout: app.ClientTimeout, 90 | }, 91 | } 92 | 93 | proxySrv := proxy.New(&app.ProxyConfig, 94 | kucoin.New( 95 | store.NewStore(app.CacheSize), 96 | store.NewTTLCache(app.TTLCacheTimeout), 97 | client, 98 | &app.KucoinConfig, 99 | ), 100 | ) 101 | 102 | proxySrv.Serve() 103 | 104 | return nil 105 | } 106 | 107 | func main() { 108 | app := newApp() 109 | 110 | if err := commandeer.Run(app); err != nil { 111 | logrus.Fatal(err) 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /model/model.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | type Candle struct { 8 | Ts time.Time 9 | Open float64 10 | High float64 11 | Low float64 12 | Close float64 13 | Volume float64 14 | Amount float64 15 | } 16 | 17 | func (c *Candle) Clone() *Candle { 18 | return &Candle{ 19 | Ts: c.Ts, 20 | Open: c.Open, 21 | High: c.High, 22 | Low: c.Low, 23 | Close: c.Close, 24 | Volume: c.Volume, 25 | Amount: c.Amount, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /proxy/client.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | 7 | "github.com/sirupsen/logrus" 8 | "github.com/valyala/fasthttp" 9 | ) 10 | 11 | var ( 12 | strLocation = []byte("Location") 13 | ) 14 | 15 | type Client struct { 16 | fasthttp.Client 17 | } 18 | 19 | func (c *Client) Do(req *fasthttp.Request, resp *fasthttp.Response) error { 20 | for { 21 | if err := c.Client.Do(req, resp); err != nil { 22 | return err 23 | } 24 | 25 | statusCode := resp.Header.StatusCode() 26 | if statusCode != fasthttp.StatusMovedPermanently && 27 | statusCode != fasthttp.StatusFound && 28 | statusCode != fasthttp.StatusSeeOther && 29 | statusCode != fasthttp.StatusTemporaryRedirect && 30 | statusCode != fasthttp.StatusPermanentRedirect { 31 | break 32 | } 33 | 34 | location := resp.Header.PeekBytes(strLocation) 35 | if len(location) == 0 { 36 | return fmt.Errorf("redirect with missing Location header") 37 | } 38 | 39 | u := req.URI() 40 | u.UpdateBytes(location) 41 | 42 | resp.Header.VisitAllCookie(func(key, value []byte) { 43 | c := fasthttp.AcquireCookie() 44 | defer fasthttp.ReleaseCookie(c) 45 | 46 | if err := c.ParseBytes(value); err != nil { 47 | logrus.Fatal(err) 48 | } 49 | 50 | if expire := c.Expire(); expire != fasthttp.CookieExpireUnlimited && expire.Before(time.Now()) { 51 | req.Header.DelCookieBytes(key) 52 | } else { 53 | req.Header.SetCookieBytesKV(key, c.Value()) 54 | } 55 | }) 56 | } 57 | 58 | return nil 59 | } 60 | -------------------------------------------------------------------------------- /proxy/config.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | validation "github.com/go-ozzo/ozzo-validation/v4" 5 | "github.com/go-ozzo/ozzo-validation/v4/is" 6 | "github.com/valyala/fasthttp" 7 | ) 8 | 9 | type Config struct { 10 | Port string `help:"listen port"` 11 | Bindaddr string `help:"bindable address"` 12 | ConcurrencyLimit int `help:"server concurrency limit"` 13 | } 14 | 15 | func (c Config) Validate() error { 16 | return validation.ValidateStruct(&c, 17 | validation.Field(&c.Port, is.Port), 18 | validation.Field(&c.Bindaddr, is.IPv4), 19 | validation.Field(&c.ConcurrencyLimit, validation.Min(fasthttp.DefaultConcurrency)), 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /proxy/handler.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "bytes" 5 | "net/http" 6 | 7 | "github.com/mikekonan/exchange-proxy/store" 8 | routing "github.com/qiangxue/fasthttp-routing" 9 | "github.com/sirupsen/logrus" 10 | "github.com/valyala/fasthttp" 11 | ) 12 | 13 | var ( 14 | contentTypeBytes = []byte("application/json") 15 | contentEncodingHeaderBytes = []byte("Content-Encoding") 16 | gzipHeaderBytes = []byte("gzip") 17 | ) 18 | 19 | type RequestURIFn func(c *routing.Context) string 20 | 21 | func TransparentHandler(requestURIFn func(c *routing.Context) string, client *Client) func(c *routing.Context) error { 22 | return func(c *routing.Context) error { 23 | logrus.Debugf("proxying over - %s", c.Request.RequestURI()) 24 | 25 | req := fasthttp.AcquireRequest() 26 | defer fasthttp.ReleaseRequest(req) 27 | c.Request.Header.CopyTo(&req.Header) 28 | 29 | req.SetRequestURI(requestURIFn(c)) 30 | 31 | req.SetBody(c.Request.Body()) 32 | 33 | resp := fasthttp.AcquireResponse() 34 | defer fasthttp.ReleaseResponse(resp) 35 | if err := client.Do(req, resp); err != nil { 36 | logrus.Error(err) 37 | return err 38 | } 39 | 40 | resp.Header.CopyTo(&c.Response.Header) 41 | c.Response.SetStatusCode(resp.StatusCode()) 42 | c.Response.SetBody(resp.Body()) 43 | 44 | return nil 45 | } 46 | } 47 | 48 | func TransparentOverCacheHandler(requestURIFn RequestURIFn, client *Client, store *store.TTLCache) func(c *routing.Context) error { 49 | return func(c *routing.Context) (err error) { 50 | logrus.Debugf("proxying over - %s", c.Request.RequestURI()) 51 | 52 | container := store.Get(string(c.Request.RequestURI())) 53 | if container != nil { 54 | c.Response.SetStatusCode(http.StatusOK) 55 | c.Response.SetBody(container.Raw()) 56 | c.Response.Header.SetContentTypeBytes(contentTypeBytes) 57 | c.Response.Header.SetContentLength(len(container.Raw())) 58 | 59 | return nil 60 | } 61 | 62 | req := fasthttp.AcquireRequest() 63 | defer fasthttp.ReleaseRequest(req) 64 | c.Request.Header.CopyTo(&req.Header) 65 | req.SetRequestURI(requestURIFn(c)) 66 | req.SetBody(c.Request.Body()) 67 | 68 | resp := fasthttp.AcquireResponse() 69 | defer fasthttp.ReleaseResponse(resp) 70 | if err := client.Do(req, resp); err != nil { 71 | logrus.Error(err) 72 | return err 73 | } 74 | 75 | var data []byte 76 | 77 | if bytes.Equal(resp.Header.PeekBytes(contentEncodingHeaderBytes), gzipHeaderBytes) { 78 | data, err = resp.BodyGunzip() 79 | if err != nil { 80 | return err 81 | } 82 | } else { 83 | data = resp.Body() 84 | } 85 | 86 | store.Store(string(c.Request.RequestURI()), data) 87 | 88 | c.Response.Header.SetContentTypeBytes(contentTypeBytes) 89 | c.Response.Header.SetContentLength(len(data)) 90 | c.Response.SetStatusCode(resp.StatusCode()) 91 | c.Response.SetBody(data) 92 | 93 | return nil 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /proxy/kucoin/config.go: -------------------------------------------------------------------------------- 1 | package kucoin 2 | 3 | import ( 4 | "github.com/go-ozzo/ozzo-validation/v4" 5 | "github.com/go-ozzo/ozzo-validation/v4/is" 6 | ) 7 | 8 | type Config struct { 9 | KucoinTopicsPerWs int `help:"amount of topics per ws connection [10-280]"` 10 | KucoinApiURL string `help:"kucoin api address"` 11 | //Localaddr string `help:"local address (use it if you understand what you are doing)"` 12 | } 13 | 14 | func (c Config) Validate() error { 15 | return validation.ValidateStruct(&c, 16 | validation.Field(&c.KucoinTopicsPerWs, validation.Min(10), validation.Max(280)), 17 | validation.Field(&c.KucoinApiURL, is.RequestURL), 18 | //validation.Field(&c.Localaddr, validation.When(c.Localaddr != "", is.IPv4)), 19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /proxy/kucoin/http.go: -------------------------------------------------------------------------------- 1 | package kucoin 2 | 3 | import ( 4 | "fmt" 5 | netHttp "net/http" 6 | "sync" 7 | "time" 8 | 9 | "github.com/mailru/easyjson" 10 | "github.com/mikekonan/exchange-proxy/proxy" 11 | "github.com/mikekonan/exchange-proxy/store" 12 | "github.com/qiangxue/fasthttp-routing" 13 | "github.com/sirupsen/logrus" 14 | "github.com/spf13/cast" 15 | "go.uber.org/ratelimit" 16 | ) 17 | 18 | const ( 19 | kLinesPath = "api/v1/market/candles" 20 | tickersPath = "api/v1/market/allTickers" 21 | currenciesPath = "api/v1/currencies" 22 | symbolsPath = "api/v1/symbols" 23 | ) 24 | 25 | func New(store *store.Store, ttlCache *store.TTLCache, client *proxy.Client, config *Config) *http { 26 | httpRl := ratelimit.New(15) 27 | 28 | instance := &http{ 29 | config: config, 30 | client: client, 31 | store: store, 32 | ttlCache: ttlCache, 33 | rl: httpRl, 34 | subscriber: &subscriber{ 35 | l: new(sync.Mutex), 36 | pool: nil, 37 | httpRl: httpRl, 38 | wsRl: ratelimit.New(9), 39 | subs: map[string]struct{}{}, 40 | config: config, 41 | client: client, 42 | store: store, 43 | }, 44 | } 45 | 46 | return instance 47 | } 48 | 49 | type http struct { 50 | client *proxy.Client 51 | 52 | store *store.Store 53 | ttlCache *store.TTLCache 54 | rl ratelimit.Limiter 55 | 56 | subscriber *subscriber 57 | config *Config 58 | } 59 | 60 | func (http *http) executeKLinesRequest(pair string, timeframe string, startAt int64, endAt int64) (int, *kLinesResponse, []byte, error) { 61 | path := fmt.Sprintf("%s/%s?type=%s&symbol=%s&startAt=%d&endAt=%d", http.config.KucoinApiURL, kLinesPath, timeframe, pair, startAt, endAt) 62 | 63 | statusCode, data, err := http.client.Get(nil, path) 64 | if err != nil { 65 | return statusCode, nil, nil, err 66 | } 67 | 68 | kLinesResponse := &kLinesResponse{} 69 | if err := easyjson.Unmarshal(data, kLinesResponse); err != nil { 70 | return statusCode, nil, data, err 71 | } 72 | 73 | return statusCode, kLinesResponse, data, nil 74 | } 75 | 76 | func (http *http) getKlines(pair string, timeframe string, startAt int64, endAt int64, retryCount int) (int, *kLinesResponse, []byte, error) { 77 | for i := 1; i <= retryCount; i++ { 78 | http.rl.Take() 79 | 80 | if statusCode, kLinesResponse, data, err := http.executeKLinesRequest(pair, timeframe, startAt, endAt); statusCode == 200 { 81 | return statusCode, kLinesResponse, data, nil 82 | } else { 83 | if i == retryCount { 84 | return statusCode, kLinesResponse, data, fmt.Errorf("get klines request '%s' '%s' '%d' '%d' exceeded retry '%d' attemts: %w", pair, timeframe, startAt, endAt, retryCount, err) 85 | } 86 | 87 | time.Sleep(time.Second) 88 | } 89 | } 90 | 91 | return 500, nil, nil, fmt.Errorf("retry count is zero") 92 | } 93 | 94 | func (http *http) transparentRequestURI(c *routing.Context) string { 95 | return fmt.Sprintf("%s/%s", http.config.KucoinApiURL, c.Request.URI().RequestURI()[8:]) 96 | } 97 | 98 | func (http *http) Name() string { 99 | return "kucoin" 100 | } 101 | 102 | func (http *http) Routes() []struct { 103 | Path string 104 | Method string 105 | Handler func(c *routing.Context) error 106 | } { 107 | 108 | return []struct { 109 | Path string 110 | Method string 111 | Handler func(c *routing.Context) error 112 | }{ 113 | { 114 | Path: tickersPath, 115 | Method: netHttp.MethodGet, 116 | Handler: proxy.TransparentOverCacheHandler(http.transparentRequestURI, http.client, http.ttlCache), 117 | }, 118 | 119 | { 120 | Path: currenciesPath, 121 | Method: netHttp.MethodGet, 122 | Handler: proxy.TransparentOverCacheHandler(http.transparentRequestURI, http.client, http.ttlCache), 123 | }, 124 | 125 | { 126 | Path: symbolsPath, 127 | Method: netHttp.MethodGet, 128 | Handler: proxy.TransparentOverCacheHandler(http.transparentRequestURI, http.client, http.ttlCache), 129 | }, 130 | 131 | { 132 | Path: kLinesPath, 133 | Method: netHttp.MethodGet, 134 | Handler: func(c *routing.Context) error { 135 | logrus.Debugf("proxying - %s", c.Request.RequestURI()) 136 | 137 | pair := string(c.Request.URI().QueryArgs().Peek("symbol")) 138 | timeframe := string(c.Request.URI().QueryArgs().Peek("type")) 139 | startAt := time.Unix(cast.ToInt64(string(c.Request.URI().QueryArgs().Peek("startAt"))), 0) 140 | endAt := time.Unix(cast.ToInt64(string(c.Request.URI().QueryArgs().Peek("endAt"))), 0) 141 | endAtAfterNow := endAt.After(time.Now().UTC().Add(-timeframeToDuration(timeframe))) 142 | 143 | candles := http.store.Get(storeKey(pair, timeframe), startAt, endAt) 144 | 145 | if len(candles) == 0 { 146 | statusCode, klinesResponse, data, err := http.getKlines(pair, timeframe, startAt.Unix(), endAt.Unix(), 15) 147 | 148 | c.Response.SetStatusCode(statusCode) 149 | c.Response.SetBody(data) 150 | 151 | if statusCode == 429 { 152 | return nil 153 | } 154 | 155 | if len(klinesResponse.Klines) == 0 { 156 | logrus.Warnf("there is no candle data from kucoin for - '%s'", c.Request.RequestURI()) 157 | } 158 | 159 | if endAtAfterNow { 160 | http.store.Store( 161 | storeKey(pair, timeframe), 162 | timeframeToDuration(timeframe), 163 | parseKLines(klinesResponse.Klines)..., 164 | ) 165 | 166 | if err == nil { 167 | go http.subscriber.subscribeKLines(pair, timeframe) 168 | } 169 | } 170 | 171 | return nil 172 | } 173 | 174 | data, err := easyjson.Marshal(genericResponse{Code: "200000", Data: candlesJSON(candles)}) 175 | 176 | if err != nil { 177 | return err 178 | } 179 | 180 | c.SetStatusCode(200) 181 | c.SetBody(data) 182 | 183 | return err 184 | }, 185 | }, 186 | 187 | { 188 | Path: "*", 189 | Method: proxy.AnyHTTPMethod, 190 | Handler: proxy.TransparentHandler(http.transparentRequestURI, http.client), 191 | }, 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /proxy/kucoin/util.go: -------------------------------------------------------------------------------- 1 | package kucoin 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "strconv" 7 | "time" 8 | 9 | "github.com/mikekonan/exchange-proxy/model" 10 | "github.com/spf13/cast" 11 | ) 12 | 13 | var ( 14 | startArrayJsonBytes = []byte(`[`) 15 | endArrayJsonBytes = []byte(`]`) 16 | ) 17 | 18 | func timeframeToDuration(timeframe string) time.Duration { 19 | switch timeframe { 20 | case "1min": 21 | return time.Minute 22 | case "3min": 23 | return time.Minute * 3 24 | case "5min": 25 | return time.Minute * 5 26 | case "15min": 27 | return time.Minute * 15 28 | case "30min": 29 | return time.Minute * 30 30 | case "1hour": 31 | return time.Hour 32 | case "2hour": 33 | return time.Hour * 2 34 | case "4hour": 35 | return time.Hour * 4 36 | case "6hour": 37 | return time.Hour * 6 38 | case "8hour": 39 | return time.Hour * 8 40 | case "12hour": 41 | return time.Hour * 12 42 | case "1day": 43 | return time.Hour * 24 44 | } 45 | 46 | return time.Hour * 24 * 7 47 | } 48 | 49 | func storeKey(pair string, tf string) string { 50 | return fmt.Sprintf("kucoin-%s-%s", pair, tf) 51 | } 52 | 53 | func parseCandle(candle kLine) *model.Candle { 54 | return &model.Candle{ 55 | Ts: time.Unix(cast.ToInt64(candle[0]), 0).UTC(), 56 | Open: cast.ToFloat64(candle[1]), 57 | High: cast.ToFloat64(candle[3]), 58 | Low: cast.ToFloat64(candle[4]), 59 | Close: cast.ToFloat64(candle[2]), 60 | Volume: cast.ToFloat64(candle[5]), 61 | Amount: cast.ToFloat64(candle[6]), 62 | } 63 | } 64 | 65 | func parseKLines(candlesModel kLines) []*model.Candle { 66 | candles := make([]*model.Candle, 0, len(candlesModel)) 67 | 68 | for _, c := range candlesModel { 69 | pc := parseCandle(*c) 70 | candles = append(candles, pc) 71 | } 72 | 73 | return candles 74 | } 75 | 76 | func floatFmt(f float64) string { 77 | return strconv.FormatFloat(f, 'f', -1, 64) 78 | } 79 | 80 | func candlesJSON(candles []*model.Candle) []byte { 81 | buff := bytes.NewBuffer(nil) 82 | buff.Write(startArrayJsonBytes) 83 | for _, c := range candles { 84 | buff.Write([]byte(fmt.Sprintf(`["%d","%s","%s","%s","%s","%s","%s"],`, c.Ts.Unix(), floatFmt(c.Open), floatFmt(c.Close), floatFmt(c.High), floatFmt(c.Low), floatFmt(c.Volume), floatFmt(c.Amount)))) 85 | } 86 | 87 | if len(candles) > 0 { 88 | buff.Truncate(buff.Len() - 1) 89 | } 90 | 91 | buff.Write(endArrayJsonBytes) 92 | 93 | return buff.Bytes() 94 | } 95 | 96 | func wsTopic(pair string, tf string) string { 97 | return fmt.Sprintf("%s_%s", pair, tf) 98 | } 99 | -------------------------------------------------------------------------------- /proxy/kucoin/wire.go: -------------------------------------------------------------------------------- 1 | package kucoin 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/google/uuid" 7 | ) 8 | 9 | //go:generate easyjson -lower_camel_case -omit_empty wire.go 10 | 11 | //easyjson:json 12 | type bulletPublicResponse struct { 13 | Code string `json:"code"` 14 | Data struct { 15 | Token string `json:"token"` 16 | InstanceServers []struct { 17 | Endpoint string `json:"endpoint"` 18 | Encrypt bool `json:"encrypt"` 19 | Protocol string `json:"protocol"` 20 | PingInterval int64 `json:"pingInterval"` 21 | PingTimeout int64 `json:"pingTimeout"` 22 | } `json:"instanceServers"` 23 | } `json:"data"` 24 | } 25 | 26 | //easyjson:json 27 | type welcomeMessageResponse struct { 28 | ID uuid.UUID `json:"id"` 29 | Type string `json:"type"` 30 | } 31 | 32 | //easyjson:json 33 | type pingMessageRequest struct { 34 | ID uuid.UUID `json:"id"` 35 | Type string `json:"type"` 36 | } 37 | 38 | //easyjson:json 39 | type subscribeMessageRequest struct { 40 | ID uuid.UUID `json:"id"` 41 | Type string `json:"type"` 42 | Topic string `json:"topic"` 43 | PrivateChannel bool `json:"privateChannel"` 44 | Response bool `json:"response"` 45 | } 46 | 47 | //easyjson:json 48 | type kLineUpdateMessageEntry struct { 49 | Symbol string `json:"symbol"` 50 | Candles kLine `json:"candles"` 51 | } 52 | 53 | //easyjson:json 54 | type genericMessageResponse struct { 55 | ID uuid.UUID `json:"id"` 56 | Type string `json:"type"` 57 | Topic string `json:"topic"` 58 | Subject string `json:"subject"` 59 | Data json.RawMessage `json:"data"` 60 | } 61 | 62 | //easyjson:json 63 | type kLinesResponse struct { 64 | Code string `json:"code"` 65 | Klines kLines `json:"data"` 66 | Message string `json:"message"` 67 | } 68 | 69 | //easyjson:json 70 | type genericResponse struct { 71 | Code string `json:"code"` 72 | Data json.RawMessage `json:"data"` 73 | Message string `json:"message"` 74 | } 75 | 76 | //easyjson:json 77 | type kLine [7]string 78 | 79 | //easyjson:json 80 | type kLines []*kLine 81 | -------------------------------------------------------------------------------- /proxy/kucoin/ws.go: -------------------------------------------------------------------------------- 1 | package kucoin 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "sync" 7 | "time" 8 | 9 | "github.com/dgrr/websocket" 10 | "github.com/google/uuid" 11 | "github.com/mailru/easyjson" 12 | "github.com/mikekonan/exchange-proxy/proxy" 13 | "github.com/mikekonan/exchange-proxy/store" 14 | "github.com/sirupsen/logrus" 15 | "go.uber.org/ratelimit" 16 | ) 17 | 18 | const ( 19 | bulletPublicPath = "/api/v1/bullet-public" 20 | 21 | welcomeMessageType = "welcome" 22 | messageMessageType = "message" 23 | subscribeMessageType = "subscribe" 24 | 25 | ping = "ping" 26 | pong = "pong" 27 | 28 | marketCandlesTopicPrefix = "/market/candles:" 29 | ) 30 | 31 | type subscriber struct { 32 | pool []*ws 33 | 34 | wsRl ratelimit.Limiter 35 | l *sync.Mutex 36 | subs map[string]struct{} 37 | client *proxy.Client 38 | config *Config 39 | store *store.Store 40 | httpRl ratelimit.Limiter 41 | } 42 | 43 | func (s *subscriber) subscribeKLines(pair string, tf string) { 44 | s.l.Lock() 45 | defer s.l.Unlock() 46 | 47 | topic := wsTopic(pair, tf) 48 | if _, ok := s.subs[topic]; ok { 49 | return 50 | } 51 | 52 | s.subs[topic] = struct{}{} 53 | 54 | for i, c := range s.pool { 55 | if c.subsCount == s.config.KucoinTopicsPerWs { 56 | continue 57 | } 58 | 59 | c.subsCount += 1 60 | s.wsRl.Take() 61 | if err := c.subscribeKLines(topic); err != nil { 62 | logrus.Fatal(err) 63 | } 64 | 65 | logrus.Infof("#%d-%d topic: '%s' subscribing...", i+1, c.subsCount, topic) 66 | 67 | return 68 | } 69 | 70 | wsConn := &ws{ 71 | subsCount: 0, 72 | client: s.client, 73 | httpRl: s.httpRl, 74 | wsRl: s.wsRl, 75 | retryCount: 15, 76 | store: s.store, 77 | config: s.config, 78 | id: uuid.New(), 79 | conn: nil, 80 | pingPongCh: make(chan uuid.UUID, 1), 81 | 82 | writeLock: new(sync.Mutex), 83 | } 84 | 85 | wsConn.connect() 86 | go wsConn.serve() 87 | 88 | wsConn.subsCount += 1 89 | if err := wsConn.subscribeKLines(topic); err != nil { 90 | logrus.Fatal(err) 91 | } 92 | 93 | s.pool = append(s.pool, wsConn) 94 | logrus.Infof("#%d-%d topic: '%s' subscribing...", len(s.pool), 1, topic) 95 | } 96 | 97 | type ws struct { 98 | id uuid.UUID 99 | 100 | subsCount int 101 | 102 | client *proxy.Client 103 | httpRl ratelimit.Limiter 104 | retryCount int 105 | store *store.Store 106 | config *Config 107 | 108 | conn *websocket.Client 109 | wsRl ratelimit.Limiter 110 | 111 | pingInterval *time.Ticker 112 | pingTimeout time.Duration 113 | pingPongCh chan uuid.UUID 114 | 115 | writeLock *sync.Mutex 116 | } 117 | 118 | func (w *ws) executeBulletPublicRequest() (int, *bulletPublicResponse, error) { 119 | w.httpRl.Take() 120 | 121 | statusCode, data, err := w.client.Post(nil, fmt.Sprintf("%s/%s", w.config.KucoinApiURL, bulletPublicPath), nil) 122 | 123 | if err != nil { 124 | return statusCode, nil, err 125 | } 126 | 127 | bulletPublicResponse := &bulletPublicResponse{} 128 | if err := easyjson.Unmarshal(data, bulletPublicResponse); err != nil { 129 | return statusCode, nil, err 130 | } 131 | 132 | return statusCode, bulletPublicResponse, nil 133 | } 134 | 135 | func (w *ws) getBulletPublic() (int, *bulletPublicResponse, error) { 136 | for i := 1; i <= w.retryCount; i++ { 137 | w.httpRl.Take() 138 | 139 | if statusCode, bulletPublicResponse, err := w.executeBulletPublicRequest(); statusCode == 200 { 140 | return statusCode, bulletPublicResponse, nil 141 | } else { 142 | if i == w.retryCount { 143 | return statusCode, bulletPublicResponse, fmt.Errorf("get bullet public exceeded retry '%d' attemts: %w", w.retryCount, err) 144 | } 145 | 146 | time.Sleep(time.Second) 147 | } 148 | } 149 | 150 | return 500, nil, fmt.Errorf("retry count is zero") 151 | } 152 | 153 | func (w *ws) connect() { 154 | _, bulletResp, err := w.getBulletPublic() 155 | if err != nil { 156 | logrus.Fatal(err) 157 | } 158 | 159 | w.pingInterval = time.NewTicker(time.Millisecond * time.Duration(bulletResp.Data.InstanceServers[0].PingInterval)) 160 | w.pingTimeout = time.Millisecond * time.Duration(bulletResp.Data.InstanceServers[0].PingTimeout) 161 | 162 | path := fmt.Sprintf("%s?token=%s&connectId=%s", bulletResp.Data.InstanceServers[0].Endpoint, bulletResp.Data.Token, w.id.String()) 163 | 164 | conn, err := websocket.Dial(path) 165 | if err != nil { 166 | logrus.Fatal(err) 167 | } 168 | 169 | w.conn = conn 170 | 171 | w.readWelcomeMsg() 172 | go w.pingPongRoutine() 173 | } 174 | 175 | func (w *ws) handlePongResponse(waitForID uuid.UUID) { 176 | logrus.Debugf("handling pong message with id '%s'", waitForID.String()) 177 | 178 | for { 179 | select { 180 | case <-time.After(w.pingTimeout): 181 | logrus.Fatal("pong timeout violation") 182 | case receivedID := <-w.pingPongCh: 183 | if waitForID == receivedID { 184 | return 185 | } else { 186 | logrus.Warnf("ping/pong id mismatch: sent '%s', received '%s'", waitForID.String(), receivedID.String()) 187 | w.pingPongCh <- receivedID 188 | } 189 | } 190 | } 191 | } 192 | 193 | func (w *ws) pingPongRoutine() { 194 | w.pingPongCh <- w.writePing() 195 | 196 | for { 197 | select { 198 | case <-w.pingInterval.C: 199 | w.pingPongCh <- w.writePing() 200 | case waitForID := <-w.pingPongCh: 201 | w.handlePongResponse(waitForID) 202 | } 203 | } 204 | } 205 | 206 | func (w *ws) writePing() uuid.UUID { 207 | id := uuid.New() 208 | 209 | logrus.Debugf("writing ping message with id '%s'", id.String()) 210 | 211 | data, err := easyjson.Marshal(pingMessageRequest{ID: id, Type: ping}) 212 | 213 | if err != nil { 214 | logrus.Fatal(err) 215 | } 216 | 217 | w.writeLock.Lock() 218 | defer w.writeLock.Unlock() 219 | 220 | if _, err := w.conn.Write(data); err != nil { 221 | logrus.Fatal(err) 222 | } 223 | 224 | return id 225 | } 226 | 227 | func (w *ws) readWelcomeMsg() { 228 | frame := websocket.AcquireFrame() 229 | defer websocket.ReleaseFrame(frame) 230 | 231 | _, err := w.conn.ReadFrame(frame) 232 | if err != nil { 233 | logrus.Fatalf("failed getting welcome message: %v", err) 234 | } 235 | 236 | welcomeMsg := &welcomeMessageResponse{} 237 | if err := easyjson.Unmarshal(frame.Payload(), welcomeMsg); err != nil { 238 | logrus.Fatalf("failed parsing welcome message: %v", err) 239 | } 240 | 241 | if welcomeMsg.ID != w.id && welcomeMsg.Type != welcomeMessageType { 242 | logrus.Fatal("failed establishing ws connection: id or message is incorrect") 243 | } 244 | } 245 | 246 | func (w *ws) subscribeKLines(topic string) error { 247 | topic = fmt.Sprintf("%s%s", marketCandlesTopicPrefix, topic) 248 | 249 | logrus.Debugf("subscribing to '%s'...", topic) 250 | 251 | message := subscribeMessageRequest{ 252 | ID: uuid.New(), 253 | Type: subscribeMessageType, 254 | Topic: topic, 255 | PrivateChannel: false, 256 | Response: false, 257 | } 258 | 259 | data, err := easyjson.Marshal(message) 260 | if err != nil { 261 | logrus.Fatal(err) 262 | } 263 | 264 | w.writeLock.Lock() 265 | defer w.writeLock.Unlock() 266 | 267 | if _, err := w.conn.Write(data); err != nil { 268 | logrus.Fatal(err) 269 | } 270 | 271 | return nil 272 | } 273 | 274 | func (w *ws) processFrame(frame *websocket.Frame) { 275 | message := &genericMessageResponse{} 276 | if err := easyjson.Unmarshal(frame.Payload(), message); err != nil { 277 | logrus.Fatalf("failed parsing generic message: %v. message is : '%s'", err, string(frame.Payload())) 278 | 279 | return 280 | } 281 | 282 | logrus.Tracef("received message '%s'-'%s'-'%s'", message.Topic, message.Subject, message.Type) 283 | 284 | switch message.Type { 285 | case pong: 286 | w.pingPongCh <- message.ID 287 | return 288 | 289 | case messageMessageType: 290 | if strings.HasPrefix(message.Topic, marketCandlesTopicPrefix) { 291 | pairTf := message.Topic[len(marketCandlesTopicPrefix):] 292 | pair := strings.Split(pairTf, "_")[0] 293 | tf := strings.Split(pairTf, "_")[1] 294 | 295 | entry := &kLineUpdateMessageEntry{} 296 | if err := easyjson.Unmarshal(message.Data, entry); err != nil { 297 | logrus.Fatal(err) 298 | } 299 | 300 | w.store.Store(storeKey(pair, tf), timeframeToDuration(tf), parseCandle(entry.Candles)) 301 | 302 | return 303 | } 304 | } 305 | } 306 | 307 | func (w *ws) serve() { 308 | for { 309 | frame := websocket.AcquireFrame() 310 | 311 | if _, err := w.conn.ReadFrame(frame); err != nil { 312 | logrus.Fatal(err) 313 | } 314 | 315 | w.processFrame(frame) 316 | 317 | websocket.ReleaseFrame(frame) 318 | } 319 | } 320 | -------------------------------------------------------------------------------- /proxy/router.go: -------------------------------------------------------------------------------- 1 | package proxy 2 | 3 | import ( 4 | "fmt" 5 | 6 | routing "github.com/qiangxue/fasthttp-routing" 7 | "github.com/sirupsen/logrus" 8 | "github.com/valyala/fasthttp" 9 | ) 10 | 11 | const AnyHTTPMethod = "" 12 | 13 | type Routable interface { 14 | Routes() []struct { 15 | Path string 16 | Method string 17 | Handler func(c *routing.Context) error 18 | } 19 | 20 | Name() string 21 | } 22 | 23 | func New(config *Config, routable Routable) *Server { 24 | router := routing.New() 25 | 26 | for _, route := range routable.Routes() { 27 | path := fmt.Sprintf("/%s/%s", routable.Name(), route.Path) 28 | logrus.Infof("applying route '%s' of method '%s'", path, route.Method) 29 | 30 | if route.Method == AnyHTTPMethod { 31 | router.Any(path, route.Handler) 32 | continue 33 | } 34 | 35 | router.To(route.Method, path, route.Handler) 36 | } 37 | 38 | return &Server{ 39 | server: &fasthttp.Server{ 40 | Handler: router.HandleRequest, 41 | Concurrency: config.ConcurrencyLimit, 42 | }, 43 | config: config, 44 | } 45 | } 46 | 47 | type Server struct { 48 | config *Config 49 | server *fasthttp.Server 50 | } 51 | 52 | func (s *Server) Serve() { 53 | logrus.Infof("starting proxy server on :%s port...", s.config.Port) 54 | logrus.Fatal(s.server.ListenAndServe(fmt.Sprintf("%s:%s", s.config.Bindaddr, s.config.Port))) 55 | } 56 | -------------------------------------------------------------------------------- /store/candles_linked_list.go: -------------------------------------------------------------------------------- 1 | //nolint:unused 2 | package store 3 | 4 | import ( 5 | "fmt" 6 | 7 | "github.com/mikekonan/exchange-proxy/model" 8 | ) 9 | 10 | type candlesLinkedList struct { 11 | first *element 12 | last *element 13 | len int 14 | } 15 | 16 | type element struct { 17 | value *model.Candle 18 | prev *element 19 | next *element 20 | } 21 | 22 | func newCandlesLinkedList(values ...*model.Candle) *candlesLinkedList { 23 | list := &candlesLinkedList{} 24 | if len(values) > 0 { 25 | list.add(values...) 26 | } 27 | return list 28 | } 29 | 30 | func (list *candlesLinkedList) add(values ...*model.Candle) { 31 | for _, value := range values { 32 | newElement := &element{value: value, prev: list.last} 33 | if list.len == 0 { 34 | list.first = newElement 35 | list.last = newElement 36 | } else { 37 | list.last.next = newElement 38 | list.last = newElement 39 | } 40 | list.len++ 41 | } 42 | } 43 | 44 | func (list *candlesLinkedList) append(values ...*model.Candle) { 45 | list.add(values...) 46 | } 47 | 48 | func (list *candlesLinkedList) prepend(values ...*model.Candle) { 49 | 50 | for v := len(values) - 1; v >= 0; v-- { 51 | newElement := &element{value: values[v], next: list.first} 52 | if list.len == 0 { 53 | list.first = newElement 54 | list.last = newElement 55 | } else { 56 | list.first.prev = newElement 57 | list.first = newElement 58 | } 59 | list.len++ 60 | } 61 | } 62 | 63 | func (list *candlesLinkedList) get(index int) (*model.Candle, bool) { 64 | if !list.withinRange(index) { 65 | return nil, false 66 | } 67 | 68 | if list.len-index < index { 69 | element := list.last 70 | for e := list.len - 1; e != index; e, element = e-1, element.prev { 71 | } 72 | return element.value, true 73 | } 74 | 75 | element := list.first 76 | for e := 0; e != index; e, element = e+1, element.next { 77 | } 78 | 79 | return element.value, true 80 | } 81 | 82 | func (list *candlesLinkedList) remove(index int) { 83 | if !list.withinRange(index) { 84 | return 85 | } 86 | 87 | if list.len == 1 { 88 | list.clear() 89 | return 90 | } 91 | 92 | var element *element 93 | 94 | if list.len-index < index { 95 | element = list.last 96 | for e := list.len - 1; e != index; e, element = e-1, element.prev { 97 | } 98 | } else { 99 | element = list.first 100 | for e := 0; e != index; e, element = e+1, element.next { 101 | } 102 | } 103 | 104 | if element == list.first { 105 | list.first = element.next 106 | } 107 | if element == list.last { 108 | list.last = element.prev 109 | } 110 | if element.prev != nil { 111 | element.prev.next = element.next 112 | } 113 | if element.next != nil { 114 | element.next.prev = element.prev 115 | } 116 | 117 | element = nil 118 | 119 | list.len-- 120 | } 121 | 122 | func (list *candlesLinkedList) contains(values ...*model.Candle) bool { 123 | if len(values) == 0 { 124 | return true 125 | } 126 | if list.len == 0 { 127 | return false 128 | } 129 | for _, value := range values { 130 | found := false 131 | for element := list.first; element != nil; element = element.next { 132 | if element.value == value { 133 | found = true 134 | break 135 | } 136 | } 137 | if !found { 138 | return false 139 | } 140 | } 141 | return true 142 | } 143 | 144 | func (list *candlesLinkedList) values() []*model.Candle { 145 | values := make([]*model.Candle, list.len) 146 | 147 | for e, element := 0, list.first; element != nil; e, element = e+1, element.next { 148 | values[e] = element.value 149 | } 150 | 151 | return values 152 | } 153 | 154 | func (list *candlesLinkedList) invertedValues() []*model.Candle { 155 | values := make([]*model.Candle, list.len) 156 | for e, element := 0, list.last; element != nil; e, element = e+1, element.prev { 157 | values[e] = element.value 158 | } 159 | return values 160 | } 161 | 162 | func (list *candlesLinkedList) indexOf(value *model.Candle) int { 163 | if list.len == 0 { 164 | return -1 165 | } 166 | for index, element := range list.values() { 167 | if element == value { 168 | return index 169 | } 170 | } 171 | return -1 172 | } 173 | 174 | func (list *candlesLinkedList) empty() bool { 175 | return list.len == 0 176 | } 177 | 178 | func (list *candlesLinkedList) size() int { 179 | return list.len 180 | } 181 | 182 | func (list *candlesLinkedList) clear() { 183 | list.len = 0 184 | list.first = nil 185 | list.last = nil 186 | } 187 | 188 | func (list *candlesLinkedList) swap(i, j int) { 189 | if list.withinRange(i) && list.withinRange(j) && i != j { 190 | var element1, element2 *element 191 | for e, currentElement := 0, list.first; element1 == nil || element2 == nil; e, currentElement = e+1, currentElement.next { 192 | switch e { 193 | case i: 194 | element1 = currentElement 195 | case j: 196 | element2 = currentElement 197 | } 198 | } 199 | element1.value, element2.value = element2.value, element1.value 200 | } 201 | } 202 | 203 | func (list *candlesLinkedList) insert(index int, values ...*model.Candle) { 204 | 205 | if !list.withinRange(index) { 206 | 207 | if index == list.len { 208 | list.add(values...) 209 | } 210 | return 211 | } 212 | 213 | list.len += len(values) 214 | 215 | var beforeElement *element 216 | var foundElement *element 217 | 218 | if list.len-index < index { 219 | foundElement = list.last 220 | for e := list.len - 1; e != index; e, foundElement = e-1, foundElement.prev { 221 | beforeElement = foundElement.prev 222 | } 223 | } else { 224 | foundElement = list.first 225 | for e := 0; e != index; e, foundElement = e+1, foundElement.next { 226 | beforeElement = foundElement 227 | } 228 | } 229 | 230 | if foundElement == list.first { 231 | oldNextElement := list.first 232 | for i, value := range values { 233 | newElement := &element{value: value} 234 | if i == 0 { 235 | list.first = newElement 236 | } else { 237 | newElement.prev = beforeElement 238 | beforeElement.next = newElement 239 | } 240 | beforeElement = newElement 241 | } 242 | oldNextElement.prev = beforeElement 243 | beforeElement.next = oldNextElement 244 | } else { 245 | oldNextElement := beforeElement.next 246 | for _, value := range values { 247 | newElement := &element{value: value} 248 | newElement.prev = beforeElement 249 | beforeElement.next = newElement 250 | beforeElement = newElement 251 | } 252 | oldNextElement.prev = beforeElement 253 | beforeElement.next = oldNextElement 254 | } 255 | } 256 | 257 | func (list *candlesLinkedList) set(index int, value *model.Candle) { 258 | 259 | if !list.withinRange(index) { 260 | 261 | if index == list.len { 262 | list.add(value) 263 | } 264 | return 265 | } 266 | 267 | var foundElement *element 268 | 269 | if list.len-index < index { 270 | foundElement = list.last 271 | for e := list.len - 1; e != index; { 272 | fmt.Println("set last", index, value, foundElement, foundElement.prev) 273 | e, foundElement = e-1, foundElement.prev 274 | } 275 | } else { 276 | foundElement = list.first 277 | for e := 0; e != index; { 278 | e, foundElement = e+1, foundElement.next 279 | } 280 | } 281 | 282 | foundElement.value = value 283 | } 284 | 285 | func (list *candlesLinkedList) withinRange(index int) bool { 286 | return index >= 0 && index < list.len 287 | } 288 | 289 | func (list *candlesLinkedList) selectFn(fromSelectorFn func(*model.Candle) bool, toSelectorFn func(*model.Candle) bool) []*model.Candle { 290 | values := make([]*model.Candle, 0, 200) 291 | 292 | started := false 293 | 294 | for element := list.first; element != nil; element = element.next { 295 | if started || toSelectorFn(element.value) { 296 | started = true 297 | } else { 298 | continue 299 | } 300 | 301 | values = append(values, element.value) 302 | 303 | if started && fromSelectorFn(element.value) { 304 | break 305 | } 306 | } 307 | 308 | return values 309 | } 310 | -------------------------------------------------------------------------------- /store/candles_store.go: -------------------------------------------------------------------------------- 1 | package store 2 | 3 | import ( 4 | "sync" 5 | "time" 6 | 7 | "github.com/mikekonan/exchange-proxy/model" 8 | "github.com/sirupsen/logrus" 9 | ) 10 | 11 | func NewStore(cacheSize int) *Store { 12 | return &Store{ 13 | l: new(sync.RWMutex), 14 | mappedLists: map[string]*candlesLinkedList{}, 15 | cacheSize: cacheSize, 16 | } 17 | } 18 | 19 | type Store struct { 20 | l *sync.RWMutex 21 | mappedLists map[string]*candlesLinkedList 22 | cacheSize int 23 | } 24 | 25 | func (s *Store) Store(key string, period time.Duration, candles ...*model.Candle) { 26 | s.l.Lock() 27 | defer s.l.Unlock() 28 | 29 | bucket := s.mappedLists[key] 30 | if bucket == nil { 31 | bucket = newCandlesLinkedList() 32 | s.mappedLists[key] = bucket 33 | } 34 | 35 | for _, c := range candles { 36 | if bucket.first != nil { 37 | steps := c.Ts.Sub(bucket.first.value.Ts) / period 38 | 39 | if steps > 1 { 40 | for i := 1; i < int(steps); i++ { 41 | painted := bucket.first.value.Clone() 42 | painted.Ts = painted.Ts.Add(period) 43 | painted.Volume = 0 44 | painted.Amount = 0 45 | 46 | logrus.Warnf("saving painted candle: ts '%s' for '%s'...", painted.Ts, key) 47 | 48 | s.store(bucket, painted) 49 | } 50 | } 51 | } 52 | 53 | s.store(bucket, c) 54 | } 55 | } 56 | 57 | func (s *Store) store(bucket *candlesLinkedList, candle *model.Candle) { 58 | first, ok := bucket.get(0) 59 | if ok && first.Ts == candle.Ts { 60 | logrus.Tracef("%s %s - update first", first.Ts.String(), candle.Ts.String()) 61 | bucket.set(0, candle) 62 | 63 | return 64 | } 65 | 66 | if bucket.size() == s.cacheSize { 67 | bucket.remove(s.cacheSize - 1) 68 | } 69 | 70 | if ok && first.Ts.Before(candle.Ts) { 71 | logrus.Tracef("%s %s - prepend", first.Ts.String(), candle.Ts.String()) 72 | bucket.prepend(candle) 73 | } else { 74 | if first != nil { 75 | logrus.Tracef("%s %s - append", first.Ts.String(), candle.Ts.String()) 76 | } 77 | 78 | bucket.append(candle) 79 | } 80 | } 81 | 82 | func (s *Store) Get(key string, from time.Time, to time.Time) []*model.Candle { 83 | s.l.RLock() 84 | defer s.l.RUnlock() 85 | 86 | bucket := s.mappedLists[key] 87 | if bucket == nil { 88 | return nil 89 | } 90 | 91 | candles := bucket.selectFn( 92 | func(candle *model.Candle) bool { return candle.Ts == from || candle.Ts.Before(from) }, 93 | func(candle *model.Candle) bool { return candle.Ts == to || candle.Ts.Before(to) }, 94 | ) 95 | 96 | return candles 97 | } 98 | -------------------------------------------------------------------------------- /store/ttl_cache.go: -------------------------------------------------------------------------------- 1 | package store 2 | 3 | import ( 4 | "sync" 5 | "time" 6 | ) 7 | 8 | type Container struct { 9 | raw []byte 10 | expiresAt time.Time 11 | } 12 | 13 | func (c *Container) Raw() []byte { 14 | return c.raw 15 | } 16 | 17 | func NewTTLCache(expirationTimeout time.Duration) *TTLCache { 18 | return &TTLCache{ 19 | l: new(sync.Mutex), 20 | kv: map[string]*Container{}, 21 | expirationTimeout: expirationTimeout, 22 | } 23 | } 24 | 25 | type TTLCache struct { 26 | l *sync.Mutex 27 | 28 | kv map[string]*Container 29 | expirationTimeout time.Duration 30 | } 31 | 32 | func (s *TTLCache) Get(key string) *Container { 33 | s.l.Lock() 34 | defer s.l.Unlock() 35 | 36 | container, ok := s.kv[key] 37 | if !ok { 38 | return nil 39 | } 40 | 41 | if container.expiresAt.Before(time.Now().UTC()) { 42 | delete(s.kv, key) 43 | return nil 44 | } 45 | 46 | return container 47 | } 48 | 49 | func (s *TTLCache) Store(key string, value []byte) { 50 | s.l.Lock() 51 | defer s.l.Unlock() 52 | 53 | s.kv[key] = &Container{ 54 | raw: value, 55 | expiresAt: time.Now().UTC().Add(s.expirationTimeout), 56 | } 57 | } 58 | --------------------------------------------------------------------------------