From 77a7c7eae05af46c4019cff1fd716f82b70c5819 Mon Sep 17 00:00:00 2001 From: windyboy Date: Tue, 23 Jul 2024 11:29:12 +0800 Subject: [PATCH] refactor: Update ARR body parsing logic --- .gitignore | 2 +- Taskfile.yml | 113 +++ configs/config.development.toml | 42 + genqlient.yaml | 6 + go.mod | 64 ++ go.sum | 104 +- internal/repository/generated.go | 163 +++ internal/repository/genqlient.graphql | 7 + internal/repository/genqlient.yaml | 13 + internal/repository/ginkgo.report | 180 ++++ internal/repository/hasura.go | 52 +- internal/repository/hasura_test.go | 52 +- internal/repository/schema.graphql | 1311 +++++++++++++++++++++++++ schema.graphql | 1289 ++++++++++++++++++++++++ 14 files changed, 3348 insertions(+), 50 deletions(-) create mode 100644 Taskfile.yml create mode 100644 configs/config.development.toml create mode 100644 genqlient.yaml create mode 100644 go.mod create mode 100644 internal/repository/generated.go create mode 100644 internal/repository/genqlient.graphql create mode 100644 internal/repository/genqlient.yaml create mode 100644 internal/repository/ginkgo.report create mode 100644 internal/repository/schema.graphql create mode 100644 schema.graphql diff --git a/.gitignore b/.gitignore index d963bec..8d923e9 100644 --- a/.gitignore +++ b/.gitignore @@ -29,7 +29,7 @@ Thumbs.db # Go specific # go.sum -go.mod +# go.mod # Test binary, built with `go test -c` *.test diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..87461ee --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,113 @@ +version: '3' + +vars: + APP_NAME: tele-proc + GO_FILES: + sh: find . -name '*.go' -type f + CONFIG_DIR: configs + BUILD_DIR: build + MAIN_RECEIVER: ./cmd/main/main.go + HASURA_ENDPOINT: http://localhost:8080/v1/graphql + SCHEMA_FILE: ./internal/repository/schema.graphql + HASURA_SECRET: # Set your Hasura admin secret here + +tasks: + all: + desc: Default target + cmds: + - task: build + + build: + desc: Build the receiver application + cmds: + - task: build-receiver + + build-receiver: + desc: Build the receiver application + cmds: + - echo "Building receiver..." + - go build -o {{.BUILD_DIR}}/receiver {{.MAIN_RECEIVER}} + + run: + desc: Run the receiver application with different configurations + cmds: + - task: run-dev + + run-dev: + desc: Run the receiver in development mode + cmds: + - echo "Running receiver in development mode..." + - GO_ENV=development {{.BUILD_DIR}}/receiver & + + run-prod: + desc: Run the receiver in production mode + cmds: + - echo "Running receiver in production mode..." + - GO_ENV=production {{.BUILD_DIR}}/receiver & + + run-test: + desc: Run the receiver in test mode + cmds: + - echo "Running receiver in test mode..." + - GO_ENV=test {{.BUILD_DIR}}/receiver & + + test: + desc: Test the application + cmds: + - echo "Running tests..." + - ginkgo -r -v + + clean: + desc: Clean build artifacts + cmds: + - echo "Cleaning build artifacts..." + - rm -rf {{.BUILD_DIR}} + + fmt: + desc: Format the code + cmds: + - echo "Formatting code..." + - go fmt ./... + + deps: + desc: Install dependencies + cmds: + - echo "Installing dependencies..." + - go mod tidy + + lint: + desc: Lint the code + cmds: + - echo "Linting code..." + - golangci-lint run + + schema: + desc: Download the GraphQL schema from Hasura server + cmds: + - echo "Downloading GraphQL schema..." + - > + gq {{.HASURA_ENDPOINT}} -H 'X-Hasura-Admin-Secret: {{.HASURA_SECRET}}' --introspect > {{.SCHEMA_FILE}} + + + gen: + desc: Generate code using genqlient + cmds: + - echo "Generating code using genqlient..." + - cd internal/repository && go run github.com/Khan/genqlient && cd ../.. + + help: + desc: Show this help message + cmds: + - echo "Taskfile usage:" + - echo " task build - Build the application" + - echo " task run - Run the receiver in development mode" + - echo " task run-dev - Run the receiver in development mode" + - echo " task run-prod - Run the receiver in production mode" + - echo " task run-test - Run the receiver in test mode" + - echo " task test - Run tests" + - echo " task clean - Clean build artifacts" + - echo " task fmt - Format the code" + - echo " task deps - Install dependencies" + - echo " task lint - Lint the code" + - echo " task download-schema - Download the GraphQL schema from Hasura server" + - echo " task help - Show this help message" diff --git a/configs/config.development.toml b/configs/config.development.toml new file mode 100644 index 0000000..80bcb08 --- /dev/null +++ b/configs/config.development.toml @@ -0,0 +1,42 @@ +[nats] +url = "nats://localhost:4222" +cluster_id = "test-cluster" +client_id = "test-client" + +[subscription] +topic = "example-topic" +queue_group = "example-group" + +[timeouts] +server_timeout = "30s" +reconnect_wait = "10s" +close_timeout = "10s" +ack_wait_timeout = "5s" + +[[body]] +name = "FPL" +[[body.patterns]] +pattern = "^\\((?P[A-Z]{3})\\-(?P[A-Z]+\\d+)\\-(?P[A-Z]{2})(?:.*\\s*)?\\-(?P[A-Z]+\\d+/?[A-Z]?)\\s*\\-(?P.*)\\s*\\-(?P[A-Z]{4})(?P\\d{4})\\s*\\-(?P[A-Z]+\\d+)(?P[A-Z0-9]+)\\s(?P.*)\\s*\\-(?P[A-Z]{4})(?P\\d{4})\\s(?P[A-Z]{4})\\s*\\-(?PPBN\\/[A-Z0-9]+)\\s(?P