From c545200adedb81b01fda8bcc28ac1c723cce2e7e Mon Sep 17 00:00:00 2001 From: Matthew Rich Date: Thu, 4 Apr 2024 12:43:46 -0700 Subject: [PATCH] add initial commit --- .gitea/workflows/lint.yaml | 21 ++++ .gitea/workflows/test.yaml | 54 +++++++++ COPYRIGHT | 1 + LICENSE | 60 ++++++++++ Makefile | 7 ++ README.md | 1 + artifacts/.gitkeep | 0 go.mod | 45 ++++++++ go.sum | 97 ++++++++++++++++ message/body.go | 37 ++++++ message/envelope.go | 49 ++++++++ message/factory.go | 11 ++ message/message.pb.go | 230 +++++++++++++++++++++++++++++++++++++ message/message.proto | 19 +++ message/router.go | 7 ++ sequence/serial.go | 16 +++ sequence/serial_test.go | 18 +++ 17 files changed, 673 insertions(+) create mode 100644 .gitea/workflows/lint.yaml create mode 100644 .gitea/workflows/test.yaml create mode 100644 COPYRIGHT create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 artifacts/.gitkeep create mode 100644 go.mod create mode 100644 go.sum create mode 100644 message/body.go create mode 100644 message/envelope.go create mode 100644 message/factory.go create mode 100644 message/message.pb.go create mode 100644 message/message.proto create mode 100644 message/router.go create mode 100644 sequence/serial.go create mode 100644 sequence/serial_test.go diff --git a/.gitea/workflows/lint.yaml b/.gitea/workflows/lint.yaml new file mode 100644 index 0000000..256b293 --- /dev/null +++ b/.gitea/workflows/lint.yaml @@ -0,0 +1,21 @@ +name: Lint +on: + - push +jobs: + lint: + name: golangci-lint + runs-on: ubuntu-latest + + steps: + - uses: actions/setup-go@v4 + with: + go-version: "1.21.1" + cache: false + + - name: Check out code + uses: actions/checkout@v3 + + - name: Lint + uses: golangci/golangci-lint-action@v3 + with: + version: v1.55 diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml new file mode 100644 index 0000000..8e5f9a9 --- /dev/null +++ b/.gitea/workflows/test.yaml @@ -0,0 +1,54 @@ +name: Declarative Tests +run-name: ${{ gitea.actor }} testing +on: + - push + - workflow_dispatch + - issue_comment + +jobs: + test: + runs-on: ubuntu-latest + container: + image: registry.cv.mazarbul.net/declarative/build-golang:1.21.1-alpine-x86_64 + env: + GOPATH: / + SSH_AUTH_SOCK: /tmp/ssh.sock + ENVIRONMENT: dev + volumes: + - ${{ env.HOME }}/.ssh/known_hosts:/root/.ssh/known_hosts + - ${{ env.SSH_AUTH_SOCK }}:/tmp/ssh.sock + - /etc/gitconfig:/etc/gitconfig + - /etc/ssl/certs:/etc/ssl/certs + - ${{ vars.GITEA_WORKSPACE }}:/go/src + options: --cpus 1 + steps: + - run: apk add --no-cache nodejs + - name: Check out repository code + uses: actions/checkout@v3 + - run: echo "The ${{ gitea.repository }} repository has been cloned to the runner." + - run: echo "The workflow is now ready to test your code on the runner." + - name: Run tests + run: | + go test -coverprofile=artifacts/coverage.profile ./... + - name: Run build + run: | + make build + - name: cli tests + run: | + go test + - run: echo "This job's status is ${{ job.status }}." + - run: echo "This job's status is ${{ job.status }}." + - name: coverage report + run: | + go tool cover -html=artifacts/coverage.profile -o artifacts/code-coverage.html + - name: Archive code coverage results + uses: actions/upload-artifact@v3 + with: + name: code-coverage-report + path: artifacts/code-coverage.html + - name: Archive binary + uses: actions/upload-artifact@v3 + with: + name: decl + path: decl + - run: echo "This job's status is ${{ job.status }}." diff --git a/COPYRIGHT b/COPYRIGHT new file mode 100644 index 0000000..baaf503 --- /dev/null +++ b/COPYRIGHT @@ -0,0 +1 @@ +Copyright 2024 Matthew Rich . All rights reserved. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..586cc31 --- /dev/null +++ b/LICENSE @@ -0,0 +1,60 @@ +Apache NON-AI License, Version 2.0 + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form, under the following conditions: + + 2.1. You shall not use the Covered Software in the creation of an Artificial Intelligence training dataset, + including but not limited to any use that contributes to the training or development of an AI model or algorithm, + unless You obtain explicit written permission from the Contributor to do so. + + 2.2. You acknowledge that the Covered Software is not intended for use in the creation of an Artificial Intelligence training dataset, + and that the Contributor has no obligation to provide support or assistance for any use that violates this license. + +3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + + (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + + You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f2fa516 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +LDFLAGS?=--ldflags '-extldflags "-static"' +export CGO_ENABLED=0 + +build: + +test: + go test ./... diff --git a/README.md b/README.md index e5e2f69..d3fe663 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # feudal +Worker framework diff --git a/artifacts/.gitkeep b/artifacts/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6a16cac --- /dev/null +++ b/go.mod @@ -0,0 +1,45 @@ +module feudal + +go 1.21.1 + +require ( + github.com/golang/protobuf v1.4.3 + google.golang.org/grpc v1.36.1 + google.golang.org/protobuf v1.25.0 +) + +require ( + cloud.google.com/go v0.26.0 // indirect + gitea.rosskeen.house/rosskeen.house/machine v0.0.0-20240404185501-944d73f34aee // indirect + github.com/BurntSushi/toml v0.3.1 // indirect + github.com/census-instrumentation/opencensus-proto v0.2.1 // indirect + github.com/client9/misspell v0.3.4 // indirect + github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403 // indirect + github.com/davecgh/go-spew v1.1.0 // indirect + github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad // indirect + github.com/envoyproxy/protoc-gen-validate v0.1.0 // indirect + github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect + github.com/golang/mock v1.1.1 // indirect + github.com/google/go-cmp v0.5.0 // indirect + github.com/google/uuid v1.1.2 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 // indirect + github.com/stretchr/objx v0.1.0 // indirect + github.com/stretchr/testify v1.5.1 // indirect + golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 // indirect + golang.org/x/exp v0.0.0-20190121172915-509febef88a4 // indirect + golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect + golang.org/x/net v0.0.0-20190311183353-d8887717615a // indirect + golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be // indirect + golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect + golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a // indirect + golang.org/x/text v0.3.0 // indirect + golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 // indirect + golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect + google.golang.org/appengine v1.4.0 // indirect + google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect + google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 // indirect + gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 // indirect + gopkg.in/yaml.v2 v2.2.2 // indirect + honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..3c81fa0 --- /dev/null +++ b/go.sum @@ -0,0 +1,97 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +gitea.rosskeen.house/rosskeen.house/machine v0.0.0-20240404174407-877f9ae2ef33 h1:mUVWLP0ynndjVeLjp2mbyA7e9ryEojV1qacwou0wg2o= +gitea.rosskeen.house/rosskeen.house/machine v0.0.0-20240404174407-877f9ae2ef33/go.mod h1:u7PGSNZPwiok9AMQ1rcPEOnRdeb2ThFow/hYekaRE1o= +gitea.rosskeen.house/rosskeen.house/machine v0.0.0-20240404182125-29fbe1b1b71e h1:Qv4C5Y/Y6186PUUutsOJwtW41nCyClwwZnsCCtnMGE8= +gitea.rosskeen.house/rosskeen.house/machine v0.0.0-20240404182125-29fbe1b1b71e/go.mod h1:0zlJnkqJNxW9np/VYufhsRDTAWo8P2DmbWYb9F4AXUg= +gitea.rosskeen.house/rosskeen.house/machine v0.0.0-20240404185501-944d73f34aee h1:NN67upOM1wG4lYiflwjx2zr0ova2XqXeRKv1K9dErIk= +gitea.rosskeen.house/rosskeen.house/machine v0.0.0-20240404185501-944d73f34aee/go.mod h1:qPxa8WMZ4YXC7vA45+9h2+MXiZbKQGVn1vDeBmlulz4= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/mrichconf/feudal v0.0.0-20170430055241-6920d09f4446 h1:XKHbtBQ1gYYopA3zZhnkkHO4ZIyR8pSyo9BPROl8Eak= +github.com/mrichconf/feudal v0.0.0-20170430055241-6920d09f4446/go.mod h1:vLGuOR9Uq2sSvBjR7Yj576TBXfQpaFyZ/+b2V1rPhYQ= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.36.1 h1:cmUfbeGKnz9+2DD/UYsMQXeqbHZqZDs4eQwW0sFOpBY= +google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 h1:M1YKkFIboKNieVO5DLUEVzQfGwJD30Nv2jfUgzb5UcE= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/message/body.go b/message/body.go new file mode 100644 index 0000000..665d910 --- /dev/null +++ b/message/body.go @@ -0,0 +1,37 @@ +// Copyright 2024 Matthew Rich . All rights reserved. + +package message; + +import ( + "time" +) + +type Empty struct {} + +type Register struct { Handler interface{} } + +type Terminated struct {} + +type Stop struct {} + +type Serialized struct { Content []byte } + +type Unserialize struct { Size int } + +type Error struct { E error } + +type HealthCheckQuery struct {} + +type HealthCheckResponse struct { QueueLen int } + +type Subscribe struct { } + +type Ack struct { } + +type Ping struct {} + +type Pong struct {} + +type SubscribeToClockTick struct { } + +type ClockTick struct { T time.Time } diff --git a/message/envelope.go b/message/envelope.go new file mode 100644 index 0000000..5ca77ca --- /dev/null +++ b/message/envelope.go @@ -0,0 +1,49 @@ +// Copyright 2024 Matthew Rich . All rights reserved. + +package message; + +import ( + "feudal/identity" +) + +type Envelope interface { + Body() interface{} + Sender() Sender + Receiver() Receiver +} + +type Handler interface { + Handle(m Envelope) +} + +type Receiver interface { + identity.Addresser + Receive(m Envelope) +} + +type Sender interface { + identity.Addresser + Send(m Envelope) +} + +type AbstractEnvelope struct { + body interface{} + sender Sender + receiver Receiver +} + +func (e *AbstractEnvelope) Body() interface{} { return e.body } +func (e *AbstractEnvelope) Sender() Sender { return e.sender } +func (e *AbstractEnvelope) Receiver() Receiver { return e.receiver } + +func New(b interface{}, s Sender) Envelope { + return &AbstractEnvelope{ body: b, sender: s } +} + +func NewAnonymous(b interface{}) Envelope { + return &AbstractEnvelope{ body: b, sender: nil } +} + +func To(b interface{}, from Sender, to Receiver) Envelope { + return &AbstractEnvelope{ body: b, sender: from, receiver: to } +} diff --git a/message/factory.go b/message/factory.go new file mode 100644 index 0000000..e1e2346 --- /dev/null +++ b/message/factory.go @@ -0,0 +1,11 @@ +// Copyright 2024 Matthew Rich . All rights reserved. + +package message; + +import ( + "github.com/golang/protobuf/proto" +) + +type Factory interface { + NewMessage() proto.Message +} diff --git a/message/message.pb.go b/message/message.pb.go new file mode 100644 index 0000000..49350a3 --- /dev/null +++ b/message/message.pb.go @@ -0,0 +1,230 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.23.0 +// protoc v3.12.2 +// source: message.proto + +package message + +import ( + proto "github.com/golang/protobuf/proto" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// This is a compile-time assertion that a sufficiently up-to-date version +// of the legacy proto package is being used. +const _ = proto.ProtoPackageIsVersion4 + +type Body_EncodingType int32 + +const ( + Body_NONE Body_EncodingType = 0 + Body_ERROR Body_EncodingType = 1 + Body_PBSERIALIZED Body_EncodingType = 2 + Body_GOBSERIALIZED Body_EncodingType = 3 + Body_JSONSERIALIZED Body_EncodingType = 4 +) + +// Enum value maps for Body_EncodingType. +var ( + Body_EncodingType_name = map[int32]string{ + 0: "NONE", + 1: "ERROR", + 2: "PBSERIALIZED", + 3: "GOBSERIALIZED", + 4: "JSONSERIALIZED", + } + Body_EncodingType_value = map[string]int32{ + "NONE": 0, + "ERROR": 1, + "PBSERIALIZED": 2, + "GOBSERIALIZED": 3, + "JSONSERIALIZED": 4, + } +) + +func (x Body_EncodingType) Enum() *Body_EncodingType { + p := new(Body_EncodingType) + *p = x + return p +} + +func (x Body_EncodingType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (Body_EncodingType) Descriptor() protoreflect.EnumDescriptor { + return file_message_proto_enumTypes[0].Descriptor() +} + +func (Body_EncodingType) Type() protoreflect.EnumType { + return &file_message_proto_enumTypes[0] +} + +func (x Body_EncodingType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use Body_EncodingType.Descriptor instead. +func (Body_EncodingType) EnumDescriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{0, 0} +} + +type Body struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Type Body_EncodingType `protobuf:"varint,1,opt,name=type,proto3,enum=message.Body_EncodingType" json:"type,omitempty"` + Key []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` + Value []byte `protobuf:"bytes,3,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *Body) Reset() { + *x = Body{} + if protoimpl.UnsafeEnabled { + mi := &file_message_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Body) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Body) ProtoMessage() {} + +func (x *Body) ProtoReflect() protoreflect.Message { + mi := &file_message_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Body.ProtoReflect.Descriptor instead. +func (*Body) Descriptor() ([]byte, []int) { + return file_message_proto_rawDescGZIP(), []int{0} +} + +func (x *Body) GetType() Body_EncodingType { + if x != nil { + return x.Type + } + return Body_NONE +} + +func (x *Body) GetKey() []byte { + if x != nil { + return x.Key + } + return nil +} + +func (x *Body) GetValue() []byte { + if x != nil { + return x.Value + } + return nil +} + +var File_message_proto protoreflect.FileDescriptor + +var file_message_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xbc, 0x01, 0x0a, 0x04, 0x42, 0x6f, 0x64, + 0x79, 0x12, 0x2e, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, + 0x1a, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 0x42, 0x6f, 0x64, 0x79, 0x2e, 0x45, + 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, + 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x03, + 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x5c, 0x0a, 0x0c, 0x45, 0x6e, 0x63, + 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x54, 0x79, 0x70, 0x65, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x4f, 0x4e, + 0x45, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x45, 0x52, 0x52, 0x4f, 0x52, 0x10, 0x01, 0x12, 0x10, + 0x0a, 0x0c, 0x50, 0x42, 0x53, 0x45, 0x52, 0x49, 0x41, 0x4c, 0x49, 0x5a, 0x45, 0x44, 0x10, 0x02, + 0x12, 0x11, 0x0a, 0x0d, 0x47, 0x4f, 0x42, 0x53, 0x45, 0x52, 0x49, 0x41, 0x4c, 0x49, 0x5a, 0x45, + 0x44, 0x10, 0x03, 0x12, 0x12, 0x0a, 0x0e, 0x4a, 0x53, 0x4f, 0x4e, 0x53, 0x45, 0x52, 0x49, 0x41, + 0x4c, 0x49, 0x5a, 0x45, 0x44, 0x10, 0x04, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_message_proto_rawDescOnce sync.Once + file_message_proto_rawDescData = file_message_proto_rawDesc +) + +func file_message_proto_rawDescGZIP() []byte { + file_message_proto_rawDescOnce.Do(func() { + file_message_proto_rawDescData = protoimpl.X.CompressGZIP(file_message_proto_rawDescData) + }) + return file_message_proto_rawDescData +} + +var file_message_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_message_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_message_proto_goTypes = []interface{}{ + (Body_EncodingType)(0), // 0: message.Body.EncodingType + (*Body)(nil), // 1: message.Body +} +var file_message_proto_depIdxs = []int32{ + 0, // 0: message.Body.type:type_name -> message.Body.EncodingType + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_message_proto_init() } +func file_message_proto_init() { + if File_message_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_message_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Body); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_message_proto_rawDesc, + NumEnums: 1, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_message_proto_goTypes, + DependencyIndexes: file_message_proto_depIdxs, + EnumInfos: file_message_proto_enumTypes, + MessageInfos: file_message_proto_msgTypes, + }.Build() + File_message_proto = out.File + file_message_proto_rawDesc = nil + file_message_proto_goTypes = nil + file_message_proto_depIdxs = nil +} diff --git a/message/message.proto b/message/message.proto new file mode 100644 index 0000000..2fe1785 --- /dev/null +++ b/message/message.proto @@ -0,0 +1,19 @@ +// Copyright 2024 Matthew Rich . All rights reserved. + +syntax = "proto3"; +package message; + +message Body { + + enum EncodingType { + NONE = 0; + ERROR = 1; + PBSERIALIZED = 2; + GOBSERIALIZED = 3; + JSONSERIALIZED = 4; + } + EncodingType type = 1; + bytes key = 2; + bytes value = 3; + +} diff --git a/message/router.go b/message/router.go new file mode 100644 index 0000000..a44bf4a --- /dev/null +++ b/message/router.go @@ -0,0 +1,7 @@ +// Copyright 2024 Matthew Rich . All rights reserved. + +package message + +type Router interface { + Route(m Envelope) +} diff --git a/sequence/serial.go b/sequence/serial.go new file mode 100644 index 0000000..2e40497 --- /dev/null +++ b/sequence/serial.go @@ -0,0 +1,16 @@ +// Copyright 2024 Matthew Rich . All rights reserved. + +package sequence + + +import ( + "sync/atomic" +) + + +type Serial32 func() uint32 + +func NewSerial32() Serial32 { + var c uint32 = 0 + return func() uint32 { return atomic.AddUint32(&c, 1) } +} diff --git a/sequence/serial_test.go b/sequence/serial_test.go new file mode 100644 index 0000000..3614726 --- /dev/null +++ b/sequence/serial_test.go @@ -0,0 +1,18 @@ +// Copyright 2024 Matthew Rich . All rights reserved. + +package sequence + +import( + "testing" +) + +func TestNewSerial32(t *testing.T) { + counter := NewSerial32() + for i := 0; i < 9; i++ { + counter() + } + r := counter() + if r != 10 { + t.Errorf("Serial counter returned incorrect value: %d != 10", r) + } +}