├── .dockerignore ├── .gitignore ├── Makefile ├── README.md ├── Tiltfile ├── cloudbuild.yaml ├── go.mod ├── go.sum ├── infra ├── development │ ├── docker │ │ ├── api-gateway-build.bat │ │ ├── api-gateway.Dockerfile │ │ ├── driver-build.bat │ │ ├── driver-service.Dockerfile │ │ ├── trip-build.bat │ │ └── trip-service.Dockerfile │ └── k8s │ │ ├── api-gateway-deployment.yaml │ │ ├── driver-service-deployment.yaml │ │ └── trip-service-deployment.yaml └── production │ ├── docker │ ├── api-gateway.Dockerfile │ ├── driver-service.Dockerfile │ └── trip-service.Dockerfile │ └── k8s │ ├── api-gateway.yaml │ ├── app-config.yaml │ ├── driver-service.yaml │ └── trip-service.yaml ├── proto ├── driver.proto ├── rider.proto └── trip.proto ├── services ├── api-gateway │ ├── grpc_clients │ │ ├── driver_client │ │ │ └── client.go │ │ └── trip_client │ │ │ └── client.go │ ├── http.go │ ├── json.go │ ├── main.go │ ├── middleware.go │ └── ws.go ├── driver-service │ ├── grpc_handler.go │ ├── json.go │ ├── main.go │ └── service.go └── trip-service │ ├── grpc_handler.go │ └── main.go ├── shared ├── proto │ ├── driver │ │ ├── driver.pb.go │ │ └── driver_grpc.pb.go │ ├── rider │ │ ├── rider.pb.go │ │ └── rider_grpc.pb.go │ └── trip │ │ ├── trip.pb.go │ │ └── trip_grpc.pb.go └── types │ └── types.go ├── skaffold.yaml └── web ├── .gitignore ├── .nvmrc ├── README.md ├── components.json ├── eslint.config.mjs ├── next.config.ts ├── package-lock.json ├── package.json ├── postcss.config.mjs ├── public ├── file.svg ├── globe.svg ├── next.svg ├── vercel.svg └── window.svg ├── src ├── app │ ├── favicon.ico │ ├── globals.css │ ├── layout.tsx │ └── page.tsx ├── assets │ └── Car.svg ├── components │ ├── DriversList.tsx │ ├── MapClickHandler.ts │ ├── NearbyDriversMap.tsx │ ├── RoutingControl.tsx │ └── ui │ │ ├── avatar.tsx │ │ ├── button.tsx │ │ ├── card.tsx │ │ └── scroll-area.tsx ├── constants.ts ├── hooks │ └── useNearbyDrivers.ts ├── lib │ └── utils.ts ├── types.ts └── utils │ └── geohash.ts ├── tailwind.config.ts └── tsconfig.json /.dockerignore: -------------------------------------------------------------------------------- 1 | # Exclude directories 2 | .git/ 3 | node_modules/ 4 | web/ 5 | dist/ 6 | *.log 7 | 8 | # Exclude editor and OS files 9 | .idea/ 10 | .vscode/ 11 | .DS_Store 12 | 13 | # Include shared code 14 | !shared/ 15 | 16 | proto/ 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | tmp 2 | .env 3 | .envrc 4 | bin/ 5 | 6 | # Logs 7 | logs 8 | *.log 9 | npm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | pnpm-debug.log* 13 | lerna-debug.log* 14 | 15 | node_modules 16 | dist 17 | dist-ssr 18 | *.local 19 | 20 | # Editor directories and files 21 | .vscode/* 22 | !.vscode/extensions.json 23 | .idea 24 | .DS_Store 25 | *.suo 26 | *.ntvs* 27 | *.njsproj 28 | *.sln 29 | *.sw? 30 | 31 | # Logs 32 | logs 33 | *.log 34 | npm-debug.log* 35 | yarn-debug.log* 36 | yarn-error.log* 37 | pnpm-debug.log* 38 | lerna-debug.log* 39 | 40 | node_modules 41 | dist 42 | dist-ssr 43 | *.local 44 | 45 | # Editor directories and files 46 | .vscode/* 47 | !.vscode/extensions.json 48 | .idea 49 | .DS_Store 50 | *.suo 51 | *.ntvs* 52 | *.njsproj 53 | *.sln 54 | *.sw? 55 | 56 | 57 | # Tilt build 58 | build/ -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PROTO_DIR := proto 2 | PROTO_SRC := $(wildcard $(PROTO_DIR)/*.proto) 3 | GO_OUT := . 4 | 5 | .PHONY: generate-proto 6 | generate-proto: 7 | protoc \ 8 | --proto_path=$(PROTO_DIR) \ 9 | --go_out=$(GO_OUT) \ 10 | --go-grpc_out=$(GO_OUT) \ 11 | $(PROTO_SRC) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ride Sharing sample k8s microservice project 2 | 3 | Checkout the https://www.selfmadeengineer.com/ where a full course is being built around this project. 4 | 5 | ## Services 6 | 7 | - api-gateway: API Gateway 8 | - driver-service: Driver Service 9 | 10 | ## Intro 11 | This is a golang microservices sample project using Kubernetes for both local development and for production, making you more confident on developing new microservices and deploying them. 12 | 13 | ## Requirements 14 | To run this project locally all you need is [Tilt](https://tilt.dev/) and [Minikube](https://minikube.sigs.k8s.io/docs/) 15 | 16 | Additionally, the `/web` folder is a NextJS web app, for that you need NodeJS (v20.12.0). 17 | 18 | The project also offers a `skaffold.yaml` file which is obsolete, it's still in the project for demo purposes of Tilt vs Skaffold. Use it if you know what you're doing. 19 | 20 | ## Run 21 | 22 | ```bash 23 | tilt up 24 | ``` 25 | 26 | ## Monitor 27 | 28 | ```bash 29 | kubectl get pods 30 | ``` 31 | 32 | or 33 | 34 | ```bash 35 | minikube dashboard 36 | ``` 37 | 38 | ## Deployment (Google Cloud example) 39 | It's advisable to first run the steps manually and then build a proper CI/CD flow according to your infrastructure. 40 | 41 | ## 0. Enviroments 42 | ```bash 43 | REGION: europe-west1 # change according to your location 44 | PROJECT_ID: 45 | ``` 46 | 47 | ## 1. Build Docker Images 48 | Build all docker images and tag them accordingly to push to Artifact Registry. 49 | ```bash 50 | docker build -t {REGION}-docker.pkg.dev/{PROJECT_ID}/ride-sharing/api-gateway:latest --platform linux/amd64 -f infra/production/docker/api-gateway.Dockerfile . 51 | docker push {REGION}-docker.pkg.dev/{PROJECT_ID}/ride-sharing/driver-service:latest -platform linux/amd64 . 52 | ``` 53 | 54 | ## 2. Create a Artifact Registry repository 55 | Go to Google Cloud > Artifact Registry and manually create a docker repository to host your project images. 56 | 57 | ## 3. Push the Docker images to artifact registry 58 | 59 | Docker push the images. 60 | If you get errors pushing: 61 | 1. Make sure to `gcloud login`, select the right project or even `gcloud init`. 62 | 2. Configure artifact on your docker config `gcloud auth configure-docker {REGION}-docker.pkg.dev` [Docs](https://cloud.google.com/artifact-registry/docs/docker/pushing-and-pulling#cred-helper) 63 | 64 | 65 | ## 4. Create a Google Kubernetes Cluster 66 | You can either run a `gcloud` command to start a GKE cluster or manually create a cluster on the UI (recommended). 67 | 68 | ## 5. Update manifests files 69 | 70 | Connect to your remote cluster and apply the kubernetes manifests. 71 | 72 | ```bash 73 | gcloud container clusters get-credentials ride-sharing-cluster --region {REGION}--project {PROJECT_ID} && \ 74 | kubectl apply -f infra/production/k8s 75 | ``` 76 | 77 | If you need to redeploy you can use the same command above or just `kubectl apply -f infra/production/k8s` 78 | Sometimes pods might need to be deleted for new ones to be deployed. 79 | 80 | ```bash 81 | kubectl get pods 82 | kubectl delete pod 83 | 84 | # or for all deployments 85 | kubectl rollout restart deployment 86 | ``` 87 | 88 | ## 6. Enjoy! 89 | ```bash 90 | Get the External IP from the api-gateway 91 | kubectl get services 92 | ``` 93 | 94 | cURL for the /servies or establish a websocket connection to /ws/drivers! 95 | ```bash 96 | curl http://{EXTERNAL_IP}:8081/services 97 | ``` 98 | 99 | Go back to locally developing your project by changing kubernetes context 100 | ```bash 101 | kubectl config get-contexts 102 | 103 | # For Docker Desktop 104 | kubectl config use-context docker-desktop 105 | 106 | # OR for Minikube 107 | kubectl config use-context minikube 108 | ``` 109 | 110 | ## Explanation 111 | 112 | This is a basic example of how to structure a microservice architecture with Kubernetes. 113 | 114 | You can try to run the `tilt up` command and then try to access the `api-gateway` service at `http://localhost:8081`. 115 | 116 | You will see that the websocket request is being routed to one of the `driver-service` pods. 117 | 118 | You can try to scale the `driver-service` to 3 replicas and then try to access the `driver-service` service again. 119 | 120 | You will see that the request is being routed to one of the `driver-service` pods in round-robin fashion (check k8s config). 121 | 122 | This is because the `driver-service` service is configured to use the round-robin algorithm to distribute traffic. 123 | 124 | This is pretty neat and it's a good way to start with Kubernetes and explore the features it offers. 125 | -------------------------------------------------------------------------------- /Tiltfile: -------------------------------------------------------------------------------- 1 | load('ext://restart_process', 'docker_build_with_restart') 2 | 3 | ### API Gateway ### 4 | 5 | gateway_compile_cmd = 'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/api-gateway ./services/api-gateway' 6 | if os.name == 'nt': 7 | gateway_compile_cmd = './infra/development/docker/api-gateway-build.bat' 8 | 9 | local_resource( 10 | 'api-gateway-compile', 11 | gateway_compile_cmd, 12 | deps=['./services/api-gateway']) 13 | 14 | 15 | docker_build_with_restart( 16 | 'ride-sharing/api-gateway', 17 | '.', 18 | entrypoint=['/app/build/api-gateway'], 19 | dockerfile='./infra/development/docker/api-gateway.Dockerfile', 20 | only=[ 21 | './build/api-gateway', 22 | './shared', 23 | ], 24 | live_update=[ 25 | sync('./build', '/app/build'), 26 | sync('./shared', '/app/shared'), 27 | ], 28 | ) 29 | 30 | k8s_yaml('./infra/development/k8s/api-gateway-deployment.yaml') 31 | k8s_resource('api-gateway', port_forwards=8081, 32 | resource_deps=['api-gateway-compile']) 33 | 34 | ### End of API Gateway ### 35 | 36 | ### Driver Service ### 37 | 38 | driver_compile_cmd = 'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/driver-service ./services/driver-service' 39 | if os.name == 'nt': 40 | driver_compile_cmd = './infra/development/docker/driver-service-build.bat' 41 | 42 | local_resource( 43 | 'driver-service-compile', 44 | driver_compile_cmd, 45 | deps=['./services/driver-service']) 46 | 47 | docker_build_with_restart( 48 | 'ride-sharing/driver-service', 49 | '.', 50 | entrypoint=['/app/build/driver-service'], 51 | dockerfile='./infra/development/docker/driver-service.Dockerfile', 52 | only=[ 53 | './build/driver-service', 54 | './shared', 55 | ], 56 | live_update=[ 57 | sync('./build', '/app/build'), 58 | sync('./shared', '/app/shared'), 59 | ], 60 | ) 61 | 62 | k8s_yaml('./infra/development/k8s/driver-service-deployment.yaml') 63 | k8s_resource('driver-service', resource_deps=['driver-service-compile']) 64 | 65 | ### End of Driver Service ### 66 | 67 | 68 | ### Trip Service ### 69 | 70 | trip_compile_cmd = 'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/trip-service ./services/trip-service' 71 | if os.name == 'nt': 72 | trip_compile_cmd = './infra/development/docker/trip-service-build.bat' 73 | 74 | local_resource( 75 | 'trip-service-compile', 76 | trip_compile_cmd, 77 | deps=['./services/trip-service']) 78 | 79 | docker_build_with_restart( 80 | 'ride-sharing/trip-service', 81 | '.', 82 | entrypoint=['/app/build/trip-service'], 83 | dockerfile='./infra/development/docker/trip-service.Dockerfile', 84 | only=[ 85 | './build/trip-service', 86 | './shared', 87 | ], 88 | live_update=[ 89 | sync('./build', '/app/build'), 90 | sync('./shared', '/app/shared'), 91 | ], 92 | ) 93 | 94 | k8s_yaml('./infra/development/k8s/trip-service-deployment.yaml') 95 | k8s_resource('trip-service', resource_deps=['trip-service-compile']) 96 | 97 | ### End of Trip Service ### -------------------------------------------------------------------------------- /cloudbuild.yaml: -------------------------------------------------------------------------------- 1 | steps: 2 | # Build API Gateway (don't forget to add --platform linux/amd64 when building locally) 3 | - id: docker-builder-api-gateway 4 | name: 'gcr.io/cloud-builders/docker' 5 | args: ['build', '-t', 'europe-west1-docker.pkg.dev/$PROJECT_ID/ride-sharing/api-gateway:$COMMIT_SHA', 6 | '-f', 'infra/production/docker/api-gateway.Dockerfile', '.'] 7 | waitFor: ['-'] 8 | 9 | # Build Driver Service (don't forget to add --platform linux/amd64 when building locally) 10 | - id: docker-builder-driver 11 | name: 'gcr.io/cloud-builders/docker' 12 | args: ['build', '-t', 'europe-west1-docker.pkg.dev/$PROJECT_ID/ride-sharing/driver-service:$COMMIT_SHA', 13 | '-f', 'infra/production/docker/driver-service.Dockerfile', '.'] 14 | waitFor: ['-'] 15 | 16 | # Push images (in parallel) 17 | - name: 'gcr.io/cloud-builders/docker' 18 | id: push-api-gateway 19 | args: ['push', 'europe-west1-docker.pkg.dev/$PROJECT_ID/ride-sharing/api-gateway:$COMMIT_SHA'] 20 | waitFor: ['docker-builder-api-gateway'] 21 | 22 | - name: 'gcr.io/cloud-builders/docker' 23 | id: push-driver-service 24 | args: ['push', 'europe-west1-docker.pkg.dev/$PROJECT_ID/ride-sharing/driver-service:$COMMIT_SHA'] 25 | waitFor: ['docker-builder-driver'] 26 | 27 | # Update kubernetes manifests (after all pushes complete) 28 | - id: gke-deploy 29 | name: 'gcr.io/cloud-builders/gke-deploy' 30 | args: 31 | - run 32 | - --filename=infra/production/k8s 33 | - --location=europe-west1 34 | - --cluster=ride-sharing-cluster 35 | waitFor: ['push-api-gateway', 'push-driver-service'] 36 | 37 | images: 38 | - 'europe-west1-docker.pkg.dev/$PROJECT_ID/ride-sharing/api-gateway:$COMMIT_SHA' 39 | - 'europe-west1-docker.pkg.dev/$PROJECT_ID/ride-sharing/driver-service:$COMMIT_SHA' 40 | 41 | timeout: 1800s # 30 minutes 42 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/sikozonpc/ride-sharing 2 | 3 | go 1.23.0 4 | 5 | require ( 6 | google.golang.org/grpc v1.69.4 7 | google.golang.org/protobuf v1.35.1 8 | ) 9 | 10 | require ( 11 | github.com/gorilla/websocket v1.5.3 12 | github.com/mmcloughlin/geohash v0.10.0 13 | golang.org/x/net v0.30.0 // indirect 14 | golang.org/x/sys v0.26.0 // indirect 15 | golang.org/x/text v0.19.0 // indirect 16 | google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect 17 | ) 18 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= 2 | github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= 3 | github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= 4 | github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= 5 | github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= 6 | github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= 7 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 8 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 9 | github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= 10 | github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 11 | github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= 12 | github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 13 | github.com/mmcloughlin/geohash v0.10.0 h1:9w1HchfDfdeLc+jFEf/04D27KP7E2QmpDu52wPbJWRE= 14 | github.com/mmcloughlin/geohash v0.10.0/go.mod h1:oNZxQo5yWJh0eMQEP/8hwQuVx9Z9tjwFUqcTB1SmG0c= 15 | go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY= 16 | go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= 17 | go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE= 18 | go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY= 19 | go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk= 20 | go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08KsbbO5BPT0= 21 | go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4JjxTeYusH7zMc= 22 | go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8= 23 | go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys= 24 | go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= 25 | golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= 26 | golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= 27 | golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= 28 | golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 29 | golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= 30 | golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= 31 | google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 h1:X58yt85/IXCx0Y3ZwN6sEIKZzQtDEYaBWrDvErdXrRE= 32 | google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= 33 | google.golang.org/grpc v1.69.4 h1:MF5TftSMkd8GLw/m0KM6V8CMOCY6NZ1NQDPGFgbTt4A= 34 | google.golang.org/grpc v1.69.4/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4= 35 | google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= 36 | google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= 37 | -------------------------------------------------------------------------------- /infra/development/docker/api-gateway-build.bat: -------------------------------------------------------------------------------- 1 | set CGO_ENABLED=0 2 | set GOOS=linux 3 | set GOARCH=amd64 4 | go build -o build/api-gateway ./services/api-gateway -------------------------------------------------------------------------------- /infra/development/docker/api-gateway.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | WORKDIR /app 3 | 4 | ADD shared shared 5 | ADD build build 6 | 7 | ENTRYPOINT build/api-gateway -------------------------------------------------------------------------------- /infra/development/docker/driver-build.bat: -------------------------------------------------------------------------------- 1 | set CGO_ENABLED=0 2 | set GOOS=linux 3 | set GOARCH=amd64 4 | go build -o build/driver-service ./services/driver-service -------------------------------------------------------------------------------- /infra/development/docker/driver-service.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | WORKDIR /app 3 | 4 | ADD shared shared 5 | ADD build build 6 | 7 | ENTRYPOINT build/driver-service -------------------------------------------------------------------------------- /infra/development/docker/trip-build.bat: -------------------------------------------------------------------------------- 1 | set CGO_ENABLED=0 2 | set GOOS=linux 3 | set GOARCH=amd64 4 | go build -o build/trip-service ./services/trip-service -------------------------------------------------------------------------------- /infra/development/docker/trip-service.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | WORKDIR /app 3 | 4 | ADD shared shared 5 | ADD build build 6 | 7 | ENTRYPOINT build/trip-service -------------------------------------------------------------------------------- /infra/development/k8s/api-gateway-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: api-gateway 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: api-gateway 10 | template: 11 | metadata: 12 | labels: 13 | app: api-gateway 14 | spec: 15 | containers: 16 | - name: api-gateway 17 | image: ride-sharing/api-gateway 18 | ports: 19 | - containerPort: 8081 20 | env: 21 | - name: DRIVER_SERVICE_URL 22 | value: "driver-service:9092" 23 | --- 24 | apiVersion: v1 25 | kind: Service 26 | metadata: 27 | name: api-gateway 28 | spec: 29 | type: LoadBalancer 30 | ports: 31 | - port: 8081 32 | targetPort: 8081 33 | selector: 34 | app: api-gateway 35 | -------------------------------------------------------------------------------- /infra/development/k8s/driver-service-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: driver-service 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: driver-service 10 | template: 11 | metadata: 12 | labels: 13 | app: driver-service 14 | spec: 15 | containers: 16 | - name: driver-service 17 | image: ride-sharing/driver-service 18 | ports: 19 | - containerPort: 8082 20 | - containerPort: 9092 21 | livenessProbe: 22 | httpGet: 23 | path: /health 24 | port: 8082 25 | initialDelaySeconds: 5 26 | periodSeconds: 10 27 | readinessProbe: 28 | httpGet: 29 | path: /health 30 | port: 8082 31 | initialDelaySeconds: 5 32 | periodSeconds: 10 33 | --- 34 | apiVersion: v1 35 | kind: Service 36 | metadata: 37 | name: driver-service 38 | spec: 39 | selector: 40 | app: driver-service 41 | ports: 42 | - port: 8082 43 | name: http 44 | targetPort: 8082 45 | - port: 9092 46 | name: grpc 47 | targetPort: 9092 48 | type: ClusterIP 49 | 50 | -------------------------------------------------------------------------------- /infra/development/k8s/trip-service-deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: trip-service 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: trip-service 10 | template: 11 | metadata: 12 | labels: 13 | app: trip-service 14 | spec: 15 | containers: 16 | - name: trip-service 17 | image: ride-sharing/trip-service 18 | ports: 19 | - containerPort: 9093 20 | --- 21 | apiVersion: v1 22 | kind: Service 23 | metadata: 24 | name: trip-service 25 | spec: 26 | selector: 27 | app: trip-service 28 | ports: 29 | - port: 9093 30 | name: grpc 31 | targetPort: 9093 32 | type: ClusterIP 33 | 34 | -------------------------------------------------------------------------------- /infra/production/docker/api-gateway.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.23 AS builder 2 | WORKDIR /app 3 | COPY . . 4 | WORKDIR /app/services/api-gateway 5 | RUN CGO_ENABLED=0 GOOS=linux go build -o api-gateway 6 | 7 | FROM alpine:latest 8 | RUN apk --no-cache add ca-certificates 9 | WORKDIR /root/ 10 | COPY --from=builder /app/services/api-gateway/api-gateway . 11 | EXPOSE 8081 12 | CMD ["./api-gateway"] -------------------------------------------------------------------------------- /infra/production/docker/driver-service.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.23 AS builder 2 | WORKDIR /app 3 | COPY . . 4 | WORKDIR /app/services/driver-service 5 | RUN CGO_ENABLED=0 GOOS=linux go build -o driver-service 6 | 7 | FROM alpine:latest 8 | RUN apk --no-cache add ca-certificates 9 | WORKDIR /root/ 10 | COPY --from=builder /app/services/driver-service/driver-service . 11 | EXPOSE 8082 12 | EXPOSE 9092 13 | CMD ["./driver-service"] -------------------------------------------------------------------------------- /infra/production/docker/trip-service.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.23 AS builder 2 | WORKDIR /app 3 | COPY . . 4 | WORKDIR /app/services/trip-service 5 | RUN CGO_ENABLED=0 GOOS=linux go build -o trip-service 6 | 7 | FROM alpine:latest 8 | RUN apk --no-cache add ca-certificates 9 | WORKDIR /root/ 10 | COPY --from=builder /app/services/trip-service/trip-service . 11 | EXPOSE 9093 12 | CMD ["./trip-service"] -------------------------------------------------------------------------------- /infra/production/k8s/api-gateway.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: api-gateway 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: api-gateway 10 | template: 11 | metadata: 12 | labels: 13 | app: api-gateway 14 | spec: 15 | containers: 16 | - name: api-gateway 17 | image: europe-west1-docker.pkg.dev/{{PROJECT_ID}}/ride-sharing/api-gateway 18 | ports: 19 | - containerPort: 8081 20 | --- 21 | apiVersion: v1 22 | kind: Service 23 | metadata: 24 | name: api-gateway 25 | spec: 26 | type: LoadBalancer 27 | ports: 28 | - port: 8081 29 | targetPort: 8081 30 | selector: 31 | app: api-gateway 32 | -------------------------------------------------------------------------------- /infra/production/k8s/app-config.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ConfigMap 3 | metadata: 4 | name: app-config 5 | data: 6 | postgres-db: "ride_sharing" 7 | --- 8 | apiVersion: v1 9 | kind: Secret 10 | metadata: 11 | name: db-credentials 12 | type: Opaque 13 | stringData: 14 | username: "postgres" 15 | password: "postgres" -------------------------------------------------------------------------------- /infra/production/k8s/driver-service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: driver-service 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: driver-service 10 | template: 11 | metadata: 12 | labels: 13 | app: driver-service 14 | spec: 15 | containers: 16 | - name: driver-service 17 | image: europe-west1-docker.pkg.dev/{{PROJECT_ID}}/ride-sharing/driver-service 18 | ports: 19 | - containerPort: 8082 20 | - containerPort: 9092 21 | --- 22 | apiVersion: v1 23 | kind: Service 24 | metadata: 25 | name: driver-service 26 | spec: 27 | selector: 28 | app: driver-service 29 | ports: 30 | - port: 8082 31 | name: http 32 | targetPort: 8082 33 | - port: 9092 34 | name: grpc 35 | targetPort: 9092 36 | type: ClusterIP 37 | 38 | -------------------------------------------------------------------------------- /infra/production/k8s/trip-service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: trip-service 5 | spec: 6 | replicas: 1 7 | selector: 8 | matchLabels: 9 | app: trip-service 10 | template: 11 | metadata: 12 | labels: 13 | app: trip-service 14 | spec: 15 | containers: 16 | - name: trip-service 17 | image: europe-west1-docker.pkg.dev/{{PROJECT_ID}}/ride-sharing/trip-service 18 | ports: 19 | - containerPort: 9093 20 | --- 21 | apiVersion: v1 22 | kind: Service 23 | metadata: 24 | name: trip-service 25 | spec: 26 | selector: 27 | app: trip-service 28 | ports: 29 | - port: 9093 30 | name: grpc 31 | targetPort: 9093 32 | type: ClusterIP 33 | 34 | -------------------------------------------------------------------------------- /proto/driver.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package driver; 4 | 5 | option go_package = "shared/proto/driver;driver"; 6 | 7 | message Driver { 8 | string driver_id = 1; 9 | Location location = 2; 10 | string geohash = 3; 11 | } 12 | 13 | message Location { 14 | float latitude = 1; 15 | float longitude = 2; 16 | } 17 | 18 | service DriverService { 19 | rpc FindNearbyDrivers(stream FindNearbyDriversRequest) returns (stream StreamDriversResponse); 20 | } 21 | 22 | message FindNearbyDriversRequest { 23 | Location location = 1; 24 | } 25 | 26 | message StreamDriversResponse { 27 | repeated Driver nearby_drivers = 1; 28 | } -------------------------------------------------------------------------------- /proto/rider.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package rider; 4 | 5 | option go_package = "shared/proto/rider;rider"; 6 | 7 | service RiderService { 8 | rpc GetNearbyRiders(RiderRequest) returns (RiderResponse); 9 | } 10 | 11 | message RiderRequest { 12 | double latitude = 1; 13 | double longitude = 2; 14 | } 15 | 16 | message RiderResponse { 17 | repeated string rider_ids = 1; 18 | } -------------------------------------------------------------------------------- /proto/trip.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package trip; 4 | 5 | option go_package = "shared/proto/trip;trip"; 6 | 7 | service TripService { 8 | rpc CreateTrip(CreateTripRequest) returns (CreateTripResponse); 9 | } 10 | 11 | message CreateTripRequest { 12 | Coordinate start_location = 1; 13 | Coordinate end_location = 2; 14 | } 15 | 16 | message Coordinate { 17 | float latitude = 1; 18 | float longitude = 2; 19 | } 20 | 21 | message Geometry { 22 | repeated Coordinate coordinates = 1; 23 | } 24 | 25 | message Route { 26 | repeated Geometry geometry = 1; 27 | float distance = 2; 28 | float duration = 3; 29 | } 30 | 31 | message CreateTripResponse { 32 | string trip_id = 1; 33 | Route route = 2; 34 | } -------------------------------------------------------------------------------- /services/api-gateway/grpc_clients/driver_client/client.go: -------------------------------------------------------------------------------- 1 | package driver_client 2 | 3 | import ( 4 | "context" 5 | "os" 6 | 7 | pb "github.com/sikozonpc/ride-sharing/shared/proto/driver" 8 | "google.golang.org/grpc" 9 | "google.golang.org/grpc/credentials/insecure" 10 | ) 11 | 12 | type DriverServiceClient struct { 13 | Client pb.DriverServiceClient 14 | conn *grpc.ClientConn 15 | } 16 | 17 | func NewDriverServiceClient() (*DriverServiceClient, error) { 18 | driverServiceURL := os.Getenv("DRIVER_SERVICE_URL") 19 | if driverServiceURL == "" { 20 | driverServiceURL = "driver-service:9092" 21 | } 22 | 23 | conn, err := grpc.NewClient(driverServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials())) 24 | if err != nil { 25 | return nil, err 26 | } 27 | 28 | client := pb.NewDriverServiceClient(conn) 29 | return &DriverServiceClient{ 30 | Client: client, 31 | conn: conn, 32 | }, nil 33 | } 34 | 35 | func (ds *DriverServiceClient) Close() { 36 | if ds.conn != nil { 37 | err := ds.conn.Close() 38 | if err != nil { 39 | return 40 | } 41 | } 42 | } 43 | 44 | func (ds *DriverServiceClient) StreamNearbyDrivers(ctx context.Context) (pb.DriverService_FindNearbyDriversClient, error) { 45 | return ds.Client.FindNearbyDrivers(ctx) 46 | } 47 | -------------------------------------------------------------------------------- /services/api-gateway/grpc_clients/trip_client/client.go: -------------------------------------------------------------------------------- 1 | package trip_client 2 | 3 | import ( 4 | "context" 5 | "os" 6 | 7 | pb "github.com/sikozonpc/ride-sharing/shared/proto/trip" 8 | "google.golang.org/grpc" 9 | "google.golang.org/grpc/credentials/insecure" 10 | ) 11 | 12 | type TripServiceClient struct { 13 | Client pb.TripServiceClient 14 | conn *grpc.ClientConn 15 | } 16 | 17 | func NewTripServiceClient() (*TripServiceClient, error) { 18 | tripServiceURL := os.Getenv("TRIP_SERVICE_URL") 19 | if tripServiceURL == "" { 20 | tripServiceURL = "trip-service:9093" 21 | } 22 | 23 | conn, err := grpc.NewClient(tripServiceURL, grpc.WithTransportCredentials(insecure.NewCredentials())) 24 | if err != nil { 25 | return nil, err 26 | } 27 | 28 | client := pb.NewTripServiceClient(conn) 29 | return &TripServiceClient{ 30 | Client: client, 31 | conn: conn, 32 | }, nil 33 | } 34 | 35 | func (ds *TripServiceClient) Close() { 36 | if ds.conn != nil { 37 | err := ds.conn.Close() 38 | if err != nil { 39 | return 40 | } 41 | } 42 | } 43 | 44 | func (ds *TripServiceClient) CreateTrip(ctx context.Context, req *pb.CreateTripRequest) (*pb.CreateTripResponse, error) { 45 | return ds.Client.CreateTrip(ctx, req) 46 | } 47 | -------------------------------------------------------------------------------- /services/api-gateway/http.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "log" 6 | "net/http" 7 | "os" 8 | 9 | "github.com/sikozonpc/ride-sharing/services/api-gateway/grpc_clients/trip_client" 10 | pb "github.com/sikozonpc/ride-sharing/shared/proto/trip" 11 | "github.com/sikozonpc/ride-sharing/shared/types" 12 | ) 13 | 14 | type Service struct { 15 | URL string `json:"url"` 16 | Name string `json:"name"` 17 | } 18 | 19 | // This is a dummy function to test the K8s DNS 20 | func handleGetServices(w http.ResponseWriter, r *http.Request) { 21 | // Logging the pod name to visually see the replica scaling load balancing 22 | podName := os.Getenv("HOSTNAME") // k8s sets this automatically 23 | log.Printf("Pod %s handling request from: %s to %s", podName, r.RemoteAddr, r.URL.Path) 24 | 25 | var services []Service 26 | services = append(services, Service{ 27 | URL: "http://localhost:8082", 28 | Name: "driver-service", 29 | }) 30 | 31 | err := writeJSON(w, http.StatusOK, services) 32 | if err != nil { 33 | return 34 | } 35 | } 36 | 37 | func handleCreateTrip(w http.ResponseWriter, r *http.Request, tripClient *trip_client.TripServiceClient) { 38 | if r.Method != http.MethodPost { 39 | http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) 40 | return 41 | } 42 | 43 | var reqBody struct { 44 | Pickup types.Location `json:"pickup"` 45 | Destination types.Location `json:"destination"` 46 | } 47 | 48 | if err := json.NewDecoder(r.Body).Decode(&reqBody); err != nil { 49 | http.Error(w, "Failed to parse JSON data", http.StatusBadRequest) 50 | return 51 | } 52 | defer r.Body.Close() 53 | 54 | resp, err := tripClient.CreateTrip(r.Context(), &pb.CreateTripRequest{ 55 | StartLocation: &pb.Coordinate{ 56 | Latitude: float32(reqBody.Pickup.Latitude), 57 | Longitude: float32(reqBody.Pickup.Longitude), 58 | }, 59 | EndLocation: &pb.Coordinate{ 60 | Latitude: float32(reqBody.Destination.Latitude), 61 | Longitude: float32(reqBody.Destination.Longitude), 62 | }, 63 | }) 64 | if err != nil { 65 | http.Error(w, "Failed to create trip", http.StatusInternalServerError) 66 | return 67 | } 68 | 69 | writeJSON(w, http.StatusOK, resp) 70 | } 71 | -------------------------------------------------------------------------------- /services/api-gateway/json.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "net/http" 6 | ) 7 | 8 | func writeJSON(w http.ResponseWriter, status int, data any) error { 9 | w.Header().Set("Content-Type", "application/json") 10 | w.WriteHeader(status) 11 | return json.NewEncoder(w).Encode(data) 12 | } 13 | -------------------------------------------------------------------------------- /services/api-gateway/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "net/http" 6 | 7 | "github.com/sikozonpc/ride-sharing/services/api-gateway/grpc_clients/driver_client" 8 | "github.com/sikozonpc/ride-sharing/services/api-gateway/grpc_clients/trip_client" 9 | 10 | "github.com/gorilla/websocket" 11 | ) 12 | 13 | var upgrader = websocket.Upgrader{ 14 | CheckOrigin: func(r *http.Request) bool { 15 | return true // Allow all origins for now 16 | }, 17 | } 18 | 19 | var HttpAddr = ":8081" 20 | 21 | func main() { 22 | // Initialize gRPC clients 23 | driverClient, err := driver_client.NewDriverServiceClient() 24 | if err != nil { 25 | log.Fatal(err) 26 | } 27 | defer driverClient.Close() 28 | 29 | tripClient, err := trip_client.NewTripServiceClient() 30 | if err != nil { 31 | log.Fatal(err) 32 | } 33 | defer tripClient.Close() 34 | 35 | // Get services (for debugging purposes) 36 | http.HandleFunc("/services", enableCORS(handleGetServices)) 37 | 38 | // Live stream driver locations 39 | http.HandleFunc("/ws/drivers", func(w http.ResponseWriter, r *http.Request) { 40 | handleDriversWebSocket(w, r, driverClient) 41 | }) 42 | 43 | http.HandleFunc("/trip", enableCORS(func(w http.ResponseWriter, r *http.Request) { 44 | handleCreateTrip(w, r, tripClient) 45 | })) 46 | 47 | log.Printf("Starting api gateway on port %s", HttpAddr) 48 | log.Fatal(http.ListenAndServe(HttpAddr, nil)) 49 | } 50 | -------------------------------------------------------------------------------- /services/api-gateway/middleware.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "net/http" 4 | 5 | func enableCORS(handler http.HandlerFunc) http.HandlerFunc { 6 | return func(w http.ResponseWriter, r *http.Request) { 7 | w.Header().Set("Access-Control-Allow-Origin", "*") 8 | w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS") 9 | w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") 10 | 11 | if r.Method == "OPTIONS" { 12 | w.WriteHeader(http.StatusOK) 13 | return 14 | } 15 | 16 | handler(w, r) 17 | } 18 | } -------------------------------------------------------------------------------- /services/api-gateway/ws.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/gorilla/websocket" 6 | "github.com/sikozonpc/ride-sharing/services/api-gateway/grpc_clients/driver_client" 7 | pb "github.com/sikozonpc/ride-sharing/shared/proto/driver" 8 | "log" 9 | "net/http" 10 | ) 11 | 12 | func handleDriversWebSocket(w http.ResponseWriter, r *http.Request, client *driver_client.DriverServiceClient) { 13 | conn, err := upgrader.Upgrade(w, r, nil) 14 | if err != nil { 15 | log.Printf("WebSocket upgrade failed: %v", err) 16 | return 17 | } 18 | defer func(conn *websocket.Conn) { 19 | _ = conn.Close() 20 | }(conn) 21 | 22 | log.Println("Client connected via WebSocket") 23 | 24 | // Channel to listen for client messages (e.g., user location updates) 25 | clientLocations := make(chan *pb.Location) 26 | go func() { 27 | for { 28 | // Read message from WebSocket 29 | _, msg, err := conn.ReadMessage() 30 | if err != nil { 31 | log.Println("Error reading WebSocket message:", err) 32 | close(clientLocations) 33 | return 34 | } 35 | 36 | var location pb.Location 37 | if err := json.Unmarshal(msg, &location); err != nil { 38 | log.Println("Invalid location data:", err) 39 | continue 40 | } 41 | clientLocations <- &location 42 | } 43 | }() 44 | 45 | // Start streaming driver updates 46 | stream, err := client.StreamNearbyDrivers(r.Context()) 47 | if err != nil { 48 | log.Println("Failed to start gRPC stream:", err) 49 | return 50 | } 51 | defer stream.CloseSend() 52 | 53 | // Handle sending client location updates to the driver service 54 | go func() { 55 | for loc := range clientLocations { 56 | err := stream.Send(&pb.FindNearbyDriversRequest{Location: loc}) 57 | if err != nil { 58 | log.Println("Failed to send location to driver service:", err) 59 | return 60 | } 61 | } 62 | }() 63 | 64 | // Receive driver updates from driver service and forward them to the client 65 | for { 66 | res, err := stream.Recv() 67 | if err != nil { 68 | log.Println("Error receiving driver updates:", err) 69 | return 70 | } 71 | 72 | driversJSON, err := json.Marshal(res.NearbyDrivers) 73 | if err != nil { 74 | log.Println("Error marshaling driver updates:", err) 75 | continue 76 | } 77 | 78 | // Send driver updates to the WebSocket client 79 | if err := conn.WriteMessage(websocket.TextMessage, driversJSON); err != nil { 80 | log.Println("Error sending driver updates:", err) 81 | return 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /services/driver-service/grpc_handler.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "time" 7 | 8 | pb "github.com/sikozonpc/ride-sharing/shared/proto/driver" 9 | "google.golang.org/grpc" 10 | ) 11 | 12 | type DriverGrpcHandler struct { 13 | pb.UnimplementedDriverServiceServer 14 | 15 | service *Service 16 | } 17 | 18 | func NewGrpcHandler(s *grpc.Server, service *Service) { 19 | var drivers []*Driver 20 | for i, route := range predefinedRoutes { 21 | drivers = append(drivers, &Driver{ 22 | DriverId: fmt.Sprintf("driver-%d", i), 23 | Route: route, 24 | Index: 0, 25 | }) 26 | } 27 | handler := &DriverGrpcHandler{ 28 | service: service, 29 | } 30 | 31 | pb.RegisterDriverServiceServer(s, handler) 32 | } 33 | 34 | func (h *DriverGrpcHandler) FindNearbyDrivers(reqStream pb.DriverService_FindNearbyDriversServer) error { 35 | ticker := time.NewTicker(3 * time.Second) 36 | defer ticker.Stop() 37 | 38 | for { 39 | select { 40 | case <-reqStream.Context().Done(): 41 | log.Println("Client disconnected from gRPC stream") 42 | return reqStream.Context().Err() 43 | case <-ticker.C: 44 | drivers := h.service.FindNearbyDrivers() 45 | 46 | // Stream updated drivers 47 | err := reqStream.Send(&pb.StreamDriversResponse{NearbyDrivers: drivers}) 48 | if err != nil { 49 | log.Println("Error streaming drivers:", err) 50 | return err 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /services/driver-service/json.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "net/http" 6 | ) 7 | 8 | func writeJSON(w http.ResponseWriter, status int, data any) error { 9 | w.Header().Set("Content-Type", "application/json") 10 | w.WriteHeader(status) 11 | return json.NewEncoder(w).Encode(data) 12 | } 13 | -------------------------------------------------------------------------------- /services/driver-service/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "net" 6 | "net/http" 7 | 8 | "google.golang.org/grpc" 9 | ) 10 | 11 | var GrpcAddr = ":9092" 12 | var HttpAddr = ":8082" 13 | 14 | func main() { 15 | // Start HTTP server 16 | go func() { 17 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 18 | log.Printf("Request from: %s to %s", r.RemoteAddr, r.URL.Path) 19 | writeJSON(w, http.StatusOK, map[string]string{"message": "Hello, Driver Service!"}) 20 | }) 21 | log.Println("Starting driver service HTTP on port 8082") 22 | log.Fatal(http.ListenAndServe(HttpAddr, nil)) 23 | }() 24 | 25 | // Start gRPC server 26 | lis, err := net.Listen("tcp", GrpcAddr) 27 | if err != nil { 28 | log.Fatalf("Failed to listen: %v", err) 29 | } 30 | 31 | grpcServer := grpc.NewServer() 32 | 33 | service := NewService() 34 | NewGrpcHandler(grpcServer, service) 35 | 36 | log.Printf("Starting gRPC server on port %s", lis.Addr().String()) 37 | if err := grpcServer.Serve(lis); err != nil { 38 | log.Fatalf("Failed to serve: %v", err) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /services/driver-service/service.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/mmcloughlin/geohash" 7 | pb "github.com/sikozonpc/ride-sharing/shared/proto/driver" 8 | ) 9 | 10 | // Predefined routes for drivers 11 | // Get this coordinates from Google Maps for example and build a route 12 | var predefinedRoutes = [][][]float64{ 13 | { 14 | {37.768727753110106, -122.41345597077878}, 15 | {37.77019784198334, -122.41298146942745}, 16 | {37.77163599059948, -122.41125013468515}, 17 | {37.773790702602305, -122.41168660785345}, 18 | }, 19 | { 20 | {37.78938865879484, -122.42206098118852}, 21 | {37.79112418447625, -122.42238063604239}, 22 | {37.79160600785717, -122.42249902672565}, 23 | {37.79111015076977, -122.42238063603901}, 24 | {37.791797800743794, -122.42253454393163}, 25 | {37.79353326986209, -122.4228837964593}, 26 | {37.7939729779581, -122.42294891128813}, 27 | {37.793739091013016, -122.42474844980799}, 28 | {37.79289241408059, -122.42455310517508}, 29 | {37.792172029382556, -122.4244643121601}, 30 | {37.79264916808487, -122.42616913804746}, 31 | }, 32 | { 33 | {37.78647766728455, -122.42321282905907}, 34 | {37.78374742447772, -122.42269398620836}, 35 | {37.78300293033823, -122.4225475612199}, 36 | {37.78291035023184, -122.42089295885036}, 37 | {37.78310564009152, -122.41910523857551}, 38 | {37.783340947012974, -122.41759218036147}, 39 | {37.78242075518227, -122.41739703541508}, 40 | {37.78149494160786, -122.41715787460058}, 41 | }, 42 | { 43 | {37.78149494160786, -122.41715787460058}, 44 | {37.78242075518227, -122.41739703541508}, 45 | {37.783340947012974, -122.41759218036147}, 46 | {37.78310564009152, -122.41910523857551}, 47 | {37.78291035023184, -122.42089295885036}, 48 | {37.78374742447772, -122.42269398620836}, 49 | {37.78647766728455, -122.42321282905907}, 50 | {37.78300293033823, -122.4225475612199}, 51 | }, 52 | } 53 | 54 | type Driver struct { 55 | DriverId string 56 | Route [][]float64 57 | Index int // Current position in the route 58 | } 59 | 60 | type Service struct { 61 | drivers []*Driver 62 | } 63 | 64 | func NewService() *Service { 65 | var drivers []*Driver 66 | for i, route := range predefinedRoutes { 67 | drivers = append(drivers, &Driver{ 68 | DriverId: fmt.Sprintf("driver-%d", i), 69 | Route: route, 70 | Index: 0, 71 | }) 72 | } 73 | 74 | return &Service{ 75 | drivers, 76 | } 77 | } 78 | 79 | func (s *Service) FindNearbyDrivers() []*pb.Driver { 80 | var drivers []*pb.Driver 81 | 82 | for _, driver := range s.drivers { 83 | // Get current position and move to the next waypoint 84 | lat := driver.Route[driver.Index][0] 85 | lng := driver.Route[driver.Index][1] 86 | driver.Index = (driver.Index + 1) % len(driver.Route) // Loop back at end of route 87 | 88 | // Update driver protobuf object 89 | pbDriver := &pb.Driver{ 90 | DriverId: driver.DriverId, 91 | Location: &pb.Location{ 92 | Latitude: float32(lat), 93 | Longitude: float32(lng), 94 | }, 95 | Geohash: geohash.Encode(lat, lng), 96 | } 97 | drivers = append(drivers, pbDriver) 98 | } 99 | 100 | return drivers 101 | } 102 | -------------------------------------------------------------------------------- /services/trip-service/grpc_handler.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "fmt" 7 | "io" 8 | "net/http" 9 | 10 | pb "github.com/sikozonpc/ride-sharing/shared/proto/trip" 11 | "google.golang.org/grpc" 12 | "google.golang.org/grpc/codes" 13 | "google.golang.org/grpc/status" 14 | ) 15 | 16 | type TripGrpcHandler struct { 17 | pb.UnimplementedTripServiceServer 18 | } 19 | 20 | func NewGrpcHandler(s *grpc.Server) { 21 | handler := &TripGrpcHandler{} 22 | 23 | pb.RegisterTripServiceServer(s, handler) 24 | } 25 | 26 | func (h *TripGrpcHandler) CreateTrip(ctx context.Context, req *pb.CreateTripRequest) (*pb.CreateTripResponse, error) { 27 | pickup := req.StartLocation 28 | destination := req.EndLocation 29 | 30 | url := fmt.Sprintf( 31 | "https://router.project-osrm.org/route/v1/driving/%f,%f;%f,%f?overview=full&geometries=geojson", 32 | pickup.Longitude, pickup.Latitude, 33 | destination.Longitude, destination.Latitude, 34 | ) 35 | 36 | // Make HTTP request 37 | resp, err := http.Get(url) 38 | if err != nil { 39 | return nil, status.Errorf(codes.Internal, "failed to fetch route: %v", err) 40 | } 41 | defer resp.Body.Close() 42 | 43 | // Read and parse response 44 | body, err := io.ReadAll(resp.Body) 45 | if err != nil { 46 | return nil, status.Errorf(codes.Internal, "failed to read response: %v", err) 47 | } 48 | 49 | type OSRMResponse struct { 50 | Routes []struct { 51 | Distance float64 `json:"distance"` 52 | Duration float64 `json:"duration"` 53 | Geometry struct { 54 | Coordinates [][]float64 `json:"coordinates"` 55 | } `json:"geometry"` 56 | } `json:"routes"` 57 | } 58 | var routeResp OSRMResponse 59 | 60 | if err := json.Unmarshal(body, &routeResp); err != nil { 61 | return nil, status.Errorf(codes.Internal, "failed to parse response: %v", err) 62 | } 63 | 64 | // parse OSRMResponse to pb.Route 65 | route := routeResp.Routes[0] 66 | geometry := route.Geometry.Coordinates 67 | coordinates := make([]*pb.Coordinate, len(geometry)) 68 | for i, coord := range geometry { 69 | coordinates[i] = &pb.Coordinate{ 70 | Latitude: float32(coord[0]), 71 | Longitude: float32(coord[1]), 72 | } 73 | } 74 | 75 | return &pb.CreateTripResponse{ 76 | Route: &pb.Route{ 77 | Geometry: []*pb.Geometry{ 78 | { 79 | Coordinates: coordinates, 80 | }, 81 | }, 82 | Distance: float32(route.Distance), 83 | Duration: float32(route.Duration), 84 | }, 85 | }, nil 86 | } 87 | -------------------------------------------------------------------------------- /services/trip-service/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "log" 5 | "net" 6 | 7 | "google.golang.org/grpc" 8 | ) 9 | 10 | var GrpcAddr = ":9093" 11 | 12 | func main() { 13 | // Start gRPC server 14 | lis, err := net.Listen("tcp", GrpcAddr) 15 | if err != nil { 16 | log.Fatalf("Failed to listen: %v", err) 17 | } 18 | 19 | grpcServer := grpc.NewServer() 20 | 21 | NewGrpcHandler(grpcServer) 22 | 23 | log.Printf("Starting gRPC server Trip service on port %s", lis.Addr().String()) 24 | if err := grpcServer.Serve(lis); err != nil { 25 | log.Fatalf("Failed to serve: %v", err) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /shared/proto/driver/driver.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.28.1 4 | // protoc v4.25.1 5 | // source: driver.proto 6 | 7 | package driver 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 | reflect "reflect" 13 | sync "sync" 14 | ) 15 | 16 | const ( 17 | // Verify that this generated code is sufficiently up-to-date. 18 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 19 | // Verify that runtime/protoimpl is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 21 | ) 22 | 23 | type Driver struct { 24 | state protoimpl.MessageState 25 | sizeCache protoimpl.SizeCache 26 | unknownFields protoimpl.UnknownFields 27 | 28 | DriverId string `protobuf:"bytes,1,opt,name=driver_id,json=driverId,proto3" json:"driver_id,omitempty"` 29 | Location *Location `protobuf:"bytes,2,opt,name=location,proto3" json:"location,omitempty"` 30 | Geohash string `protobuf:"bytes,3,opt,name=geohash,proto3" json:"geohash,omitempty"` 31 | } 32 | 33 | func (x *Driver) Reset() { 34 | *x = Driver{} 35 | if protoimpl.UnsafeEnabled { 36 | mi := &file_driver_proto_msgTypes[0] 37 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 38 | ms.StoreMessageInfo(mi) 39 | } 40 | } 41 | 42 | func (x *Driver) String() string { 43 | return protoimpl.X.MessageStringOf(x) 44 | } 45 | 46 | func (*Driver) ProtoMessage() {} 47 | 48 | func (x *Driver) ProtoReflect() protoreflect.Message { 49 | mi := &file_driver_proto_msgTypes[0] 50 | if protoimpl.UnsafeEnabled && x != nil { 51 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 52 | if ms.LoadMessageInfo() == nil { 53 | ms.StoreMessageInfo(mi) 54 | } 55 | return ms 56 | } 57 | return mi.MessageOf(x) 58 | } 59 | 60 | // Deprecated: Use Driver.ProtoReflect.Descriptor instead. 61 | func (*Driver) Descriptor() ([]byte, []int) { 62 | return file_driver_proto_rawDescGZIP(), []int{0} 63 | } 64 | 65 | func (x *Driver) GetDriverId() string { 66 | if x != nil { 67 | return x.DriverId 68 | } 69 | return "" 70 | } 71 | 72 | func (x *Driver) GetLocation() *Location { 73 | if x != nil { 74 | return x.Location 75 | } 76 | return nil 77 | } 78 | 79 | func (x *Driver) GetGeohash() string { 80 | if x != nil { 81 | return x.Geohash 82 | } 83 | return "" 84 | } 85 | 86 | type Location struct { 87 | state protoimpl.MessageState 88 | sizeCache protoimpl.SizeCache 89 | unknownFields protoimpl.UnknownFields 90 | 91 | Latitude float32 `protobuf:"fixed32,1,opt,name=latitude,proto3" json:"latitude,omitempty"` 92 | Longitude float32 `protobuf:"fixed32,2,opt,name=longitude,proto3" json:"longitude,omitempty"` 93 | } 94 | 95 | func (x *Location) Reset() { 96 | *x = Location{} 97 | if protoimpl.UnsafeEnabled { 98 | mi := &file_driver_proto_msgTypes[1] 99 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 100 | ms.StoreMessageInfo(mi) 101 | } 102 | } 103 | 104 | func (x *Location) String() string { 105 | return protoimpl.X.MessageStringOf(x) 106 | } 107 | 108 | func (*Location) ProtoMessage() {} 109 | 110 | func (x *Location) ProtoReflect() protoreflect.Message { 111 | mi := &file_driver_proto_msgTypes[1] 112 | if protoimpl.UnsafeEnabled && x != nil { 113 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 114 | if ms.LoadMessageInfo() == nil { 115 | ms.StoreMessageInfo(mi) 116 | } 117 | return ms 118 | } 119 | return mi.MessageOf(x) 120 | } 121 | 122 | // Deprecated: Use Location.ProtoReflect.Descriptor instead. 123 | func (*Location) Descriptor() ([]byte, []int) { 124 | return file_driver_proto_rawDescGZIP(), []int{1} 125 | } 126 | 127 | func (x *Location) GetLatitude() float32 { 128 | if x != nil { 129 | return x.Latitude 130 | } 131 | return 0 132 | } 133 | 134 | func (x *Location) GetLongitude() float32 { 135 | if x != nil { 136 | return x.Longitude 137 | } 138 | return 0 139 | } 140 | 141 | type FindNearbyDriversRequest struct { 142 | state protoimpl.MessageState 143 | sizeCache protoimpl.SizeCache 144 | unknownFields protoimpl.UnknownFields 145 | 146 | Location *Location `protobuf:"bytes,1,opt,name=location,proto3" json:"location,omitempty"` 147 | } 148 | 149 | func (x *FindNearbyDriversRequest) Reset() { 150 | *x = FindNearbyDriversRequest{} 151 | if protoimpl.UnsafeEnabled { 152 | mi := &file_driver_proto_msgTypes[2] 153 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 154 | ms.StoreMessageInfo(mi) 155 | } 156 | } 157 | 158 | func (x *FindNearbyDriversRequest) String() string { 159 | return protoimpl.X.MessageStringOf(x) 160 | } 161 | 162 | func (*FindNearbyDriversRequest) ProtoMessage() {} 163 | 164 | func (x *FindNearbyDriversRequest) ProtoReflect() protoreflect.Message { 165 | mi := &file_driver_proto_msgTypes[2] 166 | if protoimpl.UnsafeEnabled && x != nil { 167 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 168 | if ms.LoadMessageInfo() == nil { 169 | ms.StoreMessageInfo(mi) 170 | } 171 | return ms 172 | } 173 | return mi.MessageOf(x) 174 | } 175 | 176 | // Deprecated: Use FindNearbyDriversRequest.ProtoReflect.Descriptor instead. 177 | func (*FindNearbyDriversRequest) Descriptor() ([]byte, []int) { 178 | return file_driver_proto_rawDescGZIP(), []int{2} 179 | } 180 | 181 | func (x *FindNearbyDriversRequest) GetLocation() *Location { 182 | if x != nil { 183 | return x.Location 184 | } 185 | return nil 186 | } 187 | 188 | type StreamDriversResponse struct { 189 | state protoimpl.MessageState 190 | sizeCache protoimpl.SizeCache 191 | unknownFields protoimpl.UnknownFields 192 | 193 | NearbyDrivers []*Driver `protobuf:"bytes,1,rep,name=nearby_drivers,json=nearbyDrivers,proto3" json:"nearby_drivers,omitempty"` 194 | } 195 | 196 | func (x *StreamDriversResponse) Reset() { 197 | *x = StreamDriversResponse{} 198 | if protoimpl.UnsafeEnabled { 199 | mi := &file_driver_proto_msgTypes[3] 200 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 201 | ms.StoreMessageInfo(mi) 202 | } 203 | } 204 | 205 | func (x *StreamDriversResponse) String() string { 206 | return protoimpl.X.MessageStringOf(x) 207 | } 208 | 209 | func (*StreamDriversResponse) ProtoMessage() {} 210 | 211 | func (x *StreamDriversResponse) ProtoReflect() protoreflect.Message { 212 | mi := &file_driver_proto_msgTypes[3] 213 | if protoimpl.UnsafeEnabled && x != nil { 214 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 215 | if ms.LoadMessageInfo() == nil { 216 | ms.StoreMessageInfo(mi) 217 | } 218 | return ms 219 | } 220 | return mi.MessageOf(x) 221 | } 222 | 223 | // Deprecated: Use StreamDriversResponse.ProtoReflect.Descriptor instead. 224 | func (*StreamDriversResponse) Descriptor() ([]byte, []int) { 225 | return file_driver_proto_rawDescGZIP(), []int{3} 226 | } 227 | 228 | func (x *StreamDriversResponse) GetNearbyDrivers() []*Driver { 229 | if x != nil { 230 | return x.NearbyDrivers 231 | } 232 | return nil 233 | } 234 | 235 | var File_driver_proto protoreflect.FileDescriptor 236 | 237 | var file_driver_proto_rawDesc = []byte{ 238 | 0x0a, 0x0c, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, 239 | 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x22, 0x6d, 0x0a, 0x06, 0x44, 0x72, 0x69, 0x76, 0x65, 0x72, 240 | 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 241 | 0x01, 0x28, 0x09, 0x52, 0x08, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x2c, 0x0a, 242 | 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 243 | 0x10, 0x2e, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x2e, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 244 | 0x6e, 0x52, 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x67, 245 | 0x65, 0x6f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x67, 0x65, 246 | 0x6f, 0x68, 0x61, 0x73, 0x68, 0x22, 0x44, 0x0a, 0x08, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 247 | 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x01, 0x20, 248 | 0x01, 0x28, 0x02, 0x52, 0x08, 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 0x12, 0x1c, 0x0a, 249 | 0x09, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x02, 250 | 0x52, 0x09, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x22, 0x48, 0x0a, 0x18, 0x46, 251 | 0x69, 0x6e, 0x64, 0x4e, 0x65, 0x61, 0x72, 0x62, 0x79, 0x44, 0x72, 0x69, 0x76, 0x65, 0x72, 0x73, 252 | 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2c, 0x0a, 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x74, 253 | 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x64, 0x72, 0x69, 0x76, 254 | 0x65, 0x72, 0x2e, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x08, 0x6c, 0x6f, 0x63, 255 | 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x4e, 0x0a, 0x15, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x44, 256 | 0x72, 0x69, 0x76, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x35, 257 | 0x0a, 0x0e, 0x6e, 0x65, 0x61, 0x72, 0x62, 0x79, 0x5f, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x73, 258 | 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x2e, 259 | 0x44, 0x72, 0x69, 0x76, 0x65, 0x72, 0x52, 0x0d, 0x6e, 0x65, 0x61, 0x72, 0x62, 0x79, 0x44, 0x72, 260 | 0x69, 0x76, 0x65, 0x72, 0x73, 0x32, 0x69, 0x0a, 0x0d, 0x44, 0x72, 0x69, 0x76, 0x65, 0x72, 0x53, 261 | 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x58, 0x0a, 0x11, 0x46, 0x69, 0x6e, 0x64, 0x4e, 0x65, 262 | 0x61, 0x72, 0x62, 0x79, 0x44, 0x72, 0x69, 0x76, 0x65, 0x72, 0x73, 0x12, 0x20, 0x2e, 0x64, 0x72, 263 | 0x69, 0x76, 0x65, 0x72, 0x2e, 0x46, 0x69, 0x6e, 0x64, 0x4e, 0x65, 0x61, 0x72, 0x62, 0x79, 0x44, 264 | 0x72, 0x69, 0x76, 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 265 | 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x2e, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x44, 0x72, 0x69, 266 | 0x76, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x28, 0x01, 0x30, 0x01, 267 | 0x42, 0x1c, 0x5a, 0x1a, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 268 | 0x2f, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x3b, 0x64, 0x72, 0x69, 0x76, 0x65, 0x72, 0x62, 0x06, 269 | 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 270 | } 271 | 272 | var ( 273 | file_driver_proto_rawDescOnce sync.Once 274 | file_driver_proto_rawDescData = file_driver_proto_rawDesc 275 | ) 276 | 277 | func file_driver_proto_rawDescGZIP() []byte { 278 | file_driver_proto_rawDescOnce.Do(func() { 279 | file_driver_proto_rawDescData = protoimpl.X.CompressGZIP(file_driver_proto_rawDescData) 280 | }) 281 | return file_driver_proto_rawDescData 282 | } 283 | 284 | var file_driver_proto_msgTypes = make([]protoimpl.MessageInfo, 4) 285 | var file_driver_proto_goTypes = []interface{}{ 286 | (*Driver)(nil), // 0: driver.Driver 287 | (*Location)(nil), // 1: driver.Location 288 | (*FindNearbyDriversRequest)(nil), // 2: driver.FindNearbyDriversRequest 289 | (*StreamDriversResponse)(nil), // 3: driver.StreamDriversResponse 290 | } 291 | var file_driver_proto_depIdxs = []int32{ 292 | 1, // 0: driver.Driver.location:type_name -> driver.Location 293 | 1, // 1: driver.FindNearbyDriversRequest.location:type_name -> driver.Location 294 | 0, // 2: driver.StreamDriversResponse.nearby_drivers:type_name -> driver.Driver 295 | 2, // 3: driver.DriverService.FindNearbyDrivers:input_type -> driver.FindNearbyDriversRequest 296 | 3, // 4: driver.DriverService.FindNearbyDrivers:output_type -> driver.StreamDriversResponse 297 | 4, // [4:5] is the sub-list for method output_type 298 | 3, // [3:4] is the sub-list for method input_type 299 | 3, // [3:3] is the sub-list for extension type_name 300 | 3, // [3:3] is the sub-list for extension extendee 301 | 0, // [0:3] is the sub-list for field type_name 302 | } 303 | 304 | func init() { file_driver_proto_init() } 305 | func file_driver_proto_init() { 306 | if File_driver_proto != nil { 307 | return 308 | } 309 | if !protoimpl.UnsafeEnabled { 310 | file_driver_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 311 | switch v := v.(*Driver); i { 312 | case 0: 313 | return &v.state 314 | case 1: 315 | return &v.sizeCache 316 | case 2: 317 | return &v.unknownFields 318 | default: 319 | return nil 320 | } 321 | } 322 | file_driver_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 323 | switch v := v.(*Location); i { 324 | case 0: 325 | return &v.state 326 | case 1: 327 | return &v.sizeCache 328 | case 2: 329 | return &v.unknownFields 330 | default: 331 | return nil 332 | } 333 | } 334 | file_driver_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { 335 | switch v := v.(*FindNearbyDriversRequest); i { 336 | case 0: 337 | return &v.state 338 | case 1: 339 | return &v.sizeCache 340 | case 2: 341 | return &v.unknownFields 342 | default: 343 | return nil 344 | } 345 | } 346 | file_driver_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { 347 | switch v := v.(*StreamDriversResponse); i { 348 | case 0: 349 | return &v.state 350 | case 1: 351 | return &v.sizeCache 352 | case 2: 353 | return &v.unknownFields 354 | default: 355 | return nil 356 | } 357 | } 358 | } 359 | type x struct{} 360 | out := protoimpl.TypeBuilder{ 361 | File: protoimpl.DescBuilder{ 362 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 363 | RawDescriptor: file_driver_proto_rawDesc, 364 | NumEnums: 0, 365 | NumMessages: 4, 366 | NumExtensions: 0, 367 | NumServices: 1, 368 | }, 369 | GoTypes: file_driver_proto_goTypes, 370 | DependencyIndexes: file_driver_proto_depIdxs, 371 | MessageInfos: file_driver_proto_msgTypes, 372 | }.Build() 373 | File_driver_proto = out.File 374 | file_driver_proto_rawDesc = nil 375 | file_driver_proto_goTypes = nil 376 | file_driver_proto_depIdxs = nil 377 | } 378 | -------------------------------------------------------------------------------- /shared/proto/driver/driver_grpc.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-grpc. DO NOT EDIT. 2 | // versions: 3 | // - protoc-gen-go-grpc v1.2.0 4 | // - protoc v4.25.1 5 | // source: driver.proto 6 | 7 | package driver 8 | 9 | import ( 10 | context "context" 11 | grpc "google.golang.org/grpc" 12 | codes "google.golang.org/grpc/codes" 13 | status "google.golang.org/grpc/status" 14 | ) 15 | 16 | // This is a compile-time assertion to ensure that this generated file 17 | // is compatible with the grpc package it is being compiled against. 18 | // Requires gRPC-Go v1.32.0 or later. 19 | const _ = grpc.SupportPackageIsVersion7 20 | 21 | // DriverServiceClient is the client API for DriverService service. 22 | // 23 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 24 | type DriverServiceClient interface { 25 | FindNearbyDrivers(ctx context.Context, opts ...grpc.CallOption) (DriverService_FindNearbyDriversClient, error) 26 | } 27 | 28 | type driverServiceClient struct { 29 | cc grpc.ClientConnInterface 30 | } 31 | 32 | func NewDriverServiceClient(cc grpc.ClientConnInterface) DriverServiceClient { 33 | return &driverServiceClient{cc} 34 | } 35 | 36 | func (c *driverServiceClient) FindNearbyDrivers(ctx context.Context, opts ...grpc.CallOption) (DriverService_FindNearbyDriversClient, error) { 37 | stream, err := c.cc.NewStream(ctx, &DriverService_ServiceDesc.Streams[0], "/driver.DriverService/FindNearbyDrivers", opts...) 38 | if err != nil { 39 | return nil, err 40 | } 41 | x := &driverServiceFindNearbyDriversClient{stream} 42 | return x, nil 43 | } 44 | 45 | type DriverService_FindNearbyDriversClient interface { 46 | Send(*FindNearbyDriversRequest) error 47 | Recv() (*StreamDriversResponse, error) 48 | grpc.ClientStream 49 | } 50 | 51 | type driverServiceFindNearbyDriversClient struct { 52 | grpc.ClientStream 53 | } 54 | 55 | func (x *driverServiceFindNearbyDriversClient) Send(m *FindNearbyDriversRequest) error { 56 | return x.ClientStream.SendMsg(m) 57 | } 58 | 59 | func (x *driverServiceFindNearbyDriversClient) Recv() (*StreamDriversResponse, error) { 60 | m := new(StreamDriversResponse) 61 | if err := x.ClientStream.RecvMsg(m); err != nil { 62 | return nil, err 63 | } 64 | return m, nil 65 | } 66 | 67 | // DriverServiceServer is the server API for DriverService service. 68 | // All implementations must embed UnimplementedDriverServiceServer 69 | // for forward compatibility 70 | type DriverServiceServer interface { 71 | FindNearbyDrivers(DriverService_FindNearbyDriversServer) error 72 | mustEmbedUnimplementedDriverServiceServer() 73 | } 74 | 75 | // UnimplementedDriverServiceServer must be embedded to have forward compatible implementations. 76 | type UnimplementedDriverServiceServer struct { 77 | } 78 | 79 | func (UnimplementedDriverServiceServer) FindNearbyDrivers(DriverService_FindNearbyDriversServer) error { 80 | return status.Errorf(codes.Unimplemented, "method FindNearbyDrivers not implemented") 81 | } 82 | func (UnimplementedDriverServiceServer) mustEmbedUnimplementedDriverServiceServer() {} 83 | 84 | // UnsafeDriverServiceServer may be embedded to opt out of forward compatibility for this service. 85 | // Use of this interface is not recommended, as added methods to DriverServiceServer will 86 | // result in compilation errors. 87 | type UnsafeDriverServiceServer interface { 88 | mustEmbedUnimplementedDriverServiceServer() 89 | } 90 | 91 | func RegisterDriverServiceServer(s grpc.ServiceRegistrar, srv DriverServiceServer) { 92 | s.RegisterService(&DriverService_ServiceDesc, srv) 93 | } 94 | 95 | func _DriverService_FindNearbyDrivers_Handler(srv interface{}, stream grpc.ServerStream) error { 96 | return srv.(DriverServiceServer).FindNearbyDrivers(&driverServiceFindNearbyDriversServer{stream}) 97 | } 98 | 99 | type DriverService_FindNearbyDriversServer interface { 100 | Send(*StreamDriversResponse) error 101 | Recv() (*FindNearbyDriversRequest, error) 102 | grpc.ServerStream 103 | } 104 | 105 | type driverServiceFindNearbyDriversServer struct { 106 | grpc.ServerStream 107 | } 108 | 109 | func (x *driverServiceFindNearbyDriversServer) Send(m *StreamDriversResponse) error { 110 | return x.ServerStream.SendMsg(m) 111 | } 112 | 113 | func (x *driverServiceFindNearbyDriversServer) Recv() (*FindNearbyDriversRequest, error) { 114 | m := new(FindNearbyDriversRequest) 115 | if err := x.ServerStream.RecvMsg(m); err != nil { 116 | return nil, err 117 | } 118 | return m, nil 119 | } 120 | 121 | // DriverService_ServiceDesc is the grpc.ServiceDesc for DriverService service. 122 | // It's only intended for direct use with grpc.RegisterService, 123 | // and not to be introspected or modified (even as a copy) 124 | var DriverService_ServiceDesc = grpc.ServiceDesc{ 125 | ServiceName: "driver.DriverService", 126 | HandlerType: (*DriverServiceServer)(nil), 127 | Methods: []grpc.MethodDesc{}, 128 | Streams: []grpc.StreamDesc{ 129 | { 130 | StreamName: "FindNearbyDrivers", 131 | Handler: _DriverService_FindNearbyDrivers_Handler, 132 | ServerStreams: true, 133 | ClientStreams: true, 134 | }, 135 | }, 136 | Metadata: "driver.proto", 137 | } 138 | -------------------------------------------------------------------------------- /shared/proto/rider/rider.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.28.1 4 | // protoc v4.25.1 5 | // source: rider.proto 6 | 7 | package rider 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 | reflect "reflect" 13 | sync "sync" 14 | ) 15 | 16 | const ( 17 | // Verify that this generated code is sufficiently up-to-date. 18 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 19 | // Verify that runtime/protoimpl is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 21 | ) 22 | 23 | type RiderRequest struct { 24 | state protoimpl.MessageState 25 | sizeCache protoimpl.SizeCache 26 | unknownFields protoimpl.UnknownFields 27 | 28 | Latitude float64 `protobuf:"fixed64,1,opt,name=latitude,proto3" json:"latitude,omitempty"` 29 | Longitude float64 `protobuf:"fixed64,2,opt,name=longitude,proto3" json:"longitude,omitempty"` 30 | } 31 | 32 | func (x *RiderRequest) Reset() { 33 | *x = RiderRequest{} 34 | if protoimpl.UnsafeEnabled { 35 | mi := &file_rider_proto_msgTypes[0] 36 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 37 | ms.StoreMessageInfo(mi) 38 | } 39 | } 40 | 41 | func (x *RiderRequest) String() string { 42 | return protoimpl.X.MessageStringOf(x) 43 | } 44 | 45 | func (*RiderRequest) ProtoMessage() {} 46 | 47 | func (x *RiderRequest) ProtoReflect() protoreflect.Message { 48 | mi := &file_rider_proto_msgTypes[0] 49 | if protoimpl.UnsafeEnabled && x != nil { 50 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 51 | if ms.LoadMessageInfo() == nil { 52 | ms.StoreMessageInfo(mi) 53 | } 54 | return ms 55 | } 56 | return mi.MessageOf(x) 57 | } 58 | 59 | // Deprecated: Use RiderRequest.ProtoReflect.Descriptor instead. 60 | func (*RiderRequest) Descriptor() ([]byte, []int) { 61 | return file_rider_proto_rawDescGZIP(), []int{0} 62 | } 63 | 64 | func (x *RiderRequest) GetLatitude() float64 { 65 | if x != nil { 66 | return x.Latitude 67 | } 68 | return 0 69 | } 70 | 71 | func (x *RiderRequest) GetLongitude() float64 { 72 | if x != nil { 73 | return x.Longitude 74 | } 75 | return 0 76 | } 77 | 78 | type RiderResponse struct { 79 | state protoimpl.MessageState 80 | sizeCache protoimpl.SizeCache 81 | unknownFields protoimpl.UnknownFields 82 | 83 | RiderIds []string `protobuf:"bytes,1,rep,name=rider_ids,json=riderIds,proto3" json:"rider_ids,omitempty"` 84 | } 85 | 86 | func (x *RiderResponse) Reset() { 87 | *x = RiderResponse{} 88 | if protoimpl.UnsafeEnabled { 89 | mi := &file_rider_proto_msgTypes[1] 90 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 91 | ms.StoreMessageInfo(mi) 92 | } 93 | } 94 | 95 | func (x *RiderResponse) String() string { 96 | return protoimpl.X.MessageStringOf(x) 97 | } 98 | 99 | func (*RiderResponse) ProtoMessage() {} 100 | 101 | func (x *RiderResponse) ProtoReflect() protoreflect.Message { 102 | mi := &file_rider_proto_msgTypes[1] 103 | if protoimpl.UnsafeEnabled && x != nil { 104 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 105 | if ms.LoadMessageInfo() == nil { 106 | ms.StoreMessageInfo(mi) 107 | } 108 | return ms 109 | } 110 | return mi.MessageOf(x) 111 | } 112 | 113 | // Deprecated: Use RiderResponse.ProtoReflect.Descriptor instead. 114 | func (*RiderResponse) Descriptor() ([]byte, []int) { 115 | return file_rider_proto_rawDescGZIP(), []int{1} 116 | } 117 | 118 | func (x *RiderResponse) GetRiderIds() []string { 119 | if x != nil { 120 | return x.RiderIds 121 | } 122 | return nil 123 | } 124 | 125 | var File_rider_proto protoreflect.FileDescriptor 126 | 127 | var file_rider_proto_rawDesc = []byte{ 128 | 0x0a, 0x0b, 0x72, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x72, 129 | 0x69, 0x64, 0x65, 0x72, 0x22, 0x48, 0x0a, 0x0c, 0x52, 0x69, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 130 | 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 131 | 0x18, 0x01, 0x20, 0x01, 0x28, 0x01, 0x52, 0x08, 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 132 | 0x12, 0x1c, 0x0a, 0x09, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x02, 0x20, 133 | 0x01, 0x28, 0x01, 0x52, 0x09, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x22, 0x2c, 134 | 0x0a, 0x0d, 0x52, 0x69, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 135 | 0x1b, 0x0a, 0x09, 0x72, 0x69, 0x64, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 136 | 0x28, 0x09, 0x52, 0x08, 0x72, 0x69, 0x64, 0x65, 0x72, 0x49, 0x64, 0x73, 0x32, 0x4c, 0x0a, 0x0c, 137 | 0x52, 0x69, 0x64, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x3c, 0x0a, 0x0f, 138 | 0x47, 0x65, 0x74, 0x4e, 0x65, 0x61, 0x72, 0x62, 0x79, 0x52, 0x69, 0x64, 0x65, 0x72, 0x73, 0x12, 139 | 0x13, 0x2e, 0x72, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x52, 0x69, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 140 | 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x72, 0x69, 0x64, 0x65, 0x72, 0x2e, 0x52, 0x69, 0x64, 141 | 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x1a, 0x5a, 0x18, 0x73, 0x68, 142 | 0x61, 0x72, 0x65, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x72, 0x69, 0x64, 0x65, 0x72, 143 | 0x3b, 0x72, 0x69, 0x64, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 144 | } 145 | 146 | var ( 147 | file_rider_proto_rawDescOnce sync.Once 148 | file_rider_proto_rawDescData = file_rider_proto_rawDesc 149 | ) 150 | 151 | func file_rider_proto_rawDescGZIP() []byte { 152 | file_rider_proto_rawDescOnce.Do(func() { 153 | file_rider_proto_rawDescData = protoimpl.X.CompressGZIP(file_rider_proto_rawDescData) 154 | }) 155 | return file_rider_proto_rawDescData 156 | } 157 | 158 | var file_rider_proto_msgTypes = make([]protoimpl.MessageInfo, 2) 159 | var file_rider_proto_goTypes = []interface{}{ 160 | (*RiderRequest)(nil), // 0: rider.RiderRequest 161 | (*RiderResponse)(nil), // 1: rider.RiderResponse 162 | } 163 | var file_rider_proto_depIdxs = []int32{ 164 | 0, // 0: rider.RiderService.GetNearbyRiders:input_type -> rider.RiderRequest 165 | 1, // 1: rider.RiderService.GetNearbyRiders:output_type -> rider.RiderResponse 166 | 1, // [1:2] is the sub-list for method output_type 167 | 0, // [0:1] is the sub-list for method input_type 168 | 0, // [0:0] is the sub-list for extension type_name 169 | 0, // [0:0] is the sub-list for extension extendee 170 | 0, // [0:0] is the sub-list for field type_name 171 | } 172 | 173 | func init() { file_rider_proto_init() } 174 | func file_rider_proto_init() { 175 | if File_rider_proto != nil { 176 | return 177 | } 178 | if !protoimpl.UnsafeEnabled { 179 | file_rider_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 180 | switch v := v.(*RiderRequest); i { 181 | case 0: 182 | return &v.state 183 | case 1: 184 | return &v.sizeCache 185 | case 2: 186 | return &v.unknownFields 187 | default: 188 | return nil 189 | } 190 | } 191 | file_rider_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 192 | switch v := v.(*RiderResponse); i { 193 | case 0: 194 | return &v.state 195 | case 1: 196 | return &v.sizeCache 197 | case 2: 198 | return &v.unknownFields 199 | default: 200 | return nil 201 | } 202 | } 203 | } 204 | type x struct{} 205 | out := protoimpl.TypeBuilder{ 206 | File: protoimpl.DescBuilder{ 207 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 208 | RawDescriptor: file_rider_proto_rawDesc, 209 | NumEnums: 0, 210 | NumMessages: 2, 211 | NumExtensions: 0, 212 | NumServices: 1, 213 | }, 214 | GoTypes: file_rider_proto_goTypes, 215 | DependencyIndexes: file_rider_proto_depIdxs, 216 | MessageInfos: file_rider_proto_msgTypes, 217 | }.Build() 218 | File_rider_proto = out.File 219 | file_rider_proto_rawDesc = nil 220 | file_rider_proto_goTypes = nil 221 | file_rider_proto_depIdxs = nil 222 | } 223 | -------------------------------------------------------------------------------- /shared/proto/rider/rider_grpc.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-grpc. DO NOT EDIT. 2 | // versions: 3 | // - protoc-gen-go-grpc v1.2.0 4 | // - protoc v4.25.1 5 | // source: rider.proto 6 | 7 | package rider 8 | 9 | import ( 10 | context "context" 11 | grpc "google.golang.org/grpc" 12 | codes "google.golang.org/grpc/codes" 13 | status "google.golang.org/grpc/status" 14 | ) 15 | 16 | // This is a compile-time assertion to ensure that this generated file 17 | // is compatible with the grpc package it is being compiled against. 18 | // Requires gRPC-Go v1.32.0 or later. 19 | const _ = grpc.SupportPackageIsVersion7 20 | 21 | // RiderServiceClient is the client API for RiderService service. 22 | // 23 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 24 | type RiderServiceClient interface { 25 | GetNearbyRiders(ctx context.Context, in *RiderRequest, opts ...grpc.CallOption) (*RiderResponse, error) 26 | } 27 | 28 | type riderServiceClient struct { 29 | cc grpc.ClientConnInterface 30 | } 31 | 32 | func NewRiderServiceClient(cc grpc.ClientConnInterface) RiderServiceClient { 33 | return &riderServiceClient{cc} 34 | } 35 | 36 | func (c *riderServiceClient) GetNearbyRiders(ctx context.Context, in *RiderRequest, opts ...grpc.CallOption) (*RiderResponse, error) { 37 | out := new(RiderResponse) 38 | err := c.cc.Invoke(ctx, "/rider.RiderService/GetNearbyRiders", in, out, opts...) 39 | if err != nil { 40 | return nil, err 41 | } 42 | return out, nil 43 | } 44 | 45 | // RiderServiceServer is the server API for RiderService service. 46 | // All implementations must embed UnimplementedRiderServiceServer 47 | // for forward compatibility 48 | type RiderServiceServer interface { 49 | GetNearbyRiders(context.Context, *RiderRequest) (*RiderResponse, error) 50 | mustEmbedUnimplementedRiderServiceServer() 51 | } 52 | 53 | // UnimplementedRiderServiceServer must be embedded to have forward compatible implementations. 54 | type UnimplementedRiderServiceServer struct { 55 | } 56 | 57 | func (UnimplementedRiderServiceServer) GetNearbyRiders(context.Context, *RiderRequest) (*RiderResponse, error) { 58 | return nil, status.Errorf(codes.Unimplemented, "method GetNearbyRiders not implemented") 59 | } 60 | func (UnimplementedRiderServiceServer) mustEmbedUnimplementedRiderServiceServer() {} 61 | 62 | // UnsafeRiderServiceServer may be embedded to opt out of forward compatibility for this service. 63 | // Use of this interface is not recommended, as added methods to RiderServiceServer will 64 | // result in compilation errors. 65 | type UnsafeRiderServiceServer interface { 66 | mustEmbedUnimplementedRiderServiceServer() 67 | } 68 | 69 | func RegisterRiderServiceServer(s grpc.ServiceRegistrar, srv RiderServiceServer) { 70 | s.RegisterService(&RiderService_ServiceDesc, srv) 71 | } 72 | 73 | func _RiderService_GetNearbyRiders_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 74 | in := new(RiderRequest) 75 | if err := dec(in); err != nil { 76 | return nil, err 77 | } 78 | if interceptor == nil { 79 | return srv.(RiderServiceServer).GetNearbyRiders(ctx, in) 80 | } 81 | info := &grpc.UnaryServerInfo{ 82 | Server: srv, 83 | FullMethod: "/rider.RiderService/GetNearbyRiders", 84 | } 85 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 86 | return srv.(RiderServiceServer).GetNearbyRiders(ctx, req.(*RiderRequest)) 87 | } 88 | return interceptor(ctx, in, info, handler) 89 | } 90 | 91 | // RiderService_ServiceDesc is the grpc.ServiceDesc for RiderService service. 92 | // It's only intended for direct use with grpc.RegisterService, 93 | // and not to be introspected or modified (even as a copy) 94 | var RiderService_ServiceDesc = grpc.ServiceDesc{ 95 | ServiceName: "rider.RiderService", 96 | HandlerType: (*RiderServiceServer)(nil), 97 | Methods: []grpc.MethodDesc{ 98 | { 99 | MethodName: "GetNearbyRiders", 100 | Handler: _RiderService_GetNearbyRiders_Handler, 101 | }, 102 | }, 103 | Streams: []grpc.StreamDesc{}, 104 | Metadata: "rider.proto", 105 | } 106 | -------------------------------------------------------------------------------- /shared/proto/trip/trip.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.28.1 4 | // protoc v4.25.1 5 | // source: trip.proto 6 | 7 | package trip 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 | reflect "reflect" 13 | sync "sync" 14 | ) 15 | 16 | const ( 17 | // Verify that this generated code is sufficiently up-to-date. 18 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 19 | // Verify that runtime/protoimpl is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 21 | ) 22 | 23 | type CreateTripRequest struct { 24 | state protoimpl.MessageState 25 | sizeCache protoimpl.SizeCache 26 | unknownFields protoimpl.UnknownFields 27 | 28 | StartLocation *Coordinate `protobuf:"bytes,1,opt,name=start_location,json=startLocation,proto3" json:"start_location,omitempty"` 29 | EndLocation *Coordinate `protobuf:"bytes,2,opt,name=end_location,json=endLocation,proto3" json:"end_location,omitempty"` 30 | } 31 | 32 | func (x *CreateTripRequest) Reset() { 33 | *x = CreateTripRequest{} 34 | if protoimpl.UnsafeEnabled { 35 | mi := &file_trip_proto_msgTypes[0] 36 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 37 | ms.StoreMessageInfo(mi) 38 | } 39 | } 40 | 41 | func (x *CreateTripRequest) String() string { 42 | return protoimpl.X.MessageStringOf(x) 43 | } 44 | 45 | func (*CreateTripRequest) ProtoMessage() {} 46 | 47 | func (x *CreateTripRequest) ProtoReflect() protoreflect.Message { 48 | mi := &file_trip_proto_msgTypes[0] 49 | if protoimpl.UnsafeEnabled && x != nil { 50 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 51 | if ms.LoadMessageInfo() == nil { 52 | ms.StoreMessageInfo(mi) 53 | } 54 | return ms 55 | } 56 | return mi.MessageOf(x) 57 | } 58 | 59 | // Deprecated: Use CreateTripRequest.ProtoReflect.Descriptor instead. 60 | func (*CreateTripRequest) Descriptor() ([]byte, []int) { 61 | return file_trip_proto_rawDescGZIP(), []int{0} 62 | } 63 | 64 | func (x *CreateTripRequest) GetStartLocation() *Coordinate { 65 | if x != nil { 66 | return x.StartLocation 67 | } 68 | return nil 69 | } 70 | 71 | func (x *CreateTripRequest) GetEndLocation() *Coordinate { 72 | if x != nil { 73 | return x.EndLocation 74 | } 75 | return nil 76 | } 77 | 78 | type Coordinate struct { 79 | state protoimpl.MessageState 80 | sizeCache protoimpl.SizeCache 81 | unknownFields protoimpl.UnknownFields 82 | 83 | Latitude float32 `protobuf:"fixed32,1,opt,name=latitude,proto3" json:"latitude,omitempty"` 84 | Longitude float32 `protobuf:"fixed32,2,opt,name=longitude,proto3" json:"longitude,omitempty"` 85 | } 86 | 87 | func (x *Coordinate) Reset() { 88 | *x = Coordinate{} 89 | if protoimpl.UnsafeEnabled { 90 | mi := &file_trip_proto_msgTypes[1] 91 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 92 | ms.StoreMessageInfo(mi) 93 | } 94 | } 95 | 96 | func (x *Coordinate) String() string { 97 | return protoimpl.X.MessageStringOf(x) 98 | } 99 | 100 | func (*Coordinate) ProtoMessage() {} 101 | 102 | func (x *Coordinate) ProtoReflect() protoreflect.Message { 103 | mi := &file_trip_proto_msgTypes[1] 104 | if protoimpl.UnsafeEnabled && x != nil { 105 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 106 | if ms.LoadMessageInfo() == nil { 107 | ms.StoreMessageInfo(mi) 108 | } 109 | return ms 110 | } 111 | return mi.MessageOf(x) 112 | } 113 | 114 | // Deprecated: Use Coordinate.ProtoReflect.Descriptor instead. 115 | func (*Coordinate) Descriptor() ([]byte, []int) { 116 | return file_trip_proto_rawDescGZIP(), []int{1} 117 | } 118 | 119 | func (x *Coordinate) GetLatitude() float32 { 120 | if x != nil { 121 | return x.Latitude 122 | } 123 | return 0 124 | } 125 | 126 | func (x *Coordinate) GetLongitude() float32 { 127 | if x != nil { 128 | return x.Longitude 129 | } 130 | return 0 131 | } 132 | 133 | type Geometry struct { 134 | state protoimpl.MessageState 135 | sizeCache protoimpl.SizeCache 136 | unknownFields protoimpl.UnknownFields 137 | 138 | Coordinates []*Coordinate `protobuf:"bytes,1,rep,name=coordinates,proto3" json:"coordinates,omitempty"` 139 | } 140 | 141 | func (x *Geometry) Reset() { 142 | *x = Geometry{} 143 | if protoimpl.UnsafeEnabled { 144 | mi := &file_trip_proto_msgTypes[2] 145 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 146 | ms.StoreMessageInfo(mi) 147 | } 148 | } 149 | 150 | func (x *Geometry) String() string { 151 | return protoimpl.X.MessageStringOf(x) 152 | } 153 | 154 | func (*Geometry) ProtoMessage() {} 155 | 156 | func (x *Geometry) ProtoReflect() protoreflect.Message { 157 | mi := &file_trip_proto_msgTypes[2] 158 | if protoimpl.UnsafeEnabled && x != nil { 159 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 160 | if ms.LoadMessageInfo() == nil { 161 | ms.StoreMessageInfo(mi) 162 | } 163 | return ms 164 | } 165 | return mi.MessageOf(x) 166 | } 167 | 168 | // Deprecated: Use Geometry.ProtoReflect.Descriptor instead. 169 | func (*Geometry) Descriptor() ([]byte, []int) { 170 | return file_trip_proto_rawDescGZIP(), []int{2} 171 | } 172 | 173 | func (x *Geometry) GetCoordinates() []*Coordinate { 174 | if x != nil { 175 | return x.Coordinates 176 | } 177 | return nil 178 | } 179 | 180 | type Route struct { 181 | state protoimpl.MessageState 182 | sizeCache protoimpl.SizeCache 183 | unknownFields protoimpl.UnknownFields 184 | 185 | Geometry []*Geometry `protobuf:"bytes,1,rep,name=geometry,proto3" json:"geometry,omitempty"` 186 | Distance float32 `protobuf:"fixed32,2,opt,name=distance,proto3" json:"distance,omitempty"` 187 | Duration float32 `protobuf:"fixed32,3,opt,name=duration,proto3" json:"duration,omitempty"` 188 | } 189 | 190 | func (x *Route) Reset() { 191 | *x = Route{} 192 | if protoimpl.UnsafeEnabled { 193 | mi := &file_trip_proto_msgTypes[3] 194 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 195 | ms.StoreMessageInfo(mi) 196 | } 197 | } 198 | 199 | func (x *Route) String() string { 200 | return protoimpl.X.MessageStringOf(x) 201 | } 202 | 203 | func (*Route) ProtoMessage() {} 204 | 205 | func (x *Route) ProtoReflect() protoreflect.Message { 206 | mi := &file_trip_proto_msgTypes[3] 207 | if protoimpl.UnsafeEnabled && x != nil { 208 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 209 | if ms.LoadMessageInfo() == nil { 210 | ms.StoreMessageInfo(mi) 211 | } 212 | return ms 213 | } 214 | return mi.MessageOf(x) 215 | } 216 | 217 | // Deprecated: Use Route.ProtoReflect.Descriptor instead. 218 | func (*Route) Descriptor() ([]byte, []int) { 219 | return file_trip_proto_rawDescGZIP(), []int{3} 220 | } 221 | 222 | func (x *Route) GetGeometry() []*Geometry { 223 | if x != nil { 224 | return x.Geometry 225 | } 226 | return nil 227 | } 228 | 229 | func (x *Route) GetDistance() float32 { 230 | if x != nil { 231 | return x.Distance 232 | } 233 | return 0 234 | } 235 | 236 | func (x *Route) GetDuration() float32 { 237 | if x != nil { 238 | return x.Duration 239 | } 240 | return 0 241 | } 242 | 243 | type CreateTripResponse struct { 244 | state protoimpl.MessageState 245 | sizeCache protoimpl.SizeCache 246 | unknownFields protoimpl.UnknownFields 247 | 248 | TripId string `protobuf:"bytes,1,opt,name=trip_id,json=tripId,proto3" json:"trip_id,omitempty"` 249 | Route *Route `protobuf:"bytes,2,opt,name=route,proto3" json:"route,omitempty"` 250 | } 251 | 252 | func (x *CreateTripResponse) Reset() { 253 | *x = CreateTripResponse{} 254 | if protoimpl.UnsafeEnabled { 255 | mi := &file_trip_proto_msgTypes[4] 256 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 257 | ms.StoreMessageInfo(mi) 258 | } 259 | } 260 | 261 | func (x *CreateTripResponse) String() string { 262 | return protoimpl.X.MessageStringOf(x) 263 | } 264 | 265 | func (*CreateTripResponse) ProtoMessage() {} 266 | 267 | func (x *CreateTripResponse) ProtoReflect() protoreflect.Message { 268 | mi := &file_trip_proto_msgTypes[4] 269 | if protoimpl.UnsafeEnabled && x != nil { 270 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 271 | if ms.LoadMessageInfo() == nil { 272 | ms.StoreMessageInfo(mi) 273 | } 274 | return ms 275 | } 276 | return mi.MessageOf(x) 277 | } 278 | 279 | // Deprecated: Use CreateTripResponse.ProtoReflect.Descriptor instead. 280 | func (*CreateTripResponse) Descriptor() ([]byte, []int) { 281 | return file_trip_proto_rawDescGZIP(), []int{4} 282 | } 283 | 284 | func (x *CreateTripResponse) GetTripId() string { 285 | if x != nil { 286 | return x.TripId 287 | } 288 | return "" 289 | } 290 | 291 | func (x *CreateTripResponse) GetRoute() *Route { 292 | if x != nil { 293 | return x.Route 294 | } 295 | return nil 296 | } 297 | 298 | var File_trip_proto protoreflect.FileDescriptor 299 | 300 | var file_trip_proto_rawDesc = []byte{ 301 | 0x0a, 0x0a, 0x74, 0x72, 0x69, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x04, 0x74, 0x72, 302 | 0x69, 0x70, 0x22, 0x81, 0x01, 0x0a, 0x11, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x72, 0x69, 303 | 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x37, 0x0a, 0x0e, 0x73, 0x74, 0x61, 0x72, 304 | 0x74, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 305 | 0x32, 0x10, 0x2e, 0x74, 0x72, 0x69, 0x70, 0x2e, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 306 | 0x74, 0x65, 0x52, 0x0d, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 307 | 0x6e, 0x12, 0x33, 0x0a, 0x0c, 0x65, 0x6e, 0x64, 0x5f, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 308 | 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x74, 0x72, 0x69, 0x70, 0x2e, 0x43, 309 | 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x52, 0x0b, 0x65, 0x6e, 0x64, 0x4c, 0x6f, 310 | 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x46, 0x0a, 0x0a, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 311 | 0x6e, 0x61, 0x74, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 312 | 0x18, 0x01, 0x20, 0x01, 0x28, 0x02, 0x52, 0x08, 0x6c, 0x61, 0x74, 0x69, 0x74, 0x75, 0x64, 0x65, 313 | 0x12, 0x1c, 0x0a, 0x09, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x18, 0x02, 0x20, 314 | 0x01, 0x28, 0x02, 0x52, 0x09, 0x6c, 0x6f, 0x6e, 0x67, 0x69, 0x74, 0x75, 0x64, 0x65, 0x22, 0x3e, 315 | 0x0a, 0x08, 0x47, 0x65, 0x6f, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x12, 0x32, 0x0a, 0x0b, 0x63, 0x6f, 316 | 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 317 | 0x10, 0x2e, 0x74, 0x72, 0x69, 0x70, 0x2e, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 318 | 0x65, 0x52, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x22, 0x6b, 319 | 0x0a, 0x05, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x12, 0x2a, 0x0a, 0x08, 0x67, 0x65, 0x6f, 0x6d, 0x65, 320 | 0x74, 0x72, 0x79, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x74, 0x72, 0x69, 0x70, 321 | 0x2e, 0x47, 0x65, 0x6f, 0x6d, 0x65, 0x74, 0x72, 0x79, 0x52, 0x08, 0x67, 0x65, 0x6f, 0x6d, 0x65, 322 | 0x74, 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x69, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x18, 323 | 0x02, 0x20, 0x01, 0x28, 0x02, 0x52, 0x08, 0x64, 0x69, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x12, 324 | 0x1a, 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 325 | 0x02, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x50, 0x0a, 0x12, 0x43, 326 | 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x72, 0x69, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 327 | 0x65, 0x12, 0x17, 0x0a, 0x07, 0x74, 0x72, 0x69, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 328 | 0x28, 0x09, 0x52, 0x06, 0x74, 0x72, 0x69, 0x70, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x05, 0x72, 0x6f, 329 | 0x75, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x74, 0x72, 0x69, 0x70, 330 | 0x2e, 0x52, 0x6f, 0x75, 0x74, 0x65, 0x52, 0x05, 0x72, 0x6f, 0x75, 0x74, 0x65, 0x32, 0x4e, 0x0a, 331 | 0x0b, 0x54, 0x72, 0x69, 0x70, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x3f, 0x0a, 0x0a, 332 | 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x72, 0x69, 0x70, 0x12, 0x17, 0x2e, 0x74, 0x72, 0x69, 333 | 0x70, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x54, 0x72, 0x69, 0x70, 0x52, 0x65, 0x71, 0x75, 334 | 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x74, 0x72, 0x69, 0x70, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 335 | 0x65, 0x54, 0x72, 0x69, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x18, 0x5a, 336 | 0x16, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x74, 0x72, 337 | 0x69, 0x70, 0x3b, 0x74, 0x72, 0x69, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 338 | } 339 | 340 | var ( 341 | file_trip_proto_rawDescOnce sync.Once 342 | file_trip_proto_rawDescData = file_trip_proto_rawDesc 343 | ) 344 | 345 | func file_trip_proto_rawDescGZIP() []byte { 346 | file_trip_proto_rawDescOnce.Do(func() { 347 | file_trip_proto_rawDescData = protoimpl.X.CompressGZIP(file_trip_proto_rawDescData) 348 | }) 349 | return file_trip_proto_rawDescData 350 | } 351 | 352 | var file_trip_proto_msgTypes = make([]protoimpl.MessageInfo, 5) 353 | var file_trip_proto_goTypes = []interface{}{ 354 | (*CreateTripRequest)(nil), // 0: trip.CreateTripRequest 355 | (*Coordinate)(nil), // 1: trip.Coordinate 356 | (*Geometry)(nil), // 2: trip.Geometry 357 | (*Route)(nil), // 3: trip.Route 358 | (*CreateTripResponse)(nil), // 4: trip.CreateTripResponse 359 | } 360 | var file_trip_proto_depIdxs = []int32{ 361 | 1, // 0: trip.CreateTripRequest.start_location:type_name -> trip.Coordinate 362 | 1, // 1: trip.CreateTripRequest.end_location:type_name -> trip.Coordinate 363 | 1, // 2: trip.Geometry.coordinates:type_name -> trip.Coordinate 364 | 2, // 3: trip.Route.geometry:type_name -> trip.Geometry 365 | 3, // 4: trip.CreateTripResponse.route:type_name -> trip.Route 366 | 0, // 5: trip.TripService.CreateTrip:input_type -> trip.CreateTripRequest 367 | 4, // 6: trip.TripService.CreateTrip:output_type -> trip.CreateTripResponse 368 | 6, // [6:7] is the sub-list for method output_type 369 | 5, // [5:6] is the sub-list for method input_type 370 | 5, // [5:5] is the sub-list for extension type_name 371 | 5, // [5:5] is the sub-list for extension extendee 372 | 0, // [0:5] is the sub-list for field type_name 373 | } 374 | 375 | func init() { file_trip_proto_init() } 376 | func file_trip_proto_init() { 377 | if File_trip_proto != nil { 378 | return 379 | } 380 | if !protoimpl.UnsafeEnabled { 381 | file_trip_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 382 | switch v := v.(*CreateTripRequest); i { 383 | case 0: 384 | return &v.state 385 | case 1: 386 | return &v.sizeCache 387 | case 2: 388 | return &v.unknownFields 389 | default: 390 | return nil 391 | } 392 | } 393 | file_trip_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 394 | switch v := v.(*Coordinate); i { 395 | case 0: 396 | return &v.state 397 | case 1: 398 | return &v.sizeCache 399 | case 2: 400 | return &v.unknownFields 401 | default: 402 | return nil 403 | } 404 | } 405 | file_trip_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { 406 | switch v := v.(*Geometry); i { 407 | case 0: 408 | return &v.state 409 | case 1: 410 | return &v.sizeCache 411 | case 2: 412 | return &v.unknownFields 413 | default: 414 | return nil 415 | } 416 | } 417 | file_trip_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { 418 | switch v := v.(*Route); i { 419 | case 0: 420 | return &v.state 421 | case 1: 422 | return &v.sizeCache 423 | case 2: 424 | return &v.unknownFields 425 | default: 426 | return nil 427 | } 428 | } 429 | file_trip_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { 430 | switch v := v.(*CreateTripResponse); i { 431 | case 0: 432 | return &v.state 433 | case 1: 434 | return &v.sizeCache 435 | case 2: 436 | return &v.unknownFields 437 | default: 438 | return nil 439 | } 440 | } 441 | } 442 | type x struct{} 443 | out := protoimpl.TypeBuilder{ 444 | File: protoimpl.DescBuilder{ 445 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 446 | RawDescriptor: file_trip_proto_rawDesc, 447 | NumEnums: 0, 448 | NumMessages: 5, 449 | NumExtensions: 0, 450 | NumServices: 1, 451 | }, 452 | GoTypes: file_trip_proto_goTypes, 453 | DependencyIndexes: file_trip_proto_depIdxs, 454 | MessageInfos: file_trip_proto_msgTypes, 455 | }.Build() 456 | File_trip_proto = out.File 457 | file_trip_proto_rawDesc = nil 458 | file_trip_proto_goTypes = nil 459 | file_trip_proto_depIdxs = nil 460 | } 461 | -------------------------------------------------------------------------------- /shared/proto/trip/trip_grpc.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-grpc. DO NOT EDIT. 2 | // versions: 3 | // - protoc-gen-go-grpc v1.2.0 4 | // - protoc v4.25.1 5 | // source: trip.proto 6 | 7 | package trip 8 | 9 | import ( 10 | context "context" 11 | grpc "google.golang.org/grpc" 12 | codes "google.golang.org/grpc/codes" 13 | status "google.golang.org/grpc/status" 14 | ) 15 | 16 | // This is a compile-time assertion to ensure that this generated file 17 | // is compatible with the grpc package it is being compiled against. 18 | // Requires gRPC-Go v1.32.0 or later. 19 | const _ = grpc.SupportPackageIsVersion7 20 | 21 | // TripServiceClient is the client API for TripService service. 22 | // 23 | // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. 24 | type TripServiceClient interface { 25 | CreateTrip(ctx context.Context, in *CreateTripRequest, opts ...grpc.CallOption) (*CreateTripResponse, error) 26 | } 27 | 28 | type tripServiceClient struct { 29 | cc grpc.ClientConnInterface 30 | } 31 | 32 | func NewTripServiceClient(cc grpc.ClientConnInterface) TripServiceClient { 33 | return &tripServiceClient{cc} 34 | } 35 | 36 | func (c *tripServiceClient) CreateTrip(ctx context.Context, in *CreateTripRequest, opts ...grpc.CallOption) (*CreateTripResponse, error) { 37 | out := new(CreateTripResponse) 38 | err := c.cc.Invoke(ctx, "/trip.TripService/CreateTrip", in, out, opts...) 39 | if err != nil { 40 | return nil, err 41 | } 42 | return out, nil 43 | } 44 | 45 | // TripServiceServer is the server API for TripService service. 46 | // All implementations must embed UnimplementedTripServiceServer 47 | // for forward compatibility 48 | type TripServiceServer interface { 49 | CreateTrip(context.Context, *CreateTripRequest) (*CreateTripResponse, error) 50 | mustEmbedUnimplementedTripServiceServer() 51 | } 52 | 53 | // UnimplementedTripServiceServer must be embedded to have forward compatible implementations. 54 | type UnimplementedTripServiceServer struct { 55 | } 56 | 57 | func (UnimplementedTripServiceServer) CreateTrip(context.Context, *CreateTripRequest) (*CreateTripResponse, error) { 58 | return nil, status.Errorf(codes.Unimplemented, "method CreateTrip not implemented") 59 | } 60 | func (UnimplementedTripServiceServer) mustEmbedUnimplementedTripServiceServer() {} 61 | 62 | // UnsafeTripServiceServer may be embedded to opt out of forward compatibility for this service. 63 | // Use of this interface is not recommended, as added methods to TripServiceServer will 64 | // result in compilation errors. 65 | type UnsafeTripServiceServer interface { 66 | mustEmbedUnimplementedTripServiceServer() 67 | } 68 | 69 | func RegisterTripServiceServer(s grpc.ServiceRegistrar, srv TripServiceServer) { 70 | s.RegisterService(&TripService_ServiceDesc, srv) 71 | } 72 | 73 | func _TripService_CreateTrip_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 74 | in := new(CreateTripRequest) 75 | if err := dec(in); err != nil { 76 | return nil, err 77 | } 78 | if interceptor == nil { 79 | return srv.(TripServiceServer).CreateTrip(ctx, in) 80 | } 81 | info := &grpc.UnaryServerInfo{ 82 | Server: srv, 83 | FullMethod: "/trip.TripService/CreateTrip", 84 | } 85 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 86 | return srv.(TripServiceServer).CreateTrip(ctx, req.(*CreateTripRequest)) 87 | } 88 | return interceptor(ctx, in, info, handler) 89 | } 90 | 91 | // TripService_ServiceDesc is the grpc.ServiceDesc for TripService service. 92 | // It's only intended for direct use with grpc.RegisterService, 93 | // and not to be introspected or modified (even as a copy) 94 | var TripService_ServiceDesc = grpc.ServiceDesc{ 95 | ServiceName: "trip.TripService", 96 | HandlerType: (*TripServiceServer)(nil), 97 | Methods: []grpc.MethodDesc{ 98 | { 99 | MethodName: "CreateTrip", 100 | Handler: _TripService_CreateTrip_Handler, 101 | }, 102 | }, 103 | Streams: []grpc.StreamDesc{}, 104 | Metadata: "trip.proto", 105 | } 106 | -------------------------------------------------------------------------------- /shared/types/types.go: -------------------------------------------------------------------------------- 1 | package types 2 | 3 | type Location struct { 4 | Latitude float64 `json:"latitude"` 5 | Longitude float64 `json:"longitude"` 6 | } 7 | -------------------------------------------------------------------------------- /skaffold.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: skaffold/v4beta11 2 | kind: Config 3 | metadata: 4 | name: ride-sharing 5 | build: 6 | artifacts: 7 | - image: ride-sharing/api-gateway 8 | context: . 9 | docker: 10 | dockerfile: infra/development/docker/api-gateway.Dockerfile 11 | sync: 12 | infer: 13 | - "**/*.go" 14 | - image: ride-sharing/driver-service 15 | context: . 16 | docker: 17 | dockerfile: infra/development/docker/driver-service.Dockerfile 18 | sync: 19 | infer: 20 | - "**/*.go" 21 | tagPolicy: 22 | sha256: {} 23 | local: 24 | push: false 25 | useBuildkit: true 26 | manifests: 27 | rawYaml: 28 | - ./infra/development/k8s/api-gateway-deployment.yaml 29 | - ./infra/development/k8s/driver-service-deployment.yaml 30 | portForward: 31 | - resourceType: service 32 | resourceName: api-gateway 33 | port: 8081 34 | localPort: 8081 35 | - resourceType: service 36 | resourceName: driver-service 37 | port: 8082 38 | localPort: 8082 39 | profiles: 40 | - name: dev 41 | build: 42 | local: 43 | push: false 44 | useBuildkit: true 45 | deploy: 46 | kubectl: {} -------------------------------------------------------------------------------- /web/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.* 7 | .yarn/* 8 | !.yarn/patches 9 | !.yarn/plugins 10 | !.yarn/releases 11 | !.yarn/versions 12 | 13 | # testing 14 | /coverage 15 | 16 | # next.js 17 | /.next/ 18 | /out/ 19 | 20 | # production 21 | /build 22 | 23 | # misc 24 | .DS_Store 25 | *.pem 26 | 27 | # debug 28 | npm-debug.log* 29 | yarn-debug.log* 30 | yarn-error.log* 31 | .pnpm-debug.log* 32 | 33 | # env files (can opt-in for committing if needed) 34 | .env* 35 | 36 | # vercel 37 | .vercel 38 | 39 | # typescript 40 | *.tsbuildinfo 41 | next-env.d.ts 42 | -------------------------------------------------------------------------------- /web/.nvmrc: -------------------------------------------------------------------------------- 1 | v20.12.0 2 | -------------------------------------------------------------------------------- /web/README.md: -------------------------------------------------------------------------------- 1 | This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app). 2 | 3 | ## Getting Started 4 | 5 | First, run the development server: 6 | 7 | ```bash 8 | npm run dev 9 | # or 10 | yarn dev 11 | # or 12 | pnpm dev 13 | # or 14 | bun dev 15 | ``` 16 | 17 | Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. 18 | 19 | You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. 20 | 21 | This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel. 22 | 23 | ## Learn More 24 | 25 | To learn more about Next.js, take a look at the following resources: 26 | 27 | - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. 28 | - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. 29 | 30 | You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome! 31 | 32 | ## Deploy on Vercel 33 | 34 | The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. 35 | 36 | Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. 37 | -------------------------------------------------------------------------------- /web/components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://ui.shadcn.com/schema.json", 3 | "style": "new-york", 4 | "rsc": true, 5 | "tsx": true, 6 | "tailwind": { 7 | "config": "tailwind.config.ts", 8 | "css": "src/app/globals.css", 9 | "baseColor": "neutral", 10 | "cssVariables": true, 11 | "prefix": "" 12 | }, 13 | "aliases": { 14 | "components": "@/components", 15 | "utils": "@/lib/utils", 16 | "ui": "@/components/ui", 17 | "lib": "@/lib", 18 | "hooks": "@/hooks" 19 | }, 20 | "iconLibrary": "lucide" 21 | } -------------------------------------------------------------------------------- /web/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import { dirname } from "path"; 2 | import { fileURLToPath } from "url"; 3 | import { FlatCompat } from "@eslint/eslintrc"; 4 | 5 | const __filename = fileURLToPath(import.meta.url); 6 | const __dirname = dirname(__filename); 7 | 8 | const compat = new FlatCompat({ 9 | baseDirectory: __dirname, 10 | }); 11 | 12 | const eslintConfig = [ 13 | ...compat.extends("next/core-web-vitals", "next/typescript"), 14 | ]; 15 | 16 | export default eslintConfig; 17 | -------------------------------------------------------------------------------- /web/next.config.ts: -------------------------------------------------------------------------------- 1 | import type { NextConfig } from "next"; 2 | 3 | const nextConfig: NextConfig = { 4 | /* config options here */ 5 | }; 6 | 7 | export default nextConfig; 8 | -------------------------------------------------------------------------------- /web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev --turbopack", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "@radix-ui/react-avatar": "^1.1.2", 13 | "@radix-ui/react-scroll-area": "^1.2.2", 14 | "@radix-ui/react-slot": "^1.1.1", 15 | "class-variance-authority": "^0.7.1", 16 | "clsx": "^2.1.1", 17 | "latlon-geohash": "2.0.0", 18 | "leaflet": "1.9.4", 19 | "lucide-react": "^0.473.0", 20 | "next": "15.1.5", 21 | "react": "19.0.0", 22 | "react-dom": "19.0.0", 23 | "react-leaflet": "5.0.0", 24 | "tailwind-merge": "^2.6.0", 25 | "tailwindcss-animate": "^1.0.7" 26 | }, 27 | "devDependencies": { 28 | "@eslint/eslintrc": "3", 29 | "@types/latlon-geohash": "2.0.4", 30 | "@types/leaflet": "1.9.16", 31 | "@types/node": "20", 32 | "@types/react": "19", 33 | "@types/react-dom": "19", 34 | "eslint": "9", 35 | "eslint-config-next": "15.1.5", 36 | "postcss": "8", 37 | "tailwindcss": "3.4.1", 38 | "typescript": "5" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /web/postcss.config.mjs: -------------------------------------------------------------------------------- 1 | /** @type {import('postcss-load-config').Config} */ 2 | const config = { 3 | plugins: { 4 | tailwindcss: {}, 5 | }, 6 | }; 7 | 8 | export default config; 9 | -------------------------------------------------------------------------------- /web/public/file.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/public/globe.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/public/next.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/public/vercel.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/public/window.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /web/src/app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sikozonpc/k8s-go-microservices/432a6b01a7e10fc154cf0227730cf91365168c0e/web/src/app/favicon.ico -------------------------------------------------------------------------------- /web/src/app/globals.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | body { 6 | font-family: Arial, Helvetica, sans-serif; 7 | } 8 | 9 | @layer base { 10 | :root { 11 | --background: 0 0% 100%; 12 | --foreground: 0 0% 3.9%; 13 | --card: 0 0% 100%; 14 | --card-foreground: 0 0% 3.9%; 15 | --popover: 0 0% 100%; 16 | --popover-foreground: 0 0% 3.9%; 17 | --primary: 0 0% 9%; 18 | --primary-foreground: 0 0% 98%; 19 | --secondary: 0 0% 96.1%; 20 | --secondary-foreground: 0 0% 9%; 21 | --muted: 0 0% 96.1%; 22 | --muted-foreground: 0 0% 45.1%; 23 | --accent: 0 0% 96.1%; 24 | --accent-foreground: 0 0% 9%; 25 | --destructive: 0 84.2% 60.2%; 26 | --destructive-foreground: 0 0% 98%; 27 | --border: 0 0% 89.8%; 28 | --input: 0 0% 89.8%; 29 | --ring: 0 0% 3.9%; 30 | --chart-1: 12 76% 61%; 31 | --chart-2: 173 58% 39%; 32 | --chart-3: 197 37% 24%; 33 | --chart-4: 43 74% 66%; 34 | --chart-5: 27 87% 67%; 35 | --radius: 0.5rem; 36 | } 37 | .dark { 38 | --background: 0 0% 3.9%; 39 | --foreground: 0 0% 98%; 40 | --card: 0 0% 3.9%; 41 | --card-foreground: 0 0% 98%; 42 | --popover: 0 0% 3.9%; 43 | --popover-foreground: 0 0% 98%; 44 | --primary: 0 0% 98%; 45 | --primary-foreground: 0 0% 9%; 46 | --secondary: 0 0% 14.9%; 47 | --secondary-foreground: 0 0% 98%; 48 | --muted: 0 0% 14.9%; 49 | --muted-foreground: 0 0% 63.9%; 50 | --accent: 0 0% 14.9%; 51 | --accent-foreground: 0 0% 98%; 52 | --destructive: 0 62.8% 30.6%; 53 | --destructive-foreground: 0 0% 98%; 54 | --border: 0 0% 14.9%; 55 | --input: 0 0% 14.9%; 56 | --ring: 0 0% 83.1%; 57 | --chart-1: 220 70% 50%; 58 | --chart-2: 160 60% 45%; 59 | --chart-3: 30 80% 55%; 60 | --chart-4: 280 65% 60%; 61 | --chart-5: 340 75% 55%; 62 | } 63 | } 64 | 65 | @layer base { 66 | * { 67 | @apply border-border; 68 | } 69 | body { 70 | @apply bg-background text-foreground; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /web/src/app/layout.tsx: -------------------------------------------------------------------------------- 1 | import type { Metadata } from "next"; 2 | import { Geist, Geist_Mono } from "next/font/google"; 3 | import "./globals.css"; 4 | 5 | const geistSans = Geist({ 6 | variable: "--font-geist-sans", 7 | subsets: ["latin"], 8 | }); 9 | 10 | const geistMono = Geist_Mono({ 11 | variable: "--font-geist-mono", 12 | subsets: ["latin"], 13 | }); 14 | 15 | export const metadata: Metadata = { 16 | title: "Create Next App", 17 | description: "Generated by create next app", 18 | }; 19 | 20 | export default function RootLayout({ 21 | children, 22 | }: Readonly<{ 23 | children: React.ReactNode; 24 | }>) { 25 | return ( 26 | 27 | 30 | {children} 31 | 32 | 33 | ); 34 | } 35 | -------------------------------------------------------------------------------- /web/src/app/page.tsx: -------------------------------------------------------------------------------- 1 | import { NearbyDriversMap } from "../components/NearbyDriversMap"; 2 | 3 | export default function Home() { 4 | return ( 5 |
6 | 7 |
8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /web/src/assets/Car.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 12 | 20 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /web/src/components/DriversList.tsx: -------------------------------------------------------------------------------- 1 | import {useEffect, useState} from 'react' 2 | import {Button} from "@/components/ui/button" 3 | import {ScrollArea} from "@/components/ui/scroll-area" 4 | import {Card, CardContent, CardDescription, CardHeader, CardTitle} from "@/components/ui/card" 5 | import {Avatar, AvatarFallback, AvatarImage} from "@/components/ui/avatar" 6 | import {Car} from 'lucide-react' 7 | import {Driver} from '@/hooks/useNearbyDrivers' 8 | 9 | interface DriverListProps { 10 | drivers: Driver[] 11 | onSelectDriver: (driver: Driver) => void 12 | } 13 | 14 | export function DriverList({ drivers, onSelectDriver }: DriverListProps) { 15 | const [sortedDrivers, setSortedDrivers] = useState([]) 16 | 17 | useEffect(() => { 18 | const sorted = [...drivers].sort((a, b) => a.driver_id.localeCompare(b.driver_id)) 19 | setSortedDrivers(sorted) 20 | }, [drivers]) 21 | 22 | return ( 23 | 24 | 25 | Available Drivers 26 | Select a driver to request a ride 27 | 28 | 29 | 30 | {sortedDrivers.map((driver) => ( 31 |
32 | 33 | 34 | 35 | 36 |
37 |

{driver.driver_id}

38 |

Toyota Camry

39 |
40 | {[...Array(5)].map((_, i) => ( 41 | 51 | ))} 52 |

4.5

53 |
54 |
55 | 56 |
57 | ))} 58 |
59 |
60 |
61 | ) 62 | } 63 | -------------------------------------------------------------------------------- /web/src/components/MapClickHandler.ts: -------------------------------------------------------------------------------- 1 | import { useMapEvents } from 'react-leaflet' 2 | 3 | interface MapClickHandlerProps { 4 | onClick: (e: L.LeafletMouseEvent) => void; 5 | } 6 | 7 | export function MapClickHandler({ onClick }: MapClickHandlerProps) { 8 | useMapEvents({ 9 | click: onClick, 10 | }) 11 | return null 12 | } 13 | 14 | -------------------------------------------------------------------------------- /web/src/components/NearbyDriversMap.tsx: -------------------------------------------------------------------------------- 1 | 'use client'; 2 | 3 | import 'leaflet/dist/leaflet.css'; 4 | import { Driver, useNearbyDrivers } from '@/hooks/useNearbyDrivers'; 5 | import { MapContainer, Marker, Popup, Rectangle, TileLayer } from 'react-leaflet' 6 | import L from 'leaflet'; 7 | import { decodeGeoHash } from '@/utils/geohash'; 8 | import { useRef, useState } from 'react'; 9 | // Fix for default marker icon 10 | import icon from 'leaflet/dist/images/marker-icon.png' 11 | import iconShadow from 'leaflet/dist/images/marker-shadow.png' 12 | import { MapClickHandler } from './MapClickHandler'; 13 | import { DriverList } from './DriversList'; 14 | import { Button } from './ui/button'; 15 | import { RequestRideProps, RouteInfo } from "@/types"; 16 | import { RoutingControl } from "@/components/RoutingControl"; 17 | import { API_URL } from '../constants'; 18 | 19 | const DefaultIcon = L.icon({ 20 | iconUrl: icon.src, 21 | shadowUrl: iconShadow.src, 22 | iconSize: [25, 41], 23 | iconAnchor: [12, 41], 24 | }) 25 | 26 | L.Marker.prototype.options.icon = DefaultIcon 27 | 28 | 29 | export function NearbyDriversMap() { 30 | const [selectedDriver, setSelectedDriver] = useState(null) 31 | const [route, setRoute] = useState<[number, number][]>([]) 32 | const mapRef = useRef(null) 33 | 34 | const location = { 35 | latitude: 37.7749, 36 | longitude: -122.4194, 37 | }; 38 | 39 | const [destination, setDestination] = useState<[number, number] | null>(null) 40 | 41 | const handleMapClick = async (e: L.LeafletMouseEvent) => { 42 | setDestination([e.latlng.lat, e.latlng.lng]) 43 | 44 | await requestRide({ 45 | pickup: [location.latitude, location.longitude], 46 | destination: [e.latlng.lat, e.latlng.lng], 47 | }) 48 | } 49 | 50 | const { drivers, error } = useNearbyDrivers(location); 51 | 52 | const userMarker = new L.Icon({ 53 | iconUrl: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/ed/Map_pin_icon.svg/176px-Map_pin_icon.svg.png", 54 | iconSize: [40, 40], // Size of the marker 55 | iconAnchor: [20, 40], // Anchor point 56 | }); 57 | 58 | const driverMarker = new L.Icon({ 59 | iconUrl: "https://www.svgrepo.com/show/25407/car.svg", 60 | iconSize: [30, 30], 61 | iconAnchor: [15, 30], 62 | }); 63 | 64 | // Function to create grid bounds from geohash 65 | const getGeohashBounds = (geohash: string) => { 66 | const { latitude: [minLat, maxLat], longitude: [minLng, maxLng] } = decodeGeoHash(geohash); 67 | return [ 68 | [minLat, minLng], 69 | [maxLat, maxLng], 70 | ]; 71 | }; 72 | 73 | const requestRide = async (props: RequestRideProps): Promise => { 74 | const { pickup, destination } = props 75 | const payload = { 76 | pickup: { 77 | latitude: pickup[0], 78 | longitude: pickup[1], 79 | }, 80 | destination: { 81 | latitude: destination[0], 82 | longitude: destination[1], 83 | }, 84 | } 85 | 86 | const response = await fetch(`${API_URL}/trip`, { 87 | method: 'POST', 88 | body: JSON.stringify(payload), 89 | }) 90 | const data = await response.json() as RouteInfo 91 | const route = data.route 92 | const parsedRoute = route.geometry[0].coordinates 93 | .map((coord) => [coord.longitude, coord.latitude] as [number, number]) 94 | 95 | setRoute(parsedRoute) 96 | return data 97 | } 98 | 99 | if (error) { 100 | return
Error: {error}
; 101 | } 102 | 103 | return ( 104 | 110 | 114 | 115 | 116 | {/* Render geohash grid cells */} 117 | {drivers.map((driver) => ( 118 | 127 | Geohash: {driver.geohash} 128 | 129 | ))} 130 | 131 | {/* Render driver markers */} 132 | {drivers.map((driver) => ( 133 | 138 | 139 | Driver ID: {driver.driver_id} 140 |
141 | Geohash: {driver.geohash} 142 |
143 |
144 | ))} 145 | {destination && ( 146 | 147 | Destination 148 | 149 | )} 150 | {destination ? ( 151 | 152 | ) : ( 153 |
154 |

Click on the map to set a destination

155 |
156 | )} 157 | {selectedDriver && ( 158 |
159 | 162 |
163 | )} 164 | 167 | 168 |
169 | ) 170 | } -------------------------------------------------------------------------------- /web/src/components/RoutingControl.tsx: -------------------------------------------------------------------------------- 1 | import { Polyline } from "react-leaflet"; 2 | 3 | export function RoutingControl({ route }: { 4 | route: [number, number][] 5 | }) { 6 | if (!route) return null 7 | 8 | return 9 | } -------------------------------------------------------------------------------- /web/src/components/ui/avatar.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as AvatarPrimitive from "@radix-ui/react-avatar" 5 | 6 | import { cn } from "@/lib/utils" 7 | 8 | const Avatar = React.forwardRef< 9 | React.ElementRef, 10 | React.ComponentPropsWithoutRef 11 | >(({ className, ...props }, ref) => ( 12 | 20 | )) 21 | Avatar.displayName = AvatarPrimitive.Root.displayName 22 | 23 | const AvatarImage = React.forwardRef< 24 | React.ElementRef, 25 | React.ComponentPropsWithoutRef 26 | >(({ className, ...props }, ref) => ( 27 | 32 | )) 33 | AvatarImage.displayName = AvatarPrimitive.Image.displayName 34 | 35 | const AvatarFallback = React.forwardRef< 36 | React.ElementRef, 37 | React.ComponentPropsWithoutRef 38 | >(({ className, ...props }, ref) => ( 39 | 47 | )) 48 | AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName 49 | 50 | export { Avatar, AvatarImage, AvatarFallback } 51 | -------------------------------------------------------------------------------- /web/src/components/ui/button.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import { Slot } from "@radix-ui/react-slot" 3 | import { cva, type VariantProps } from "class-variance-authority" 4 | 5 | import { cn } from "@/lib/utils" 6 | 7 | const buttonVariants = cva( 8 | "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0", 9 | { 10 | variants: { 11 | variant: { 12 | default: 13 | "bg-primary text-primary-foreground shadow hover:bg-primary/90", 14 | destructive: 15 | "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90", 16 | outline: 17 | "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground", 18 | secondary: 19 | "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80", 20 | ghost: "hover:bg-accent hover:text-accent-foreground", 21 | link: "text-primary underline-offset-4 hover:underline", 22 | }, 23 | size: { 24 | default: "h-9 px-4 py-2", 25 | sm: "h-8 rounded-md px-3 text-xs", 26 | lg: "h-10 rounded-md px-8", 27 | icon: "h-9 w-9", 28 | }, 29 | }, 30 | defaultVariants: { 31 | variant: "default", 32 | size: "default", 33 | }, 34 | } 35 | ) 36 | 37 | export interface ButtonProps 38 | extends React.ButtonHTMLAttributes, 39 | VariantProps { 40 | asChild?: boolean 41 | } 42 | 43 | const Button = React.forwardRef( 44 | ({ className, variant, size, asChild = false, ...props }, ref) => { 45 | const Comp = asChild ? Slot : "button" 46 | return ( 47 | 52 | ) 53 | } 54 | ) 55 | Button.displayName = "Button" 56 | 57 | export { Button, buttonVariants } 58 | -------------------------------------------------------------------------------- /web/src/components/ui/card.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | 3 | import { cn } from "@/lib/utils" 4 | 5 | const Card = React.forwardRef< 6 | HTMLDivElement, 7 | React.HTMLAttributes 8 | >(({ className, ...props }, ref) => ( 9 |
17 | )) 18 | Card.displayName = "Card" 19 | 20 | const CardHeader = React.forwardRef< 21 | HTMLDivElement, 22 | React.HTMLAttributes 23 | >(({ className, ...props }, ref) => ( 24 |
29 | )) 30 | CardHeader.displayName = "CardHeader" 31 | 32 | const CardTitle = React.forwardRef< 33 | HTMLDivElement, 34 | React.HTMLAttributes 35 | >(({ className, ...props }, ref) => ( 36 |
41 | )) 42 | CardTitle.displayName = "CardTitle" 43 | 44 | const CardDescription = React.forwardRef< 45 | HTMLDivElement, 46 | React.HTMLAttributes 47 | >(({ className, ...props }, ref) => ( 48 |
53 | )) 54 | CardDescription.displayName = "CardDescription" 55 | 56 | const CardContent = React.forwardRef< 57 | HTMLDivElement, 58 | React.HTMLAttributes 59 | >(({ className, ...props }, ref) => ( 60 |
61 | )) 62 | CardContent.displayName = "CardContent" 63 | 64 | const CardFooter = React.forwardRef< 65 | HTMLDivElement, 66 | React.HTMLAttributes 67 | >(({ className, ...props }, ref) => ( 68 |
73 | )) 74 | CardFooter.displayName = "CardFooter" 75 | 76 | export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent } 77 | -------------------------------------------------------------------------------- /web/src/components/ui/scroll-area.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area" 5 | 6 | import { cn } from "@/lib/utils" 7 | 8 | const ScrollArea = React.forwardRef< 9 | React.ElementRef, 10 | React.ComponentPropsWithoutRef 11 | >(({ className, children, ...props }, ref) => ( 12 | 17 | 18 | {children} 19 | 20 | 21 | 22 | 23 | )) 24 | ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName 25 | 26 | const ScrollBar = React.forwardRef< 27 | React.ElementRef, 28 | React.ComponentPropsWithoutRef 29 | >(({ className, orientation = "vertical", ...props }, ref) => ( 30 | 43 | 44 | 45 | )) 46 | ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName 47 | 48 | export { ScrollArea, ScrollBar } 49 | -------------------------------------------------------------------------------- /web/src/constants.ts: -------------------------------------------------------------------------------- 1 | export const API_URL = process.env.API_URL ?? 'http://localhost:8081'; 2 | export const WEBSOCKET_URL = process.env.WEBSOCKET_URL ?? 'ws://localhost:8081/ws'; 3 | -------------------------------------------------------------------------------- /web/src/hooks/useNearbyDrivers.ts: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from 'react'; 2 | import { WEBSOCKET_URL } from "@/constants"; 3 | 4 | interface Location { 5 | latitude: number; 6 | longitude: number; 7 | } 8 | 9 | export interface Driver { 10 | driver_id: string; 11 | location: Location; 12 | geohash: string; 13 | } 14 | 15 | export function useNearbyDrivers(location: Location) { 16 | const [drivers, setDrivers] = useState([]); 17 | const [error, setError] = useState(null); 18 | 19 | useEffect(() => { 20 | const ws = new WebSocket(`${WEBSOCKET_URL}/drivers`); 21 | 22 | ws.onopen = () => { 23 | // Send initial location 24 | ws.send(JSON.stringify(location)); 25 | }; 26 | 27 | ws.onmessage = (event) => { 28 | const drivers = JSON.parse(event.data) as Driver[]; 29 | 30 | setDrivers(drivers); 31 | }; 32 | 33 | ws.onclose = () => { 34 | console.log('WebSocket closed'); 35 | }; 36 | 37 | ws.onerror = (event) => { 38 | setError('WebSocket error occurred'); 39 | console.error('WebSocket error:', event); 40 | }; 41 | 42 | return () => { 43 | console.log('Closing WebSocket'); 44 | ws.close(); 45 | }; 46 | // eslint-disable-next-line react-hooks/exhaustive-deps 47 | }, []); 48 | 49 | return { drivers, error }; 50 | } -------------------------------------------------------------------------------- /web/src/lib/utils.ts: -------------------------------------------------------------------------------- 1 | import { clsx, type ClassValue } from "clsx" 2 | import { twMerge } from "tailwind-merge" 3 | 4 | export function cn(...inputs: ClassValue[]) { 5 | return twMerge(clsx(inputs)) 6 | } 7 | -------------------------------------------------------------------------------- /web/src/types.ts: -------------------------------------------------------------------------------- 1 | export interface RequestRideProps { 2 | pickup: [number, number], 3 | destination: [number, number], 4 | } 5 | 6 | export interface Location { 7 | latitude: number, 8 | longitude: number, 9 | } 10 | 11 | export interface RouteInfo { 12 | route: { 13 | geometry: { 14 | coordinates: Location[] 15 | }[] 16 | } 17 | } -------------------------------------------------------------------------------- /web/src/utils/geohash.ts: -------------------------------------------------------------------------------- 1 | import Geohash from 'latlon-geohash'; 2 | 3 | export function decodeGeoHash(geohash: string) { 4 | const bounds = Geohash.bounds(geohash); 5 | return { 6 | latitude: [bounds.sw.lat, bounds.ne.lat], 7 | longitude: [bounds.sw.lon, bounds.ne.lon], 8 | }; 9 | } -------------------------------------------------------------------------------- /web/tailwind.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from "tailwindcss"; 2 | 3 | export default { 4 | darkMode: ["class"], 5 | content: [ 6 | "./src/pages/**/*.{js,ts,jsx,tsx,mdx}", 7 | "./src/components/**/*.{js,ts,jsx,tsx,mdx}", 8 | "./src/app/**/*.{js,ts,jsx,tsx,mdx}", 9 | ], 10 | theme: { 11 | extend: { 12 | colors: { 13 | background: 'hsl(var(--background))', 14 | foreground: 'hsl(var(--foreground))', 15 | card: { 16 | DEFAULT: 'hsl(var(--card))', 17 | foreground: 'hsl(var(--card-foreground))' 18 | }, 19 | popover: { 20 | DEFAULT: 'hsl(var(--popover))', 21 | foreground: 'hsl(var(--popover-foreground))' 22 | }, 23 | primary: { 24 | DEFAULT: 'hsl(var(--primary))', 25 | foreground: 'hsl(var(--primary-foreground))' 26 | }, 27 | secondary: { 28 | DEFAULT: 'hsl(var(--secondary))', 29 | foreground: 'hsl(var(--secondary-foreground))' 30 | }, 31 | muted: { 32 | DEFAULT: 'hsl(var(--muted))', 33 | foreground: 'hsl(var(--muted-foreground))' 34 | }, 35 | accent: { 36 | DEFAULT: 'hsl(var(--accent))', 37 | foreground: 'hsl(var(--accent-foreground))' 38 | }, 39 | destructive: { 40 | DEFAULT: 'hsl(var(--destructive))', 41 | foreground: 'hsl(var(--destructive-foreground))' 42 | }, 43 | border: 'hsl(var(--border))', 44 | input: 'hsl(var(--input))', 45 | ring: 'hsl(var(--ring))', 46 | chart: { 47 | '1': 'hsl(var(--chart-1))', 48 | '2': 'hsl(var(--chart-2))', 49 | '3': 'hsl(var(--chart-3))', 50 | '4': 'hsl(var(--chart-4))', 51 | '5': 'hsl(var(--chart-5))' 52 | } 53 | }, 54 | borderRadius: { 55 | lg: 'var(--radius)', 56 | md: 'calc(var(--radius) - 2px)', 57 | sm: 'calc(var(--radius) - 4px)' 58 | } 59 | } 60 | }, 61 | plugins: [require("tailwindcss-animate")], 62 | } satisfies Config; 63 | -------------------------------------------------------------------------------- /web/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2017", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "noEmit": true, 9 | "esModuleInterop": true, 10 | "module": "esnext", 11 | "moduleResolution": "bundler", 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "jsx": "preserve", 15 | "incremental": true, 16 | "plugins": [ 17 | { 18 | "name": "next" 19 | } 20 | ], 21 | "paths": { 22 | "@/*": ["./src/*"] 23 | } 24 | }, 25 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], 26 | "exclude": ["node_modules"] 27 | } 28 | --------------------------------------------------------------------------------