I am batman
This commit is contained in:
18
.gitignore
vendored
Normal file
18
.gitignore
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
.env
|
||||||
|
|
||||||
|
build/*
|
||||||
|
.github/copilot-instructions.md
|
||||||
|
.git
|
||||||
|
|
||||||
|
/k8s/*.yaml
|
||||||
|
.env.example
|
||||||
|
|
||||||
|
*.json
|
||||||
|
go.mod
|
||||||
|
go.sum
|
||||||
|
|
||||||
|
Tiltfile
|
||||||
|
scripts/*.sh
|
||||||
|
|
||||||
|
/bin/
|
||||||
|
**/bin/
|
||||||
235
Makefile
Normal file
235
Makefile
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
# Go Microservices Makefile
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
PROTO_DIR := proto
|
||||||
|
SERVICES := auth-service user-service post-service
|
||||||
|
API_GATEWAY := api-gateway
|
||||||
|
DOCKER_COMPOSE := docker-compose.yml
|
||||||
|
|
||||||
|
# Go variables
|
||||||
|
GOOS := $(shell go env GOOS)
|
||||||
|
GOARCH := $(shell go env GOARCH)
|
||||||
|
GO_VERSION := 1.21
|
||||||
|
|
||||||
|
# Proto compilation
|
||||||
|
.PHONY: proto
|
||||||
|
proto:
|
||||||
|
@echo "Generating protobuf files..."
|
||||||
|
@for service in $(SERVICES); do \
|
||||||
|
echo "Generating proto for $$service..."; \
|
||||||
|
mkdir -p services/$$service/proto; \
|
||||||
|
protoc --go_out=services/$$service/proto --go_opt=paths=source_relative \
|
||||||
|
--go-grpc_out=services/$$service/proto --go-grpc_opt=paths=source_relative \
|
||||||
|
--proto_path=$(PROTO_DIR) \
|
||||||
|
$(PROTO_DIR)/*.proto $(PROTO_DIR)/common/*.proto; \
|
||||||
|
done
|
||||||
|
@echo "Protobuf generation completed!"
|
||||||
|
|
||||||
|
# Build individual services
|
||||||
|
.PHONY: build-auth
|
||||||
|
build-auth:
|
||||||
|
@echo "Building auth-service..."
|
||||||
|
cd services/auth-service && go build -o bin/auth-service ./cmd/main.go
|
||||||
|
|
||||||
|
.PHONY: build-user
|
||||||
|
build-user:
|
||||||
|
@echo "Building user-service..."
|
||||||
|
cd services/user-service && go build -o bin/user-service ./cmd/main.go
|
||||||
|
|
||||||
|
.PHONY: build-post
|
||||||
|
build-post:
|
||||||
|
@echo "Building post-service..."
|
||||||
|
cd services/post-service && go build -o bin/post-service ./cmd/main.go
|
||||||
|
|
||||||
|
.PHONY: build-gateway
|
||||||
|
build-gateway:
|
||||||
|
@echo "Building api-gateway..."
|
||||||
|
cd api-gateway && go build -o bin/api-gateway ./cmd/main.go
|
||||||
|
|
||||||
|
# Build all services
|
||||||
|
.PHONY: build
|
||||||
|
build: build-auth build-user build-post build-gateway
|
||||||
|
@echo "All services built successfully!"
|
||||||
|
|
||||||
|
# Run individual services locally
|
||||||
|
.PHONY: run-auth
|
||||||
|
run-auth:
|
||||||
|
cd services/auth-service && go run ./cmd/main.go
|
||||||
|
|
||||||
|
.PHONY: run-user
|
||||||
|
run-user:
|
||||||
|
cd services/user-service && go run ./cmd/main.go
|
||||||
|
|
||||||
|
.PHONY: run-post
|
||||||
|
run-post:
|
||||||
|
cd services/post-service && go run ./cmd/main.go
|
||||||
|
|
||||||
|
.PHONY: run-gateway
|
||||||
|
run-gateway:
|
||||||
|
cd api-gateway && go run ./cmd/main.go
|
||||||
|
|
||||||
|
# Docker operations
|
||||||
|
.PHONY: docker-build
|
||||||
|
docker-build:
|
||||||
|
@echo "Building Docker images..."
|
||||||
|
docker-compose build
|
||||||
|
|
||||||
|
.PHONY: docker-up
|
||||||
|
docker-up:
|
||||||
|
@echo "Starting services with Docker Compose..."
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
.PHONY: docker-down
|
||||||
|
docker-down:
|
||||||
|
@echo "Stopping services..."
|
||||||
|
docker-compose down
|
||||||
|
|
||||||
|
.PHONY: docker-logs
|
||||||
|
docker-logs:
|
||||||
|
docker-compose logs -f
|
||||||
|
|
||||||
|
.PHONY: docker-clean
|
||||||
|
docker-clean:
|
||||||
|
@echo "Cleaning up Docker resources..."
|
||||||
|
docker-compose down -v
|
||||||
|
docker system prune -f
|
||||||
|
|
||||||
|
# Development operations
|
||||||
|
.PHONY: deps
|
||||||
|
deps:
|
||||||
|
@echo "Installing dependencies for all services..."
|
||||||
|
@for service in $(SERVICES); do \
|
||||||
|
echo "Installing deps for $$service..."; \
|
||||||
|
cd services/$$service && go mod tidy && go mod download; \
|
||||||
|
cd ../..; \
|
||||||
|
done
|
||||||
|
cd $(API_GATEWAY) && go mod tidy && go mod download
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test:
|
||||||
|
@echo "Running tests for all services..."
|
||||||
|
@for service in $(SERVICES); do \
|
||||||
|
echo "Testing $$service..."; \
|
||||||
|
cd services/$$service && go test ./... -v; \
|
||||||
|
cd ../..; \
|
||||||
|
done
|
||||||
|
cd $(API_GATEWAY) && go test ./... -v
|
||||||
|
|
||||||
|
.PHONY: test-coverage
|
||||||
|
test-coverage:
|
||||||
|
@echo "Running tests with coverage..."
|
||||||
|
@for service in $(SERVICES); do \
|
||||||
|
echo "Testing $$service with coverage..."; \
|
||||||
|
cd services/$$service && go test ./... -coverprofile=coverage.out -v; \
|
||||||
|
go tool cover -html=coverage.out -o coverage.html; \
|
||||||
|
cd ../..; \
|
||||||
|
done
|
||||||
|
|
||||||
|
.PHONY: lint
|
||||||
|
lint:
|
||||||
|
@echo "Running linter for all services..."
|
||||||
|
@for service in $(SERVICES); do \
|
||||||
|
echo "Linting $$service..."; \
|
||||||
|
cd services/$$service && golangci-lint run; \
|
||||||
|
cd ../..; \
|
||||||
|
done
|
||||||
|
cd $(API_GATEWAY) && golangci-lint run
|
||||||
|
|
||||||
|
.PHONY: format
|
||||||
|
format:
|
||||||
|
@echo "Formatting code..."
|
||||||
|
@for service in $(SERVICES); do \
|
||||||
|
echo "Formatting $$service..."; \
|
||||||
|
cd services/$$service && gofmt -w .; \
|
||||||
|
cd ../..; \
|
||||||
|
done
|
||||||
|
cd $(API_GATEWAY) && gofmt -w .
|
||||||
|
|
||||||
|
# Database operations
|
||||||
|
.PHONY: db-up
|
||||||
|
db-up:
|
||||||
|
@echo "Starting database..."
|
||||||
|
docker-compose up -d postgres redis
|
||||||
|
|
||||||
|
.PHONY: db-down
|
||||||
|
db-down:
|
||||||
|
@echo "Stopping database..."
|
||||||
|
docker-compose stop postgres redis
|
||||||
|
|
||||||
|
.PHONY: db-migrate
|
||||||
|
db-migrate:
|
||||||
|
@echo "Running database migrations..."
|
||||||
|
# Add migration commands here when implemented
|
||||||
|
|
||||||
|
# Monitoring
|
||||||
|
.PHONY: monitoring-up
|
||||||
|
monitoring-up:
|
||||||
|
@echo "Starting monitoring stack..."
|
||||||
|
docker-compose up -d prometheus grafana jaeger
|
||||||
|
|
||||||
|
.PHONY: monitoring-down
|
||||||
|
monitoring-down:
|
||||||
|
@echo "Stopping monitoring stack..."
|
||||||
|
docker-compose stop prometheus grafana jaeger
|
||||||
|
|
||||||
|
# Development workflow
|
||||||
|
.PHONY: dev-setup
|
||||||
|
dev-setup: deps proto
|
||||||
|
@echo "Development environment setup complete!"
|
||||||
|
|
||||||
|
.PHONY: dev-start
|
||||||
|
dev-start: db-up
|
||||||
|
@echo "Starting development environment..."
|
||||||
|
@echo "Database is running. Start your services manually or use make run-<service>"
|
||||||
|
|
||||||
|
.PHONY: dev-stop
|
||||||
|
dev-stop: docker-down
|
||||||
|
@echo "Development environment stopped."
|
||||||
|
|
||||||
|
# Production deployment
|
||||||
|
.PHONY: deploy
|
||||||
|
deploy: proto build docker-build docker-up
|
||||||
|
@echo "Deployment completed!"
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
.PHONY: clean
|
||||||
|
clean:
|
||||||
|
@echo "Cleaning up build artifacts..."
|
||||||
|
@for service in $(SERVICES); do \
|
||||||
|
rm -rf services/$$service/bin; \
|
||||||
|
rm -rf services/$$service/coverage.*; \
|
||||||
|
done
|
||||||
|
rm -rf $(API_GATEWAY)/bin
|
||||||
|
rm -rf $(API_GATEWAY)/coverage.*
|
||||||
|
|
||||||
|
# Help
|
||||||
|
.PHONY: help
|
||||||
|
help:
|
||||||
|
@echo "Available commands:"
|
||||||
|
@echo " proto - Generate protobuf files"
|
||||||
|
@echo " build - Build all services"
|
||||||
|
@echo " build-<service> - Build specific service (auth, user, post, gateway)"
|
||||||
|
@echo " run-<service> - Run specific service locally"
|
||||||
|
@echo " docker-build - Build Docker images"
|
||||||
|
@echo " docker-up - Start all services with Docker"
|
||||||
|
@echo " docker-down - Stop all services"
|
||||||
|
@echo " docker-logs - View service logs"
|
||||||
|
@echo " docker-clean - Clean up Docker resources"
|
||||||
|
@echo " deps - Install dependencies"
|
||||||
|
@echo " test - Run tests"
|
||||||
|
@echo " test-coverage - Run tests with coverage"
|
||||||
|
@echo " lint - Run linter"
|
||||||
|
@echo " format - Format code"
|
||||||
|
@echo " db-up - Start database services"
|
||||||
|
@echo " db-down - Stop database services"
|
||||||
|
@echo " monitoring-up - Start monitoring stack"
|
||||||
|
@echo " monitoring-down - Stop monitoring stack"
|
||||||
|
@echo " dev-setup - Setup development environment"
|
||||||
|
@echo " dev-start - Start development environment"
|
||||||
|
@echo " dev-stop - Stop development environment"
|
||||||
|
@echo " deploy - Deploy to production"
|
||||||
|
@echo " clean - Clean up build artifacts"
|
||||||
|
@echo " help - Show this help message"
|
||||||
|
|
||||||
|
# Default target
|
||||||
|
.DEFAULT_GOAL := help
|
||||||
169
README.md
Normal file
169
README.md
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
# Go Microservices
|
||||||
|
|
||||||
|
Go-based microservices backend with a REST API gateway, gRPC service-to-service communication, JWT auth, and local observability tooling.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
This repo contains:
|
||||||
|
|
||||||
|
- `api-gateway`: public HTTP API (`/api/v1/*`)
|
||||||
|
- `services/auth-service`: authentication and user auth workflows
|
||||||
|
- `services/user-service`: user domain service
|
||||||
|
- `services/post-service`: post domain service
|
||||||
|
- `proto`: shared protobuf contracts used by gateway and services
|
||||||
|
|
||||||
|
Core infra for local development includes PostgreSQL, Redis, Docker Compose, Prometheus, Grafana, and Jaeger.
|
||||||
|
|
||||||
|
## Project Layout
|
||||||
|
|
||||||
|
```text
|
||||||
|
go-microservices/
|
||||||
|
├── api-gateway/
|
||||||
|
├── services/
|
||||||
|
│ ├── auth-service/
|
||||||
|
│ ├── user-service/
|
||||||
|
│ └── post-service/
|
||||||
|
├── proto/
|
||||||
|
├── scripts/
|
||||||
|
├── docker-compose.yml
|
||||||
|
├── Makefile
|
||||||
|
└── README.md
|
||||||
|
```
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
Prerequisites:
|
||||||
|
|
||||||
|
- Go 1.21+
|
||||||
|
- Docker + Docker Compose
|
||||||
|
- `protoc`
|
||||||
|
- `make`
|
||||||
|
|
||||||
|
Local startup:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make dev-setup
|
||||||
|
make db-up
|
||||||
|
make proto
|
||||||
|
|
||||||
|
# run each in separate terminals
|
||||||
|
make run-auth
|
||||||
|
make run-user
|
||||||
|
make run-post
|
||||||
|
make run-gateway
|
||||||
|
```
|
||||||
|
|
||||||
|
Docker-first startup:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make docker-build
|
||||||
|
make docker-up
|
||||||
|
make docker-logs
|
||||||
|
```
|
||||||
|
|
||||||
|
## API Summary
|
||||||
|
|
||||||
|
Base URL: `http://localhost:8080/api/v1`
|
||||||
|
|
||||||
|
Endpoints:
|
||||||
|
|
||||||
|
- `GET /` health check
|
||||||
|
- `POST /signup` register
|
||||||
|
- `POST /signin` login (returns `access_token`, `refresh_token`)
|
||||||
|
- `POST /validate` validate token
|
||||||
|
- `POST /userinfo` protected endpoint (`Authorization: Bearer <token>`)
|
||||||
|
- `POST /test` create test entry
|
||||||
|
- `GET /tests` list test entries
|
||||||
|
|
||||||
|
Typical auth flow:
|
||||||
|
|
||||||
|
1. `POST /signup`
|
||||||
|
2. `POST /signin`
|
||||||
|
3. Use `access_token` as `Bearer` token on protected routes
|
||||||
|
4. (Optional) `POST /validate`
|
||||||
|
|
||||||
|
## Service Ports
|
||||||
|
|
||||||
|
- API Gateway: `8080`
|
||||||
|
- Auth gRPC: `50051`
|
||||||
|
- User gRPC: `50052`
|
||||||
|
- Post gRPC: `50053`
|
||||||
|
- PostgreSQL: `5432`
|
||||||
|
- Redis: `6379`
|
||||||
|
- Grafana: `3000`
|
||||||
|
- Prometheus: `9090`
|
||||||
|
- Jaeger: `16686`
|
||||||
|
|
||||||
|
## Testing Options
|
||||||
|
|
||||||
|
### 1) Postman
|
||||||
|
|
||||||
|
- Import `postman_collection.json`
|
||||||
|
- Import `postman_environment.json`
|
||||||
|
- Set `base_url=http://localhost:8080`
|
||||||
|
- Run requests in this order: health -> signup -> signin -> validate -> userinfo -> test -> tests
|
||||||
|
|
||||||
|
### 2) Posting (terminal TUI)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./scripts/posting-start.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Environment file used by Posting:
|
||||||
|
|
||||||
|
- `~/.config/posting/collections/go_microservices/Go Microservices API.env`
|
||||||
|
|
||||||
|
### 3) curl
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Health
|
||||||
|
curl -X GET http://localhost:8080/api/v1/
|
||||||
|
|
||||||
|
# Sign in
|
||||||
|
curl -X POST http://localhost:8080/api/v1/signin \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d '{"email":"john@example.com","password":"SecurePassword123!"}'
|
||||||
|
```
|
||||||
|
|
||||||
|
## Common Make Targets
|
||||||
|
|
||||||
|
- `make build` build all services
|
||||||
|
- `make test` run tests
|
||||||
|
- `make lint` run linting
|
||||||
|
- `make format` format code
|
||||||
|
- `make proto` regenerate protobuf output
|
||||||
|
- `make db-up` / `make db-down` start/stop DB infra
|
||||||
|
- `make docker-up` / `make docker-down` start/stop container stack
|
||||||
|
|
||||||
|
## Protobuf Regeneration
|
||||||
|
|
||||||
|
When proto contracts change, regenerate bindings:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
make proto
|
||||||
|
```
|
||||||
|
|
||||||
|
Direct command example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
protoc --go_out=. --go-grpc_out=. proto/auth.proto
|
||||||
|
```
|
||||||
|
|
||||||
|
Generated files are expected in service proto directories such as:
|
||||||
|
|
||||||
|
- `services/auth-service/proto/`
|
||||||
|
- `services/user-service/proto/`
|
||||||
|
- `services/post-service/proto/`
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
- Port conflicts: stop local stack (`make docker-down`) and restart required services
|
||||||
|
- DB errors: run `make db-down && make db-up`
|
||||||
|
- Token errors (`401`): sign in again and ensure `Bearer` prefix is present
|
||||||
|
- 404/connection errors: verify `base_url` and gateway process on `:8080`
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
- API returns JSON for most responses; errors typically use `{ "error": "..." }`
|
||||||
|
- JWT can be passed via `Authorization` header (or cookie where supported)
|
||||||
|
- Keep docs and contract examples in sync when changing endpoint behavior
|
||||||
32
api-gateway/Dockerfile
Normal file
32
api-gateway/Dockerfile
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
FROM golang:1.24-alpine AS build
|
||||||
|
RUN apk add --no-cache git ca-certificates protobuf-dev
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# install Go protoc plugins
|
||||||
|
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && \
|
||||||
|
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
|
||||||
|
|
||||||
|
COPY api-gateway ./api-gateway
|
||||||
|
COPY services/auth-service ./services/auth-service
|
||||||
|
COPY proto ./proto
|
||||||
|
|
||||||
|
# generate proto files
|
||||||
|
RUN mkdir -p proto/auth proto/user proto/post && \
|
||||||
|
export PATH=/go/bin:$PATH && \
|
||||||
|
protoc --go_out=proto --go_opt=paths=source_relative \
|
||||||
|
--go-grpc_out=proto --go-grpc_opt=paths=source_relative \
|
||||||
|
--proto_path=proto \
|
||||||
|
proto/auth.proto proto/user.proto proto/post.proto && \
|
||||||
|
ls -la proto/auth/ proto/user/ proto/post/
|
||||||
|
|
||||||
|
RUN go build -o /app/main ./api-gateway/cmd
|
||||||
|
|
||||||
|
FROM alpine:3.20
|
||||||
|
RUN apk add --no-cache ca-certificates
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=build /app/main /app/main
|
||||||
|
EXPOSE 8080
|
||||||
|
ENTRYPOINT ["/app/main"]
|
||||||
42
api-gateway/cmd/main.go
Normal file
42
api-gateway/cmd/main.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go-microservices/api-gateway/internal/handlers"
|
||||||
|
"go-microservices/api-gateway/internal/routes"
|
||||||
|
|
||||||
|
"go-microservices/api-gateway/internal/clients"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("Starting API Gateway...")
|
||||||
|
app := fiber.New()
|
||||||
|
|
||||||
|
// Connect to AuthService gRPC
|
||||||
|
authServiceAddr := os.Getenv("AUTH_SERVICE_GRPC")
|
||||||
|
|
||||||
|
conn, err := grpc.Dial(authServiceAddr, grpc.WithInsecure())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to connect to AuthService: %v", err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
authClient := clients.NewAuthClient(conn)
|
||||||
|
authHandler := handlers.NewAuthHandler(authClient)
|
||||||
|
|
||||||
|
routes.RegisterAuthRoutes(app, authHandler, authClient)
|
||||||
|
|
||||||
|
port := os.Getenv("PORT")
|
||||||
|
if port == "" {
|
||||||
|
port = "8080"
|
||||||
|
}
|
||||||
|
log.Printf("API Gateway listening on :%s", port)
|
||||||
|
|
||||||
|
log.Fatal(app.Listen(":" + port))
|
||||||
|
}
|
||||||
0
api-gateway/config/config.yml
Normal file
0
api-gateway/config/config.yml
Normal file
36
api-gateway/config/env.go
Normal file
36
api-gateway/config/env.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
// import (
|
||||||
|
// "os"
|
||||||
|
// "strconv"
|
||||||
|
// )
|
||||||
|
|
||||||
|
// type Env struct {
|
||||||
|
// Port string
|
||||||
|
// AuthServiceURL string
|
||||||
|
// UserServiceURL string
|
||||||
|
// PostServiceURL string
|
||||||
|
// CommentServiceURL string
|
||||||
|
// LikeServiceURL string
|
||||||
|
// FollowServiceURL string
|
||||||
|
// NotificationURL string
|
||||||
|
// RateLimitPerMinute int
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func LoadEnv() *Env {
|
||||||
|
// rateLimit, err := strconv.Atoi(os.Getenv("RATE_LIMIT_PER_MINUTE"))
|
||||||
|
// if err != nil {
|
||||||
|
// rateLimit = 60 // default value
|
||||||
|
// }
|
||||||
|
// return &Env{
|
||||||
|
// Port: getEnv("PORT", "8080"),
|
||||||
|
// AuthServiceURL: getEnv("AUTH_SERVICE_URL", "http://localhost:8001"),
|
||||||
|
// UserServiceURL: getEnv("USER_SERVICE_URL", "http://localhost:8002"),
|
||||||
|
// PostServiceURL: getEnv("POST_SERVICE_URL", "http://localhost:8003"),
|
||||||
|
// CommentServiceURL: getEnv("COMMENT_SERVICE_URL", "http://localhost:8004"),
|
||||||
|
// LikeServiceURL: getEnv("LIKE_SERVICE_URL", "http://localhost:8005"),
|
||||||
|
// FollowServiceURL: getEnv("FOLLOW_SERVICE_URL", "http://localhost:8006"),
|
||||||
|
// NotificationURL: getEnv("NOTIFICATION_SERVICE_URL", "http://localhost:8007"),
|
||||||
|
// RateLimitPerMinute: rateLimit,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
118
api-gateway/internal/clients/clients.go
Normal file
118
api-gateway/internal/clients/clients.go
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
package clients
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
pb "go-microservices/proto/auth"
|
||||||
|
pbPost "go-microservices/proto/post"
|
||||||
|
pbUser "go-microservices/proto/user"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AuthClient struct {
|
||||||
|
client pb.AuthServiceClient
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAuthClient(conn *grpc.ClientConn) *AuthClient {
|
||||||
|
return &AuthClient{
|
||||||
|
client: pb.NewAuthServiceClient(conn),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AuthClient) SignUp(ctx context.Context, req *pb.SignUpRequest) (*pb.SignUpResponse, error) {
|
||||||
|
return a.client.SignUp(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AuthClient) SignIn(ctx context.Context, req *pb.SignInRequest) (*pb.SignInResponse, error) {
|
||||||
|
return a.client.SignIn(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AuthClient) ValidateToken(ctx context.Context, req *pb.ValidateTokenRequest) (*pb.ValidateTokenResponse, error) {
|
||||||
|
return a.client.ValidateToken(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AuthClient) GetUserInfo(ctx context.Context, req *pb.GetUserInfoRequest) (*pb.GetUserInfoResponse, error) {
|
||||||
|
return a.client.GetUserInfo(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AuthClient) CreateTest(ctx context.Context, req *pb.CreateTestRequest) (*pb.CreateTestResponse, error) {
|
||||||
|
return a.client.CreateTest(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AuthClient) ListTests(ctx context.Context, req *pb.ListTestsRequest) (*pb.ListTestsResponse, error) {
|
||||||
|
return a.client.ListTests(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AuthClient) GetTest(ctx context.Context, req *pb.GetTestRequest) (*pb.GetTestResponse, error) {
|
||||||
|
return a.client.GetTest(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AuthClient) UpdateTest(ctx context.Context, req *pb.UpdateTestRequest) (*pb.UpdateTestResponse, error) {
|
||||||
|
return a.client.UpdateTest(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AuthClient) DeleteTest(ctx context.Context, req *pb.DeleteTestRequest) (*pb.DeleteTestResponse, error) {
|
||||||
|
return a.client.DeleteTest(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserClient struct {
|
||||||
|
client pbUser.UserServiceClient
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUserClient(conn *grpc.ClientConn) *UserClient {
|
||||||
|
return &UserClient{
|
||||||
|
client: pbUser.NewUserServiceClient(conn),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *UserClient) CreateUser(ctx context.Context, req *pbUser.CreateUserRequest) (*pbUser.CreateUserResponse, error) {
|
||||||
|
return u.client.CreateUser(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *UserClient) GetUser(ctx context.Context, req *pbUser.GetUserRequest) (*pbUser.GetUserResponse, error) {
|
||||||
|
return u.client.GetUser(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *UserClient) UpdateUser(ctx context.Context, req *pbUser.UpdateUserRequest) (*pbUser.UpdateUserResponse, error) {
|
||||||
|
return u.client.UpdateUser(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *UserClient) DeleteUser(ctx context.Context, req *pbUser.DeleteUserRequest) error {
|
||||||
|
_, err := u.client.DeleteUser(ctx, req)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *UserClient) ListUsers(ctx context.Context, req *pbUser.ListUsersRequest) (*pbUser.ListUsersResponse, error) {
|
||||||
|
return u.client.ListUsers(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
type PostClient struct {
|
||||||
|
client pbPost.PostServiceClient
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPostClient(conn *grpc.ClientConn) *PostClient {
|
||||||
|
return &PostClient{
|
||||||
|
client: pbPost.NewPostServiceClient(conn),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PostClient) CreatePost(ctx context.Context, req *pbPost.CreatePostRequest) (*pbPost.CreatePostResponse, error) {
|
||||||
|
return p.client.CreatePost(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PostClient) GetPost(ctx context.Context, req *pbPost.GetPostRequest) (*pbPost.GetPostResponse, error) {
|
||||||
|
return p.client.GetPost(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PostClient) UpdatePost(ctx context.Context, req *pbPost.UpdatePostRequest) (*pbPost.UpdatePostResponse, error) {
|
||||||
|
return p.client.UpdatePost(ctx, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PostClient) DeletePost(ctx context.Context, req *pbPost.DeletePostRequest) error {
|
||||||
|
_, err := p.client.DeletePost(ctx, req)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PostClient) ListPosts(ctx context.Context, req *pbPost.ListPostsRequest) (*pbPost.ListPostsResponse, error) {
|
||||||
|
return p.client.ListPosts(ctx, req)
|
||||||
|
}
|
||||||
167
api-gateway/internal/handlers/handlers.go
Normal file
167
api-gateway/internal/handlers/handlers.go
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
package handlers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"go-microservices/api-gateway/internal/clients"
|
||||||
|
pb "go-microservices/proto/auth"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AuthHandler struct {
|
||||||
|
AuthClient *clients.AuthClient
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAuthHandler(authClient *clients.AuthClient) *AuthHandler {
|
||||||
|
return &AuthHandler{AuthClient: authClient}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *AuthHandler) SignUp(c *fiber.Ctx) error {
|
||||||
|
var req pb.SignUpRequest
|
||||||
|
if err := c.BodyParser(&req); err != nil {
|
||||||
|
return c.Status(http.StatusBadRequest).JSON(fiber.Map{"error": "invalid request"})
|
||||||
|
}
|
||||||
|
resp, err := h.AuthClient.SignUp(context.Background(), &req)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(http.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
|
||||||
|
}
|
||||||
|
return c.JSON(resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *AuthHandler) SignIn(c *fiber.Ctx) error {
|
||||||
|
var req pb.SignInRequest
|
||||||
|
if err := c.BodyParser(&req); err != nil {
|
||||||
|
return c.Status(http.StatusBadRequest).JSON(fiber.Map{"error": "invalid request"})
|
||||||
|
}
|
||||||
|
resp, err := h.AuthClient.SignIn(context.Background(), &req)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(http.StatusUnauthorized).JSON(fiber.Map{"error": err.Error()})
|
||||||
|
}
|
||||||
|
return c.JSON(resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *AuthHandler) ValidateToken(c *fiber.Ctx) error {
|
||||||
|
var req pb.ValidateTokenRequest
|
||||||
|
if err := c.BodyParser(&req); err != nil {
|
||||||
|
return c.Status(http.StatusBadRequest).JSON(fiber.Map{"error": "invalid request"})
|
||||||
|
}
|
||||||
|
resp, err := h.AuthClient.ValidateToken(context.Background(), &req)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(http.StatusUnauthorized).JSON(fiber.Map{"error": err.Error()})
|
||||||
|
}
|
||||||
|
return c.JSON(resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *AuthHandler) GetUserInfo(c *fiber.Ctx) error {
|
||||||
|
var req pb.GetUserInfoRequest
|
||||||
|
if err := c.BodyParser(&req); err != nil {
|
||||||
|
return c.Status(http.StatusBadRequest).JSON(fiber.Map{"error": "invalid request"})
|
||||||
|
}
|
||||||
|
resp, err := h.AuthClient.GetUserInfo(context.Background(), &req)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(http.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
|
||||||
|
}
|
||||||
|
return c.JSON(resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTest forwards a test creation request to the auth service
|
||||||
|
func (h *AuthHandler) CreateTest(c *fiber.Ctx) error {
|
||||||
|
var body struct {
|
||||||
|
Test string `json:"test"`
|
||||||
|
}
|
||||||
|
if err := c.BodyParser(&body); err != nil {
|
||||||
|
return c.Status(http.StatusBadRequest).JSON(fiber.Map{"error": "invalid request"})
|
||||||
|
}
|
||||||
|
req := pb.CreateTestRequest{Content: body.Test}
|
||||||
|
resp, err := h.AuthClient.CreateTest(context.Background(), &req)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(http.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
|
||||||
|
}
|
||||||
|
return c.JSON(resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListTests retrieves tests from the auth service
|
||||||
|
func (h *AuthHandler) ListTests(c *fiber.Ctx) error {
|
||||||
|
resp, err := h.AuthClient.ListTests(context.Background(), &pb.ListTestsRequest{})
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(http.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
|
||||||
|
}
|
||||||
|
return c.JSON(resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTest retrieves a single test by ID
|
||||||
|
func (h *AuthHandler) GetTest(c *fiber.Ctx) error {
|
||||||
|
id := c.Params("id")
|
||||||
|
if id == "" {
|
||||||
|
return c.Status(http.StatusBadRequest).JSON(fiber.Map{"error": "test id required"})
|
||||||
|
}
|
||||||
|
|
||||||
|
var testID uint64
|
||||||
|
_, err := fmt.Sscanf(id, "%d", &testID)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(http.StatusBadRequest).JSON(fiber.Map{"error": "invalid test id"})
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.AuthClient.GetTest(context.Background(), &pb.GetTestRequest{Id: testID})
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(http.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
|
||||||
|
}
|
||||||
|
return c.JSON(resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTest updates a test by ID
|
||||||
|
func (h *AuthHandler) UpdateTest(c *fiber.Ctx) error {
|
||||||
|
id := c.Params("id")
|
||||||
|
if id == "" {
|
||||||
|
return c.Status(http.StatusBadRequest).JSON(fiber.Map{"error": "test id required"})
|
||||||
|
}
|
||||||
|
|
||||||
|
var testID uint64
|
||||||
|
_, err := fmt.Sscanf(id, "%d", &testID)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(http.StatusBadRequest).JSON(fiber.Map{"error": "invalid test id"})
|
||||||
|
}
|
||||||
|
|
||||||
|
var body struct {
|
||||||
|
Content string `json:"content"`
|
||||||
|
}
|
||||||
|
if err := c.BodyParser(&body); err != nil {
|
||||||
|
return c.Status(http.StatusBadRequest).JSON(fiber.Map{"error": "invalid request"})
|
||||||
|
}
|
||||||
|
|
||||||
|
if body.Content == "" {
|
||||||
|
return c.Status(http.StatusBadRequest).JSON(fiber.Map{"error": "content required"})
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.AuthClient.UpdateTest(context.Background(), &pb.UpdateTestRequest{
|
||||||
|
Id: testID,
|
||||||
|
Content: body.Content,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(http.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
|
||||||
|
}
|
||||||
|
return c.JSON(resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteTest deletes a test by ID
|
||||||
|
func (h *AuthHandler) DeleteTest(c *fiber.Ctx) error {
|
||||||
|
id := c.Params("id")
|
||||||
|
if id == "" {
|
||||||
|
return c.Status(http.StatusBadRequest).JSON(fiber.Map{"error": "test id required"})
|
||||||
|
}
|
||||||
|
|
||||||
|
var testID uint64
|
||||||
|
_, err := fmt.Sscanf(id, "%d", &testID)
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(http.StatusBadRequest).JSON(fiber.Map{"error": "invalid test id"})
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := h.AuthClient.DeleteTest(context.Background(), &pb.DeleteTestRequest{Id: testID})
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(http.StatusInternalServerError).JSON(fiber.Map{"error": err.Error()})
|
||||||
|
}
|
||||||
|
return c.JSON(resp)
|
||||||
|
}
|
||||||
50
api-gateway/internal/middlewares/jwt.go
Normal file
50
api-gateway/internal/middlewares/jwt.go
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package middlewares
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"go-microservices/api-gateway/internal/clients"
|
||||||
|
pb "go-microservices/proto/auth"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
// JWTMiddleware returns a Fiber middleware that validates JWT via the auth service gRPC.
|
||||||
|
func JWTMiddleware(authClient *clients.AuthClient) fiber.Handler {
|
||||||
|
return func(c *fiber.Ctx) error {
|
||||||
|
// Try to get Authorization header (Fiber handles case-insensitivity)
|
||||||
|
authHeader := c.Get("Authorization")
|
||||||
|
var token string
|
||||||
|
|
||||||
|
if authHeader != "" {
|
||||||
|
parts := strings.Split(authHeader, " ")
|
||||||
|
if len(parts) == 2 && parts[0] == "Bearer" {
|
||||||
|
token = parts[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to cookie if no Bearer token found
|
||||||
|
if token == "" {
|
||||||
|
token = c.Cookies("access_token")
|
||||||
|
}
|
||||||
|
|
||||||
|
if token == "" {
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{"error": "missing token"})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate token via gRPC
|
||||||
|
resp, err := authClient.ValidateToken(context.Background(), &pb.ValidateTokenRequest{Token: token})
|
||||||
|
if err != nil {
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{"error": "token validation failed"})
|
||||||
|
}
|
||||||
|
|
||||||
|
if !resp.Valid {
|
||||||
|
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{"error": "invalid token"})
|
||||||
|
}
|
||||||
|
|
||||||
|
c.Locals("userID", resp.UserId)
|
||||||
|
|
||||||
|
return c.Next()
|
||||||
|
}
|
||||||
|
}
|
||||||
36
api-gateway/internal/middlewares/roles.go
Normal file
36
api-gateway/internal/middlewares/roles.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package middlewares
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func OnlyAdmin(db *gorm.DB, fn fiber.Handler) fiber.Handler {
|
||||||
|
return func(c *fiber.Ctx) error {
|
||||||
|
role, ok := c.Locals("userRole").(string)
|
||||||
|
if !ok || role != "Admin" {
|
||||||
|
return c.Status(fiber.StatusForbidden).JSON(fiber.Map{"error": "Access denied"})
|
||||||
|
}
|
||||||
|
return fn(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func OnlyModerator(db *gorm.DB, fn fiber.Handler) fiber.Handler {
|
||||||
|
return func(c *fiber.Ctx) error {
|
||||||
|
role, ok := c.Locals("userRole").(string)
|
||||||
|
if !ok || (role != "Moderator" && role != "Admin") {
|
||||||
|
return c.Status(fiber.StatusForbidden).JSON(fiber.Map{"error": "Access denied"})
|
||||||
|
}
|
||||||
|
return fn(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func OnlyUser(db *gorm.DB, fn fiber.Handler) fiber.Handler {
|
||||||
|
return func(c *fiber.Ctx) error {
|
||||||
|
role, ok := c.Locals("userRole").(string)
|
||||||
|
if !ok || role != "User" {
|
||||||
|
return c.Status(fiber.StatusForbidden).JSON(fiber.Map{"error": "Access denied"})
|
||||||
|
}
|
||||||
|
return fn(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
30
api-gateway/internal/routes/routes.go
Normal file
30
api-gateway/internal/routes/routes.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package routes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go-microservices/api-gateway/internal/clients"
|
||||||
|
"go-microservices/api-gateway/internal/handlers"
|
||||||
|
"go-microservices/api-gateway/internal/middlewares"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RegisterAuthRoutes(app *fiber.App, authHandler *handlers.AuthHandler, authClient *clients.AuthClient) {
|
||||||
|
api := app.Group("/api/v1")
|
||||||
|
|
||||||
|
// Health route
|
||||||
|
api.Get("/", func(c *fiber.Ctx) error {
|
||||||
|
return c.SendString("API Gateway is running!")
|
||||||
|
})
|
||||||
|
|
||||||
|
api.Post("/signup", authHandler.SignUp)
|
||||||
|
api.Post("/signin", authHandler.SignIn)
|
||||||
|
api.Post("/validate", authHandler.ValidateToken)
|
||||||
|
api.Post("/userinfo", middlewares.JWTMiddleware(authClient), authHandler.GetUserInfo)
|
||||||
|
|
||||||
|
// Test endpoints
|
||||||
|
api.Post("/test", authHandler.CreateTest)
|
||||||
|
api.Get("/tests", authHandler.ListTests)
|
||||||
|
api.Get("/tests/:id", authHandler.GetTest)
|
||||||
|
api.Put("/tests/:id", authHandler.UpdateTest)
|
||||||
|
api.Delete("/tests/:id", authHandler.DeleteTest)
|
||||||
|
}
|
||||||
86
docker-compose.yml
Normal file
86
docker-compose.yml
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
# PostgreSQL Database
|
||||||
|
postgres:
|
||||||
|
image: postgres:15-alpine
|
||||||
|
container_name: go-microservices-db
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: ${POSTGRES_DB:-microservices_db}
|
||||||
|
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
||||||
|
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
|
||||||
|
ports:
|
||||||
|
- "${BLUEPRINT_DB_PORT:-5432}:5432"
|
||||||
|
volumes:
|
||||||
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
networks:
|
||||||
|
- microservices-network
|
||||||
|
|
||||||
|
# Auth Service
|
||||||
|
auth-service:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./services/auth-service/Dockerfile
|
||||||
|
container_name: auth-service
|
||||||
|
ports:
|
||||||
|
- "50051:50051"
|
||||||
|
environment:
|
||||||
|
- DATABASE_URL=postgres://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@postgres:${BLUEPRINT_DB_PORT:-5432}/${POSTGRES_DB:-microservices_db}?sslmode=disable
|
||||||
|
- JWT_SECRET=${JWT_SECRET:-your-development-jwt-secret-change-in-production}
|
||||||
|
depends_on:
|
||||||
|
- postgres
|
||||||
|
networks:
|
||||||
|
- microservices-network
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
# User Service
|
||||||
|
user-service:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./services/user-service/Dockerfile
|
||||||
|
container_name: user-service
|
||||||
|
ports:
|
||||||
|
- "50052:50052"
|
||||||
|
environment:
|
||||||
|
- DATABASE_URL=postgres://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@postgres:${BLUEPRINT_DB_PORT:-5432}/${POSTGRES_DB:-microservices_db}?sslmode=disable
|
||||||
|
networks:
|
||||||
|
- microservices-network
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
# Post Service
|
||||||
|
post-service:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./services/post-service/Dockerfile
|
||||||
|
container_name: post-service
|
||||||
|
ports:
|
||||||
|
- "50053:50053"
|
||||||
|
environment:
|
||||||
|
- DATABASE_URL=postgres://${POSTGRES_USER:-postgres}:${POSTGRES_PASSWORD:-postgres}@postgres:${BLUEPRINT_DB_PORT:-5432}/${POSTGRES_DB:-microservices_db}?sslmode=disable
|
||||||
|
networks:
|
||||||
|
- microservices-network
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
# API Gateway
|
||||||
|
api-gateway:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./api-gateway/Dockerfile
|
||||||
|
container_name: api-gateway
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
environment:
|
||||||
|
- AUTH_SERVICE_GRPC=auth-service:50051
|
||||||
|
- JWT_SECRET=${JWT_SECRET:-your-development-jwt-secret-change-in-production}
|
||||||
|
depends_on:
|
||||||
|
- auth-service
|
||||||
|
networks:
|
||||||
|
- microservices-network
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
postgres_data:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
microservices-network:
|
||||||
|
driver: bridge
|
||||||
1241
proto/auth.pb.go
Normal file
1241
proto/auth.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
118
proto/auth.proto
Normal file
118
proto/auth.proto
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package auth;
|
||||||
|
|
||||||
|
// set to your module path + proto path; adjust if your module name differs
|
||||||
|
option go_package = "go-microservices/proto/auth;authpb";
|
||||||
|
|
||||||
|
service AuthService {
|
||||||
|
rpc SignUp (SignUpRequest) returns (SignUpResponse);
|
||||||
|
rpc SignIn (SignInRequest) returns (SignInResponse);
|
||||||
|
rpc ValidateToken (ValidateTokenRequest) returns (ValidateTokenResponse);
|
||||||
|
rpc GetUserInfo (GetUserInfoRequest) returns (GetUserInfoResponse);
|
||||||
|
rpc ConfirmEmail (ConfirmEmailRequest) returns (ConfirmEmailResponse);
|
||||||
|
|
||||||
|
rpc CreateTest (CreateTestRequest) returns (CreateTestResponse);
|
||||||
|
rpc ListTests (ListTestsRequest) returns (ListTestsResponse);
|
||||||
|
rpc GetTest (GetTestRequest) returns (GetTestResponse);
|
||||||
|
rpc UpdateTest (UpdateTestRequest) returns (UpdateTestResponse);
|
||||||
|
rpc DeleteTest (DeleteTestRequest) returns (DeleteTestResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
message SignUpRequest {
|
||||||
|
string username = 1;
|
||||||
|
string email = 2;
|
||||||
|
string password = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SignUpResponse {
|
||||||
|
string user_id = 1;
|
||||||
|
string message = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SignInRequest {
|
||||||
|
string email = 1;
|
||||||
|
string password = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message SignInResponse {
|
||||||
|
string access_token = 1;
|
||||||
|
string refresh_token = 2;
|
||||||
|
string user_id = 3;
|
||||||
|
string message = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ValidateTokenRequest {
|
||||||
|
string token = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ValidateTokenResponse {
|
||||||
|
bool valid = 1;
|
||||||
|
string user_id = 2;
|
||||||
|
string message = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetUserInfoRequest {
|
||||||
|
string user_id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetUserInfoResponse {
|
||||||
|
string user_id = 1;
|
||||||
|
string username = 2;
|
||||||
|
string email = 3;
|
||||||
|
repeated string roles = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ConfirmEmailRequest {
|
||||||
|
string token = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ConfirmEmailResponse {
|
||||||
|
bool success = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Test {
|
||||||
|
uint64 id = 1;
|
||||||
|
string content = 2;
|
||||||
|
string created_at = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateTestRequest {
|
||||||
|
string content = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateTestResponse {
|
||||||
|
Test test = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ListTestsRequest {}
|
||||||
|
|
||||||
|
message ListTestsResponse {
|
||||||
|
repeated Test tests = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetTestRequest {
|
||||||
|
uint64 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetTestResponse {
|
||||||
|
Test test = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateTestRequest {
|
||||||
|
uint64 id = 1;
|
||||||
|
string content = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateTestResponse {
|
||||||
|
Test test = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteTestRequest {
|
||||||
|
uint64 id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteTestResponse {
|
||||||
|
bool success = 1;
|
||||||
|
string message = 2;
|
||||||
|
}
|
||||||
1241
proto/auth/auth.pb.go
Normal file
1241
proto/auth/auth.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
463
proto/auth/auth_grpc.pb.go
Normal file
463
proto/auth/auth_grpc.pb.go
Normal file
@@ -0,0 +1,463 @@
|
|||||||
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// - protoc-gen-go-grpc v1.6.1
|
||||||
|
// - protoc v6.31.1
|
||||||
|
// source: auth.proto
|
||||||
|
|
||||||
|
package authpb
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
codes "google.golang.org/grpc/codes"
|
||||||
|
status "google.golang.org/grpc/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
// Requires gRPC-Go v1.64.0 or later.
|
||||||
|
const _ = grpc.SupportPackageIsVersion9
|
||||||
|
|
||||||
|
const (
|
||||||
|
AuthService_SignUp_FullMethodName = "/auth.AuthService/SignUp"
|
||||||
|
AuthService_SignIn_FullMethodName = "/auth.AuthService/SignIn"
|
||||||
|
AuthService_ValidateToken_FullMethodName = "/auth.AuthService/ValidateToken"
|
||||||
|
AuthService_GetUserInfo_FullMethodName = "/auth.AuthService/GetUserInfo"
|
||||||
|
AuthService_ConfirmEmail_FullMethodName = "/auth.AuthService/ConfirmEmail"
|
||||||
|
AuthService_CreateTest_FullMethodName = "/auth.AuthService/CreateTest"
|
||||||
|
AuthService_ListTests_FullMethodName = "/auth.AuthService/ListTests"
|
||||||
|
AuthService_GetTest_FullMethodName = "/auth.AuthService/GetTest"
|
||||||
|
AuthService_UpdateTest_FullMethodName = "/auth.AuthService/UpdateTest"
|
||||||
|
AuthService_DeleteTest_FullMethodName = "/auth.AuthService/DeleteTest"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AuthServiceClient is the client API for AuthService service.
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
type AuthServiceClient interface {
|
||||||
|
SignUp(ctx context.Context, in *SignUpRequest, opts ...grpc.CallOption) (*SignUpResponse, error)
|
||||||
|
SignIn(ctx context.Context, in *SignInRequest, opts ...grpc.CallOption) (*SignInResponse, error)
|
||||||
|
ValidateToken(ctx context.Context, in *ValidateTokenRequest, opts ...grpc.CallOption) (*ValidateTokenResponse, error)
|
||||||
|
GetUserInfo(ctx context.Context, in *GetUserInfoRequest, opts ...grpc.CallOption) (*GetUserInfoResponse, error)
|
||||||
|
ConfirmEmail(ctx context.Context, in *ConfirmEmailRequest, opts ...grpc.CallOption) (*ConfirmEmailResponse, error)
|
||||||
|
CreateTest(ctx context.Context, in *CreateTestRequest, opts ...grpc.CallOption) (*CreateTestResponse, error)
|
||||||
|
ListTests(ctx context.Context, in *ListTestsRequest, opts ...grpc.CallOption) (*ListTestsResponse, error)
|
||||||
|
GetTest(ctx context.Context, in *GetTestRequest, opts ...grpc.CallOption) (*GetTestResponse, error)
|
||||||
|
UpdateTest(ctx context.Context, in *UpdateTestRequest, opts ...grpc.CallOption) (*UpdateTestResponse, error)
|
||||||
|
DeleteTest(ctx context.Context, in *DeleteTestRequest, opts ...grpc.CallOption) (*DeleteTestResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type authServiceClient struct {
|
||||||
|
cc grpc.ClientConnInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAuthServiceClient(cc grpc.ClientConnInterface) AuthServiceClient {
|
||||||
|
return &authServiceClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) SignUp(ctx context.Context, in *SignUpRequest, opts ...grpc.CallOption) (*SignUpResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(SignUpResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_SignUp_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) SignIn(ctx context.Context, in *SignInRequest, opts ...grpc.CallOption) (*SignInResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(SignInResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_SignIn_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) ValidateToken(ctx context.Context, in *ValidateTokenRequest, opts ...grpc.CallOption) (*ValidateTokenResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(ValidateTokenResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_ValidateToken_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) GetUserInfo(ctx context.Context, in *GetUserInfoRequest, opts ...grpc.CallOption) (*GetUserInfoResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(GetUserInfoResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_GetUserInfo_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) ConfirmEmail(ctx context.Context, in *ConfirmEmailRequest, opts ...grpc.CallOption) (*ConfirmEmailResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(ConfirmEmailResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_ConfirmEmail_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) CreateTest(ctx context.Context, in *CreateTestRequest, opts ...grpc.CallOption) (*CreateTestResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(CreateTestResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_CreateTest_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) ListTests(ctx context.Context, in *ListTestsRequest, opts ...grpc.CallOption) (*ListTestsResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(ListTestsResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_ListTests_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) GetTest(ctx context.Context, in *GetTestRequest, opts ...grpc.CallOption) (*GetTestResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(GetTestResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_GetTest_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) UpdateTest(ctx context.Context, in *UpdateTestRequest, opts ...grpc.CallOption) (*UpdateTestResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(UpdateTestResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_UpdateTest_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) DeleteTest(ctx context.Context, in *DeleteTestRequest, opts ...grpc.CallOption) (*DeleteTestResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(DeleteTestResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_DeleteTest_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthServiceServer is the server API for AuthService service.
|
||||||
|
// All implementations must embed UnimplementedAuthServiceServer
|
||||||
|
// for forward compatibility.
|
||||||
|
type AuthServiceServer interface {
|
||||||
|
SignUp(context.Context, *SignUpRequest) (*SignUpResponse, error)
|
||||||
|
SignIn(context.Context, *SignInRequest) (*SignInResponse, error)
|
||||||
|
ValidateToken(context.Context, *ValidateTokenRequest) (*ValidateTokenResponse, error)
|
||||||
|
GetUserInfo(context.Context, *GetUserInfoRequest) (*GetUserInfoResponse, error)
|
||||||
|
ConfirmEmail(context.Context, *ConfirmEmailRequest) (*ConfirmEmailResponse, error)
|
||||||
|
CreateTest(context.Context, *CreateTestRequest) (*CreateTestResponse, error)
|
||||||
|
ListTests(context.Context, *ListTestsRequest) (*ListTestsResponse, error)
|
||||||
|
GetTest(context.Context, *GetTestRequest) (*GetTestResponse, error)
|
||||||
|
UpdateTest(context.Context, *UpdateTestRequest) (*UpdateTestResponse, error)
|
||||||
|
DeleteTest(context.Context, *DeleteTestRequest) (*DeleteTestResponse, error)
|
||||||
|
mustEmbedUnimplementedAuthServiceServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedAuthServiceServer must be embedded to have
|
||||||
|
// forward compatible implementations.
|
||||||
|
//
|
||||||
|
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||||
|
// pointer dereference when methods are called.
|
||||||
|
type UnimplementedAuthServiceServer struct{}
|
||||||
|
|
||||||
|
func (UnimplementedAuthServiceServer) SignUp(context.Context, *SignUpRequest) (*SignUpResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method SignUp not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) SignIn(context.Context, *SignInRequest) (*SignInResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method SignIn not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) ValidateToken(context.Context, *ValidateTokenRequest) (*ValidateTokenResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method ValidateToken not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) GetUserInfo(context.Context, *GetUserInfoRequest) (*GetUserInfoResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method GetUserInfo not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) ConfirmEmail(context.Context, *ConfirmEmailRequest) (*ConfirmEmailResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method ConfirmEmail not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) CreateTest(context.Context, *CreateTestRequest) (*CreateTestResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method CreateTest not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) ListTests(context.Context, *ListTestsRequest) (*ListTestsResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method ListTests not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) GetTest(context.Context, *GetTestRequest) (*GetTestResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method GetTest not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) UpdateTest(context.Context, *UpdateTestRequest) (*UpdateTestResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method UpdateTest not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) DeleteTest(context.Context, *DeleteTestRequest) (*DeleteTestResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method DeleteTest not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) mustEmbedUnimplementedAuthServiceServer() {}
|
||||||
|
func (UnimplementedAuthServiceServer) testEmbeddedByValue() {}
|
||||||
|
|
||||||
|
// UnsafeAuthServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||||
|
// Use of this interface is not recommended, as added methods to AuthServiceServer will
|
||||||
|
// result in compilation errors.
|
||||||
|
type UnsafeAuthServiceServer interface {
|
||||||
|
mustEmbedUnimplementedAuthServiceServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterAuthServiceServer(s grpc.ServiceRegistrar, srv AuthServiceServer) {
|
||||||
|
// If the following call panics, it indicates UnimplementedAuthServiceServer was
|
||||||
|
// embedded by pointer and is nil. This will cause panics if an
|
||||||
|
// unimplemented method is ever invoked, so we test this at initialization
|
||||||
|
// time to prevent it from happening at runtime later due to I/O.
|
||||||
|
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||||
|
t.testEmbeddedByValue()
|
||||||
|
}
|
||||||
|
s.RegisterService(&AuthService_ServiceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_SignUp_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(SignUpRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).SignUp(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_SignUp_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).SignUp(ctx, req.(*SignUpRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_SignIn_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(SignInRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).SignIn(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_SignIn_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).SignIn(ctx, req.(*SignInRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_ValidateToken_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(ValidateTokenRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).ValidateToken(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_ValidateToken_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).ValidateToken(ctx, req.(*ValidateTokenRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_GetUserInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetUserInfoRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).GetUserInfo(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_GetUserInfo_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).GetUserInfo(ctx, req.(*GetUserInfoRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_ConfirmEmail_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(ConfirmEmailRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).ConfirmEmail(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_ConfirmEmail_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).ConfirmEmail(ctx, req.(*ConfirmEmailRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_CreateTest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(CreateTestRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).CreateTest(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_CreateTest_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).CreateTest(ctx, req.(*CreateTestRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_ListTests_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(ListTestsRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).ListTests(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_ListTests_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).ListTests(ctx, req.(*ListTestsRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_GetTest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetTestRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).GetTest(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_GetTest_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).GetTest(ctx, req.(*GetTestRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_UpdateTest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(UpdateTestRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).UpdateTest(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_UpdateTest_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).UpdateTest(ctx, req.(*UpdateTestRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_DeleteTest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(DeleteTestRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).DeleteTest(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_DeleteTest_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).DeleteTest(ctx, req.(*DeleteTestRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthService_ServiceDesc is the grpc.ServiceDesc for AuthService service.
|
||||||
|
// It's only intended for direct use with grpc.RegisterService,
|
||||||
|
// and not to be introspected or modified (even as a copy)
|
||||||
|
var AuthService_ServiceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "auth.AuthService",
|
||||||
|
HandlerType: (*AuthServiceServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "SignUp",
|
||||||
|
Handler: _AuthService_SignUp_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "SignIn",
|
||||||
|
Handler: _AuthService_SignIn_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "ValidateToken",
|
||||||
|
Handler: _AuthService_ValidateToken_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "GetUserInfo",
|
||||||
|
Handler: _AuthService_GetUserInfo_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "ConfirmEmail",
|
||||||
|
Handler: _AuthService_ConfirmEmail_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "CreateTest",
|
||||||
|
Handler: _AuthService_CreateTest_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "ListTests",
|
||||||
|
Handler: _AuthService_ListTests_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "GetTest",
|
||||||
|
Handler: _AuthService_GetTest_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "UpdateTest",
|
||||||
|
Handler: _AuthService_UpdateTest_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "DeleteTest",
|
||||||
|
Handler: _AuthService_DeleteTest_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{},
|
||||||
|
Metadata: "auth.proto",
|
||||||
|
}
|
||||||
463
proto/auth_grpc.pb.go
Normal file
463
proto/auth_grpc.pb.go
Normal file
@@ -0,0 +1,463 @@
|
|||||||
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// - protoc-gen-go-grpc v1.6.1
|
||||||
|
// - protoc v6.31.1
|
||||||
|
// source: auth.proto
|
||||||
|
|
||||||
|
package authpb
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
codes "google.golang.org/grpc/codes"
|
||||||
|
status "google.golang.org/grpc/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
// Requires gRPC-Go v1.64.0 or later.
|
||||||
|
const _ = grpc.SupportPackageIsVersion9
|
||||||
|
|
||||||
|
const (
|
||||||
|
AuthService_SignUp_FullMethodName = "/auth.AuthService/SignUp"
|
||||||
|
AuthService_SignIn_FullMethodName = "/auth.AuthService/SignIn"
|
||||||
|
AuthService_ValidateToken_FullMethodName = "/auth.AuthService/ValidateToken"
|
||||||
|
AuthService_GetUserInfo_FullMethodName = "/auth.AuthService/GetUserInfo"
|
||||||
|
AuthService_ConfirmEmail_FullMethodName = "/auth.AuthService/ConfirmEmail"
|
||||||
|
AuthService_CreateTest_FullMethodName = "/auth.AuthService/CreateTest"
|
||||||
|
AuthService_ListTests_FullMethodName = "/auth.AuthService/ListTests"
|
||||||
|
AuthService_GetTest_FullMethodName = "/auth.AuthService/GetTest"
|
||||||
|
AuthService_UpdateTest_FullMethodName = "/auth.AuthService/UpdateTest"
|
||||||
|
AuthService_DeleteTest_FullMethodName = "/auth.AuthService/DeleteTest"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AuthServiceClient is the client API for AuthService service.
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
type AuthServiceClient interface {
|
||||||
|
SignUp(ctx context.Context, in *SignUpRequest, opts ...grpc.CallOption) (*SignUpResponse, error)
|
||||||
|
SignIn(ctx context.Context, in *SignInRequest, opts ...grpc.CallOption) (*SignInResponse, error)
|
||||||
|
ValidateToken(ctx context.Context, in *ValidateTokenRequest, opts ...grpc.CallOption) (*ValidateTokenResponse, error)
|
||||||
|
GetUserInfo(ctx context.Context, in *GetUserInfoRequest, opts ...grpc.CallOption) (*GetUserInfoResponse, error)
|
||||||
|
ConfirmEmail(ctx context.Context, in *ConfirmEmailRequest, opts ...grpc.CallOption) (*ConfirmEmailResponse, error)
|
||||||
|
CreateTest(ctx context.Context, in *CreateTestRequest, opts ...grpc.CallOption) (*CreateTestResponse, error)
|
||||||
|
ListTests(ctx context.Context, in *ListTestsRequest, opts ...grpc.CallOption) (*ListTestsResponse, error)
|
||||||
|
GetTest(ctx context.Context, in *GetTestRequest, opts ...grpc.CallOption) (*GetTestResponse, error)
|
||||||
|
UpdateTest(ctx context.Context, in *UpdateTestRequest, opts ...grpc.CallOption) (*UpdateTestResponse, error)
|
||||||
|
DeleteTest(ctx context.Context, in *DeleteTestRequest, opts ...grpc.CallOption) (*DeleteTestResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type authServiceClient struct {
|
||||||
|
cc grpc.ClientConnInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAuthServiceClient(cc grpc.ClientConnInterface) AuthServiceClient {
|
||||||
|
return &authServiceClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) SignUp(ctx context.Context, in *SignUpRequest, opts ...grpc.CallOption) (*SignUpResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(SignUpResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_SignUp_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) SignIn(ctx context.Context, in *SignInRequest, opts ...grpc.CallOption) (*SignInResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(SignInResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_SignIn_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) ValidateToken(ctx context.Context, in *ValidateTokenRequest, opts ...grpc.CallOption) (*ValidateTokenResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(ValidateTokenResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_ValidateToken_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) GetUserInfo(ctx context.Context, in *GetUserInfoRequest, opts ...grpc.CallOption) (*GetUserInfoResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(GetUserInfoResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_GetUserInfo_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) ConfirmEmail(ctx context.Context, in *ConfirmEmailRequest, opts ...grpc.CallOption) (*ConfirmEmailResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(ConfirmEmailResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_ConfirmEmail_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) CreateTest(ctx context.Context, in *CreateTestRequest, opts ...grpc.CallOption) (*CreateTestResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(CreateTestResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_CreateTest_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) ListTests(ctx context.Context, in *ListTestsRequest, opts ...grpc.CallOption) (*ListTestsResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(ListTestsResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_ListTests_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) GetTest(ctx context.Context, in *GetTestRequest, opts ...grpc.CallOption) (*GetTestResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(GetTestResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_GetTest_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) UpdateTest(ctx context.Context, in *UpdateTestRequest, opts ...grpc.CallOption) (*UpdateTestResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(UpdateTestResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_UpdateTest_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *authServiceClient) DeleteTest(ctx context.Context, in *DeleteTestRequest, opts ...grpc.CallOption) (*DeleteTestResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(DeleteTestResponse)
|
||||||
|
err := c.cc.Invoke(ctx, AuthService_DeleteTest_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthServiceServer is the server API for AuthService service.
|
||||||
|
// All implementations must embed UnimplementedAuthServiceServer
|
||||||
|
// for forward compatibility.
|
||||||
|
type AuthServiceServer interface {
|
||||||
|
SignUp(context.Context, *SignUpRequest) (*SignUpResponse, error)
|
||||||
|
SignIn(context.Context, *SignInRequest) (*SignInResponse, error)
|
||||||
|
ValidateToken(context.Context, *ValidateTokenRequest) (*ValidateTokenResponse, error)
|
||||||
|
GetUserInfo(context.Context, *GetUserInfoRequest) (*GetUserInfoResponse, error)
|
||||||
|
ConfirmEmail(context.Context, *ConfirmEmailRequest) (*ConfirmEmailResponse, error)
|
||||||
|
CreateTest(context.Context, *CreateTestRequest) (*CreateTestResponse, error)
|
||||||
|
ListTests(context.Context, *ListTestsRequest) (*ListTestsResponse, error)
|
||||||
|
GetTest(context.Context, *GetTestRequest) (*GetTestResponse, error)
|
||||||
|
UpdateTest(context.Context, *UpdateTestRequest) (*UpdateTestResponse, error)
|
||||||
|
DeleteTest(context.Context, *DeleteTestRequest) (*DeleteTestResponse, error)
|
||||||
|
mustEmbedUnimplementedAuthServiceServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedAuthServiceServer must be embedded to have
|
||||||
|
// forward compatible implementations.
|
||||||
|
//
|
||||||
|
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||||
|
// pointer dereference when methods are called.
|
||||||
|
type UnimplementedAuthServiceServer struct{}
|
||||||
|
|
||||||
|
func (UnimplementedAuthServiceServer) SignUp(context.Context, *SignUpRequest) (*SignUpResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method SignUp not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) SignIn(context.Context, *SignInRequest) (*SignInResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method SignIn not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) ValidateToken(context.Context, *ValidateTokenRequest) (*ValidateTokenResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method ValidateToken not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) GetUserInfo(context.Context, *GetUserInfoRequest) (*GetUserInfoResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method GetUserInfo not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) ConfirmEmail(context.Context, *ConfirmEmailRequest) (*ConfirmEmailResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method ConfirmEmail not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) CreateTest(context.Context, *CreateTestRequest) (*CreateTestResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method CreateTest not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) ListTests(context.Context, *ListTestsRequest) (*ListTestsResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method ListTests not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) GetTest(context.Context, *GetTestRequest) (*GetTestResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method GetTest not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) UpdateTest(context.Context, *UpdateTestRequest) (*UpdateTestResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method UpdateTest not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) DeleteTest(context.Context, *DeleteTestRequest) (*DeleteTestResponse, error) {
|
||||||
|
return nil, status.Error(codes.Unimplemented, "method DeleteTest not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedAuthServiceServer) mustEmbedUnimplementedAuthServiceServer() {}
|
||||||
|
func (UnimplementedAuthServiceServer) testEmbeddedByValue() {}
|
||||||
|
|
||||||
|
// UnsafeAuthServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||||
|
// Use of this interface is not recommended, as added methods to AuthServiceServer will
|
||||||
|
// result in compilation errors.
|
||||||
|
type UnsafeAuthServiceServer interface {
|
||||||
|
mustEmbedUnimplementedAuthServiceServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterAuthServiceServer(s grpc.ServiceRegistrar, srv AuthServiceServer) {
|
||||||
|
// If the following call panics, it indicates UnimplementedAuthServiceServer was
|
||||||
|
// embedded by pointer and is nil. This will cause panics if an
|
||||||
|
// unimplemented method is ever invoked, so we test this at initialization
|
||||||
|
// time to prevent it from happening at runtime later due to I/O.
|
||||||
|
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||||
|
t.testEmbeddedByValue()
|
||||||
|
}
|
||||||
|
s.RegisterService(&AuthService_ServiceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_SignUp_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(SignUpRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).SignUp(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_SignUp_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).SignUp(ctx, req.(*SignUpRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_SignIn_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(SignInRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).SignIn(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_SignIn_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).SignIn(ctx, req.(*SignInRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_ValidateToken_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(ValidateTokenRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).ValidateToken(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_ValidateToken_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).ValidateToken(ctx, req.(*ValidateTokenRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_GetUserInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetUserInfoRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).GetUserInfo(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_GetUserInfo_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).GetUserInfo(ctx, req.(*GetUserInfoRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_ConfirmEmail_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(ConfirmEmailRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).ConfirmEmail(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_ConfirmEmail_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).ConfirmEmail(ctx, req.(*ConfirmEmailRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_CreateTest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(CreateTestRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).CreateTest(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_CreateTest_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).CreateTest(ctx, req.(*CreateTestRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_ListTests_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(ListTestsRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).ListTests(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_ListTests_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).ListTests(ctx, req.(*ListTestsRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_GetTest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetTestRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).GetTest(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_GetTest_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).GetTest(ctx, req.(*GetTestRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_UpdateTest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(UpdateTestRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).UpdateTest(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_UpdateTest_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).UpdateTest(ctx, req.(*UpdateTestRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _AuthService_DeleteTest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(DeleteTestRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(AuthServiceServer).DeleteTest(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: AuthService_DeleteTest_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(AuthServiceServer).DeleteTest(ctx, req.(*DeleteTestRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthService_ServiceDesc is the grpc.ServiceDesc for AuthService service.
|
||||||
|
// It's only intended for direct use with grpc.RegisterService,
|
||||||
|
// and not to be introspected or modified (even as a copy)
|
||||||
|
var AuthService_ServiceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "auth.AuthService",
|
||||||
|
HandlerType: (*AuthServiceServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "SignUp",
|
||||||
|
Handler: _AuthService_SignUp_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "SignIn",
|
||||||
|
Handler: _AuthService_SignIn_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "ValidateToken",
|
||||||
|
Handler: _AuthService_ValidateToken_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "GetUserInfo",
|
||||||
|
Handler: _AuthService_GetUserInfo_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "ConfirmEmail",
|
||||||
|
Handler: _AuthService_ConfirmEmail_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "CreateTest",
|
||||||
|
Handler: _AuthService_CreateTest_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "ListTests",
|
||||||
|
Handler: _AuthService_ListTests_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "GetTest",
|
||||||
|
Handler: _AuthService_GetTest_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "UpdateTest",
|
||||||
|
Handler: _AuthService_UpdateTest_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "DeleteTest",
|
||||||
|
Handler: _AuthService_DeleteTest_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{},
|
||||||
|
Metadata: "auth.proto",
|
||||||
|
}
|
||||||
0
proto/common/types.proto
Normal file
0
proto/common/types.proto
Normal file
65
proto/post.proto
Normal file
65
proto/post.proto
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package post;
|
||||||
|
|
||||||
|
option go_package = "go-microservices/proto/post;postpb";
|
||||||
|
|
||||||
|
import "google/protobuf/empty.proto";
|
||||||
|
|
||||||
|
service PostService {
|
||||||
|
rpc CreatePost (CreatePostRequest) returns (CreatePostResponse);
|
||||||
|
rpc GetPost (GetPostRequest) returns (GetPostResponse);
|
||||||
|
rpc UpdatePost (UpdatePostRequest) returns (UpdatePostResponse);
|
||||||
|
rpc DeletePost (DeletePostRequest) returns (google.protobuf.Empty);
|
||||||
|
rpc ListPosts (ListPostsRequest) returns (ListPostsResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
message Post {
|
||||||
|
string id = 1;
|
||||||
|
string author_id = 2;
|
||||||
|
string title = 3;
|
||||||
|
string content = 4;
|
||||||
|
int64 created_at = 5;
|
||||||
|
int64 updated_at = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreatePostRequest {
|
||||||
|
string author_id = 1;
|
||||||
|
string title = 2;
|
||||||
|
string content = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreatePostResponse {
|
||||||
|
Post post = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetPostRequest {
|
||||||
|
string id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetPostResponse {
|
||||||
|
Post post = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdatePostRequest {
|
||||||
|
string id = 1;
|
||||||
|
string title = 2;
|
||||||
|
string content = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdatePostResponse {
|
||||||
|
Post post = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeletePostRequest {
|
||||||
|
string id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ListPostsRequest {
|
||||||
|
int32 page = 1;
|
||||||
|
int32 page_size = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ListPostsResponse {
|
||||||
|
repeated Post posts = 1;
|
||||||
|
}
|
||||||
687
proto/post/post.pb.go
Normal file
687
proto/post/post.pb.go
Normal file
@@ -0,0 +1,687 @@
|
|||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// File: post.proto
|
||||||
|
//
|
||||||
|
// This Protocol Buffers file defines the gRPC contract for the PostService.
|
||||||
|
// It includes service definitions for creating, retrieving, updating, deleting,
|
||||||
|
// and listing posts. Each RPC method has corresponding request and response
|
||||||
|
// messages. The syntax follows proto3 conventions and uses message types for
|
||||||
|
// structured data exchange between microservices.
|
||||||
|
//
|
||||||
|
// Syntax:
|
||||||
|
// - Uses proto3 syntax for modern Protocol Buffers features.
|
||||||
|
// - Defines service and message types for CRUD operations.
|
||||||
|
// - Supports repeated fields for listing multiple posts.
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
// - Enables strongly-typed, language-agnostic communication between services.
|
||||||
|
// - Provides a contract for backend and API Gateway integration.
|
||||||
|
// - Facilitates code generation for gRPC servers and clients.
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// protoc-gen-go v1.36.7
|
||||||
|
// protoc v6.31.1
|
||||||
|
// source: post.proto
|
||||||
|
|
||||||
|
package postpb
|
||||||
|
|
||||||
|
import (
|
||||||
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||||
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||||
|
emptypb "google.golang.org/protobuf/types/known/emptypb"
|
||||||
|
reflect "reflect"
|
||||||
|
sync "sync"
|
||||||
|
unsafe "unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Verify that this generated code is sufficiently up-to-date.
|
||||||
|
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||||
|
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||||
|
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||||
|
)
|
||||||
|
|
||||||
|
type Post struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
AuthorId string `protobuf:"bytes,2,opt,name=author_id,json=authorId,proto3" json:"author_id,omitempty"`
|
||||||
|
Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"`
|
||||||
|
Content string `protobuf:"bytes,4,opt,name=content,proto3" json:"content,omitempty"`
|
||||||
|
CreatedAt int64 `protobuf:"varint,5,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
|
||||||
|
UpdatedAt int64 `protobuf:"varint,6,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Post) Reset() {
|
||||||
|
*x = Post{}
|
||||||
|
mi := &file_post_proto_msgTypes[0]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Post) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*Post) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *Post) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_post_proto_msgTypes[0]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use Post.ProtoReflect.Descriptor instead.
|
||||||
|
func (*Post) Descriptor() ([]byte, []int) {
|
||||||
|
return file_post_proto_rawDescGZIP(), []int{0}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Post) GetId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Post) GetAuthorId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.AuthorId
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Post) GetTitle() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Title
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Post) GetContent() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Content
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Post) GetCreatedAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.CreatedAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *Post) GetUpdatedAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.UpdatedAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreatePostRequest struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
AuthorId string `protobuf:"bytes,1,opt,name=author_id,json=authorId,proto3" json:"author_id,omitempty"`
|
||||||
|
Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"`
|
||||||
|
Content string `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreatePostRequest) Reset() {
|
||||||
|
*x = CreatePostRequest{}
|
||||||
|
mi := &file_post_proto_msgTypes[1]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreatePostRequest) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*CreatePostRequest) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *CreatePostRequest) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_post_proto_msgTypes[1]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use CreatePostRequest.ProtoReflect.Descriptor instead.
|
||||||
|
func (*CreatePostRequest) Descriptor() ([]byte, []int) {
|
||||||
|
return file_post_proto_rawDescGZIP(), []int{1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreatePostRequest) GetAuthorId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.AuthorId
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreatePostRequest) GetTitle() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Title
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreatePostRequest) GetContent() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Content
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreatePostResponse struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Post *Post `protobuf:"bytes,1,opt,name=post,proto3" json:"post,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreatePostResponse) Reset() {
|
||||||
|
*x = CreatePostResponse{}
|
||||||
|
mi := &file_post_proto_msgTypes[2]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreatePostResponse) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*CreatePostResponse) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *CreatePostResponse) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_post_proto_msgTypes[2]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use CreatePostResponse.ProtoReflect.Descriptor instead.
|
||||||
|
func (*CreatePostResponse) Descriptor() ([]byte, []int) {
|
||||||
|
return file_post_proto_rawDescGZIP(), []int{2}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreatePostResponse) GetPost() *Post {
|
||||||
|
if x != nil {
|
||||||
|
return x.Post
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetPostRequest struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetPostRequest) Reset() {
|
||||||
|
*x = GetPostRequest{}
|
||||||
|
mi := &file_post_proto_msgTypes[3]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetPostRequest) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*GetPostRequest) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *GetPostRequest) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_post_proto_msgTypes[3]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use GetPostRequest.ProtoReflect.Descriptor instead.
|
||||||
|
func (*GetPostRequest) Descriptor() ([]byte, []int) {
|
||||||
|
return file_post_proto_rawDescGZIP(), []int{3}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetPostRequest) GetId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetPostResponse struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Post *Post `protobuf:"bytes,1,opt,name=post,proto3" json:"post,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetPostResponse) Reset() {
|
||||||
|
*x = GetPostResponse{}
|
||||||
|
mi := &file_post_proto_msgTypes[4]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetPostResponse) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*GetPostResponse) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *GetPostResponse) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_post_proto_msgTypes[4]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use GetPostResponse.ProtoReflect.Descriptor instead.
|
||||||
|
func (*GetPostResponse) Descriptor() ([]byte, []int) {
|
||||||
|
return file_post_proto_rawDescGZIP(), []int{4}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetPostResponse) GetPost() *Post {
|
||||||
|
if x != nil {
|
||||||
|
return x.Post
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdatePostRequest struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"`
|
||||||
|
Content string `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdatePostRequest) Reset() {
|
||||||
|
*x = UpdatePostRequest{}
|
||||||
|
mi := &file_post_proto_msgTypes[5]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdatePostRequest) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*UpdatePostRequest) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *UpdatePostRequest) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_post_proto_msgTypes[5]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use UpdatePostRequest.ProtoReflect.Descriptor instead.
|
||||||
|
func (*UpdatePostRequest) Descriptor() ([]byte, []int) {
|
||||||
|
return file_post_proto_rawDescGZIP(), []int{5}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdatePostRequest) GetId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdatePostRequest) GetTitle() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Title
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdatePostRequest) GetContent() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Content
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdatePostResponse struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Post *Post `protobuf:"bytes,1,opt,name=post,proto3" json:"post,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdatePostResponse) Reset() {
|
||||||
|
*x = UpdatePostResponse{}
|
||||||
|
mi := &file_post_proto_msgTypes[6]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdatePostResponse) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*UpdatePostResponse) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *UpdatePostResponse) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_post_proto_msgTypes[6]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use UpdatePostResponse.ProtoReflect.Descriptor instead.
|
||||||
|
func (*UpdatePostResponse) Descriptor() ([]byte, []int) {
|
||||||
|
return file_post_proto_rawDescGZIP(), []int{6}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdatePostResponse) GetPost() *Post {
|
||||||
|
if x != nil {
|
||||||
|
return x.Post
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeletePostRequest struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DeletePostRequest) Reset() {
|
||||||
|
*x = DeletePostRequest{}
|
||||||
|
mi := &file_post_proto_msgTypes[7]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DeletePostRequest) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DeletePostRequest) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *DeletePostRequest) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_post_proto_msgTypes[7]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use DeletePostRequest.ProtoReflect.Descriptor instead.
|
||||||
|
func (*DeletePostRequest) Descriptor() ([]byte, []int) {
|
||||||
|
return file_post_proto_rawDescGZIP(), []int{7}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DeletePostRequest) GetId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListPostsRequest struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Page int32 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"`
|
||||||
|
PageSize int32 `protobuf:"varint,2,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListPostsRequest) Reset() {
|
||||||
|
*x = ListPostsRequest{}
|
||||||
|
mi := &file_post_proto_msgTypes[8]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListPostsRequest) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ListPostsRequest) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *ListPostsRequest) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_post_proto_msgTypes[8]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use ListPostsRequest.ProtoReflect.Descriptor instead.
|
||||||
|
func (*ListPostsRequest) Descriptor() ([]byte, []int) {
|
||||||
|
return file_post_proto_rawDescGZIP(), []int{8}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListPostsRequest) GetPage() int32 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Page
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListPostsRequest) GetPageSize() int32 {
|
||||||
|
if x != nil {
|
||||||
|
return x.PageSize
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListPostsResponse struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Posts []*Post `protobuf:"bytes,1,rep,name=posts,proto3" json:"posts,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListPostsResponse) Reset() {
|
||||||
|
*x = ListPostsResponse{}
|
||||||
|
mi := &file_post_proto_msgTypes[9]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListPostsResponse) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ListPostsResponse) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *ListPostsResponse) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_post_proto_msgTypes[9]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use ListPostsResponse.ProtoReflect.Descriptor instead.
|
||||||
|
func (*ListPostsResponse) Descriptor() ([]byte, []int) {
|
||||||
|
return file_post_proto_rawDescGZIP(), []int{9}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListPostsResponse) GetPosts() []*Post {
|
||||||
|
if x != nil {
|
||||||
|
return x.Posts
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var File_post_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
|
const file_post_proto_rawDesc = "" +
|
||||||
|
"\n" +
|
||||||
|
"\n" +
|
||||||
|
"post.proto\x12\x04post\x1a\x1bgoogle/protobuf/empty.proto\"\xa1\x01\n" +
|
||||||
|
"\x04Post\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\tR\x02id\x12\x1b\n" +
|
||||||
|
"\tauthor_id\x18\x02 \x01(\tR\bauthorId\x12\x14\n" +
|
||||||
|
"\x05title\x18\x03 \x01(\tR\x05title\x12\x18\n" +
|
||||||
|
"\acontent\x18\x04 \x01(\tR\acontent\x12\x1d\n" +
|
||||||
|
"\n" +
|
||||||
|
"created_at\x18\x05 \x01(\x03R\tcreatedAt\x12\x1d\n" +
|
||||||
|
"\n" +
|
||||||
|
"updated_at\x18\x06 \x01(\x03R\tupdatedAt\"`\n" +
|
||||||
|
"\x11CreatePostRequest\x12\x1b\n" +
|
||||||
|
"\tauthor_id\x18\x01 \x01(\tR\bauthorId\x12\x14\n" +
|
||||||
|
"\x05title\x18\x02 \x01(\tR\x05title\x12\x18\n" +
|
||||||
|
"\acontent\x18\x03 \x01(\tR\acontent\"4\n" +
|
||||||
|
"\x12CreatePostResponse\x12\x1e\n" +
|
||||||
|
"\x04post\x18\x01 \x01(\v2\n" +
|
||||||
|
".post.PostR\x04post\" \n" +
|
||||||
|
"\x0eGetPostRequest\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\tR\x02id\"1\n" +
|
||||||
|
"\x0fGetPostResponse\x12\x1e\n" +
|
||||||
|
"\x04post\x18\x01 \x01(\v2\n" +
|
||||||
|
".post.PostR\x04post\"S\n" +
|
||||||
|
"\x11UpdatePostRequest\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\tR\x02id\x12\x14\n" +
|
||||||
|
"\x05title\x18\x02 \x01(\tR\x05title\x12\x18\n" +
|
||||||
|
"\acontent\x18\x03 \x01(\tR\acontent\"4\n" +
|
||||||
|
"\x12UpdatePostResponse\x12\x1e\n" +
|
||||||
|
"\x04post\x18\x01 \x01(\v2\n" +
|
||||||
|
".post.PostR\x04post\"#\n" +
|
||||||
|
"\x11DeletePostRequest\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\tR\x02id\"C\n" +
|
||||||
|
"\x10ListPostsRequest\x12\x12\n" +
|
||||||
|
"\x04page\x18\x01 \x01(\x05R\x04page\x12\x1b\n" +
|
||||||
|
"\tpage_size\x18\x02 \x01(\x05R\bpageSize\"5\n" +
|
||||||
|
"\x11ListPostsResponse\x12 \n" +
|
||||||
|
"\x05posts\x18\x01 \x03(\v2\n" +
|
||||||
|
".post.PostR\x05posts2\xc4\x02\n" +
|
||||||
|
"\vPostService\x12?\n" +
|
||||||
|
"\n" +
|
||||||
|
"CreatePost\x12\x17.post.CreatePostRequest\x1a\x18.post.CreatePostResponse\x126\n" +
|
||||||
|
"\aGetPost\x12\x14.post.GetPostRequest\x1a\x15.post.GetPostResponse\x12?\n" +
|
||||||
|
"\n" +
|
||||||
|
"UpdatePost\x12\x17.post.UpdatePostRequest\x1a\x18.post.UpdatePostResponse\x12=\n" +
|
||||||
|
"\n" +
|
||||||
|
"DeletePost\x12\x17.post.DeletePostRequest\x1a\x16.google.protobuf.Empty\x12<\n" +
|
||||||
|
"\tListPosts\x12\x16.post.ListPostsRequest\x1a\x17.post.ListPostsResponseB\x0eZ\f/post;postpbb\x06proto3"
|
||||||
|
|
||||||
|
var (
|
||||||
|
file_post_proto_rawDescOnce sync.Once
|
||||||
|
file_post_proto_rawDescData []byte
|
||||||
|
)
|
||||||
|
|
||||||
|
func file_post_proto_rawDescGZIP() []byte {
|
||||||
|
file_post_proto_rawDescOnce.Do(func() {
|
||||||
|
file_post_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_post_proto_rawDesc), len(file_post_proto_rawDesc)))
|
||||||
|
})
|
||||||
|
return file_post_proto_rawDescData
|
||||||
|
}
|
||||||
|
|
||||||
|
var file_post_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
|
||||||
|
var file_post_proto_goTypes = []any{
|
||||||
|
(*Post)(nil), // 0: post.Post
|
||||||
|
(*CreatePostRequest)(nil), // 1: post.CreatePostRequest
|
||||||
|
(*CreatePostResponse)(nil), // 2: post.CreatePostResponse
|
||||||
|
(*GetPostRequest)(nil), // 3: post.GetPostRequest
|
||||||
|
(*GetPostResponse)(nil), // 4: post.GetPostResponse
|
||||||
|
(*UpdatePostRequest)(nil), // 5: post.UpdatePostRequest
|
||||||
|
(*UpdatePostResponse)(nil), // 6: post.UpdatePostResponse
|
||||||
|
(*DeletePostRequest)(nil), // 7: post.DeletePostRequest
|
||||||
|
(*ListPostsRequest)(nil), // 8: post.ListPostsRequest
|
||||||
|
(*ListPostsResponse)(nil), // 9: post.ListPostsResponse
|
||||||
|
(*emptypb.Empty)(nil), // 10: google.protobuf.Empty
|
||||||
|
}
|
||||||
|
var file_post_proto_depIdxs = []int32{
|
||||||
|
0, // 0: post.CreatePostResponse.post:type_name -> post.Post
|
||||||
|
0, // 1: post.GetPostResponse.post:type_name -> post.Post
|
||||||
|
0, // 2: post.UpdatePostResponse.post:type_name -> post.Post
|
||||||
|
0, // 3: post.ListPostsResponse.posts:type_name -> post.Post
|
||||||
|
1, // 4: post.PostService.CreatePost:input_type -> post.CreatePostRequest
|
||||||
|
3, // 5: post.PostService.GetPost:input_type -> post.GetPostRequest
|
||||||
|
5, // 6: post.PostService.UpdatePost:input_type -> post.UpdatePostRequest
|
||||||
|
7, // 7: post.PostService.DeletePost:input_type -> post.DeletePostRequest
|
||||||
|
8, // 8: post.PostService.ListPosts:input_type -> post.ListPostsRequest
|
||||||
|
2, // 9: post.PostService.CreatePost:output_type -> post.CreatePostResponse
|
||||||
|
4, // 10: post.PostService.GetPost:output_type -> post.GetPostResponse
|
||||||
|
6, // 11: post.PostService.UpdatePost:output_type -> post.UpdatePostResponse
|
||||||
|
10, // 12: post.PostService.DeletePost:output_type -> google.protobuf.Empty
|
||||||
|
9, // 13: post.PostService.ListPosts:output_type -> post.ListPostsResponse
|
||||||
|
9, // [9:14] is the sub-list for method output_type
|
||||||
|
4, // [4:9] is the sub-list for method input_type
|
||||||
|
4, // [4:4] is the sub-list for extension type_name
|
||||||
|
4, // [4:4] is the sub-list for extension extendee
|
||||||
|
0, // [0:4] is the sub-list for field type_name
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { file_post_proto_init() }
|
||||||
|
func file_post_proto_init() {
|
||||||
|
if File_post_proto != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
type x struct{}
|
||||||
|
out := protoimpl.TypeBuilder{
|
||||||
|
File: protoimpl.DescBuilder{
|
||||||
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
|
RawDescriptor: unsafe.Slice(unsafe.StringData(file_post_proto_rawDesc), len(file_post_proto_rawDesc)),
|
||||||
|
NumEnums: 0,
|
||||||
|
NumMessages: 10,
|
||||||
|
NumExtensions: 0,
|
||||||
|
NumServices: 1,
|
||||||
|
},
|
||||||
|
GoTypes: file_post_proto_goTypes,
|
||||||
|
DependencyIndexes: file_post_proto_depIdxs,
|
||||||
|
MessageInfos: file_post_proto_msgTypes,
|
||||||
|
}.Build()
|
||||||
|
File_post_proto = out.File
|
||||||
|
file_post_proto_goTypes = nil
|
||||||
|
file_post_proto_depIdxs = nil
|
||||||
|
}
|
||||||
294
proto/post/post_grpc.pb.go
Normal file
294
proto/post/post_grpc.pb.go
Normal file
@@ -0,0 +1,294 @@
|
|||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// File: post.proto
|
||||||
|
//
|
||||||
|
// This Protocol Buffers file defines the gRPC contract for the PostService.
|
||||||
|
// It includes service definitions for creating, retrieving, updating, deleting,
|
||||||
|
// and listing posts. Each RPC method has corresponding request and response
|
||||||
|
// messages. The syntax follows proto3 conventions and uses message types for
|
||||||
|
// structured data exchange between microservices.
|
||||||
|
//
|
||||||
|
// Syntax:
|
||||||
|
// - Uses proto3 syntax for modern Protocol Buffers features.
|
||||||
|
// - Defines service and message types for CRUD operations.
|
||||||
|
// - Supports repeated fields for listing multiple posts.
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
// - Enables strongly-typed, language-agnostic communication between services.
|
||||||
|
// - Provides a contract for backend and API Gateway integration.
|
||||||
|
// - Facilitates code generation for gRPC servers and clients.
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// - protoc-gen-go-grpc v1.5.1
|
||||||
|
// - protoc v6.31.1
|
||||||
|
// source: post.proto
|
||||||
|
|
||||||
|
package postpb
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
codes "google.golang.org/grpc/codes"
|
||||||
|
status "google.golang.org/grpc/status"
|
||||||
|
emptypb "google.golang.org/protobuf/types/known/emptypb"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
// Requires gRPC-Go v1.64.0 or later.
|
||||||
|
const _ = grpc.SupportPackageIsVersion9
|
||||||
|
|
||||||
|
const (
|
||||||
|
PostService_CreatePost_FullMethodName = "/post.PostService/CreatePost"
|
||||||
|
PostService_GetPost_FullMethodName = "/post.PostService/GetPost"
|
||||||
|
PostService_UpdatePost_FullMethodName = "/post.PostService/UpdatePost"
|
||||||
|
PostService_DeletePost_FullMethodName = "/post.PostService/DeletePost"
|
||||||
|
PostService_ListPosts_FullMethodName = "/post.PostService/ListPosts"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PostServiceClient is the client API for PostService service.
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
type PostServiceClient interface {
|
||||||
|
CreatePost(ctx context.Context, in *CreatePostRequest, opts ...grpc.CallOption) (*CreatePostResponse, error)
|
||||||
|
GetPost(ctx context.Context, in *GetPostRequest, opts ...grpc.CallOption) (*GetPostResponse, error)
|
||||||
|
UpdatePost(ctx context.Context, in *UpdatePostRequest, opts ...grpc.CallOption) (*UpdatePostResponse, error)
|
||||||
|
DeletePost(ctx context.Context, in *DeletePostRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
|
||||||
|
ListPosts(ctx context.Context, in *ListPostsRequest, opts ...grpc.CallOption) (*ListPostsResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type postServiceClient struct {
|
||||||
|
cc grpc.ClientConnInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPostServiceClient(cc grpc.ClientConnInterface) PostServiceClient {
|
||||||
|
return &postServiceClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *postServiceClient) CreatePost(ctx context.Context, in *CreatePostRequest, opts ...grpc.CallOption) (*CreatePostResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(CreatePostResponse)
|
||||||
|
err := c.cc.Invoke(ctx, PostService_CreatePost_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *postServiceClient) GetPost(ctx context.Context, in *GetPostRequest, opts ...grpc.CallOption) (*GetPostResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(GetPostResponse)
|
||||||
|
err := c.cc.Invoke(ctx, PostService_GetPost_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *postServiceClient) UpdatePost(ctx context.Context, in *UpdatePostRequest, opts ...grpc.CallOption) (*UpdatePostResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(UpdatePostResponse)
|
||||||
|
err := c.cc.Invoke(ctx, PostService_UpdatePost_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *postServiceClient) DeletePost(ctx context.Context, in *DeletePostRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(emptypb.Empty)
|
||||||
|
err := c.cc.Invoke(ctx, PostService_DeletePost_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *postServiceClient) ListPosts(ctx context.Context, in *ListPostsRequest, opts ...grpc.CallOption) (*ListPostsResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(ListPostsResponse)
|
||||||
|
err := c.cc.Invoke(ctx, PostService_ListPosts_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostServiceServer is the server API for PostService service.
|
||||||
|
// All implementations must embed UnimplementedPostServiceServer
|
||||||
|
// for forward compatibility.
|
||||||
|
type PostServiceServer interface {
|
||||||
|
CreatePost(context.Context, *CreatePostRequest) (*CreatePostResponse, error)
|
||||||
|
GetPost(context.Context, *GetPostRequest) (*GetPostResponse, error)
|
||||||
|
UpdatePost(context.Context, *UpdatePostRequest) (*UpdatePostResponse, error)
|
||||||
|
DeletePost(context.Context, *DeletePostRequest) (*emptypb.Empty, error)
|
||||||
|
ListPosts(context.Context, *ListPostsRequest) (*ListPostsResponse, error)
|
||||||
|
mustEmbedUnimplementedPostServiceServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedPostServiceServer must be embedded to have
|
||||||
|
// forward compatible implementations.
|
||||||
|
//
|
||||||
|
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||||
|
// pointer dereference when methods are called.
|
||||||
|
type UnimplementedPostServiceServer struct{}
|
||||||
|
|
||||||
|
func (UnimplementedPostServiceServer) CreatePost(context.Context, *CreatePostRequest) (*CreatePostResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method CreatePost not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedPostServiceServer) GetPost(context.Context, *GetPostRequest) (*GetPostResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method GetPost not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedPostServiceServer) UpdatePost(context.Context, *UpdatePostRequest) (*UpdatePostResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method UpdatePost not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedPostServiceServer) DeletePost(context.Context, *DeletePostRequest) (*emptypb.Empty, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method DeletePost not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedPostServiceServer) ListPosts(context.Context, *ListPostsRequest) (*ListPostsResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method ListPosts not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedPostServiceServer) mustEmbedUnimplementedPostServiceServer() {}
|
||||||
|
func (UnimplementedPostServiceServer) testEmbeddedByValue() {}
|
||||||
|
|
||||||
|
// UnsafePostServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||||
|
// Use of this interface is not recommended, as added methods to PostServiceServer will
|
||||||
|
// result in compilation errors.
|
||||||
|
type UnsafePostServiceServer interface {
|
||||||
|
mustEmbedUnimplementedPostServiceServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterPostServiceServer(s grpc.ServiceRegistrar, srv PostServiceServer) {
|
||||||
|
// If the following call pancis, it indicates UnimplementedPostServiceServer was
|
||||||
|
// embedded by pointer and is nil. This will cause panics if an
|
||||||
|
// unimplemented method is ever invoked, so we test this at initialization
|
||||||
|
// time to prevent it from happening at runtime later due to I/O.
|
||||||
|
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||||
|
t.testEmbeddedByValue()
|
||||||
|
}
|
||||||
|
s.RegisterService(&PostService_ServiceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _PostService_CreatePost_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(CreatePostRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(PostServiceServer).CreatePost(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: PostService_CreatePost_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(PostServiceServer).CreatePost(ctx, req.(*CreatePostRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _PostService_GetPost_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetPostRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(PostServiceServer).GetPost(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: PostService_GetPost_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(PostServiceServer).GetPost(ctx, req.(*GetPostRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _PostService_UpdatePost_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(UpdatePostRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(PostServiceServer).UpdatePost(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: PostService_UpdatePost_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(PostServiceServer).UpdatePost(ctx, req.(*UpdatePostRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _PostService_DeletePost_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(DeletePostRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(PostServiceServer).DeletePost(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: PostService_DeletePost_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(PostServiceServer).DeletePost(ctx, req.(*DeletePostRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _PostService_ListPosts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(ListPostsRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(PostServiceServer).ListPosts(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: PostService_ListPosts_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(PostServiceServer).ListPosts(ctx, req.(*ListPostsRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostService_ServiceDesc is the grpc.ServiceDesc for PostService service.
|
||||||
|
// It's only intended for direct use with grpc.RegisterService,
|
||||||
|
// and not to be introspected or modified (even as a copy)
|
||||||
|
var PostService_ServiceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "post.PostService",
|
||||||
|
HandlerType: (*PostServiceServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "CreatePost",
|
||||||
|
Handler: _PostService_CreatePost_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "GetPost",
|
||||||
|
Handler: _PostService_GetPost_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "UpdatePost",
|
||||||
|
Handler: _PostService_UpdatePost_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "DeletePost",
|
||||||
|
Handler: _PostService_DeletePost_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "ListPosts",
|
||||||
|
Handler: _PostService_ListPosts_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{},
|
||||||
|
Metadata: "post.proto",
|
||||||
|
}
|
||||||
69
proto/user.proto
Normal file
69
proto/user.proto
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package user;
|
||||||
|
|
||||||
|
option go_package = "go-microservices/proto/user;userpb";
|
||||||
|
|
||||||
|
import "google/protobuf/empty.proto";
|
||||||
|
|
||||||
|
service UserService {
|
||||||
|
rpc CreateUser (CreateUserRequest) returns (CreateUserResponse);
|
||||||
|
rpc GetUser (GetUserRequest) returns (GetUserResponse);
|
||||||
|
rpc UpdateUser (UpdateUserRequest) returns (UpdateUserResponse);
|
||||||
|
rpc DeleteUser (DeleteUserRequest) returns (google.protobuf.Empty);
|
||||||
|
rpc ListUsers (ListUsersRequest) returns (ListUsersResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
message User {
|
||||||
|
string id = 1;
|
||||||
|
string username = 2;
|
||||||
|
string email = 3;
|
||||||
|
string bio = 4;
|
||||||
|
string avatar_url = 5;
|
||||||
|
int64 created_at = 6;
|
||||||
|
int64 updated_at = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateUserRequest {
|
||||||
|
string username = 1;
|
||||||
|
string email = 2;
|
||||||
|
string bio = 3;
|
||||||
|
string avatar_url = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CreateUserResponse {
|
||||||
|
User user = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetUserRequest {
|
||||||
|
string id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GetUserResponse {
|
||||||
|
User user = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateUserRequest {
|
||||||
|
string id = 1;
|
||||||
|
string username = 2;
|
||||||
|
string email = 3;
|
||||||
|
string bio = 4;
|
||||||
|
string avatar_url = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message UpdateUserResponse {
|
||||||
|
User user = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message DeleteUserRequest {
|
||||||
|
string id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ListUsersRequest {
|
||||||
|
int32 page = 1;
|
||||||
|
int32 page_size = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ListUsersResponse {
|
||||||
|
repeated User users = 1;
|
||||||
|
}
|
||||||
726
proto/user/user.pb.go
Normal file
726
proto/user/user.pb.go
Normal file
@@ -0,0 +1,726 @@
|
|||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// File: user.proto
|
||||||
|
//
|
||||||
|
// This Protocol Buffers file defines the gRPC contract for the UserService.
|
||||||
|
// It includes service definitions for creating, retrieving, updating, deleting,
|
||||||
|
// and listing users. Each RPC method has corresponding request and response
|
||||||
|
// messages. The syntax follows proto3 conventions and uses message types for
|
||||||
|
// structured data exchange between microservices.
|
||||||
|
//
|
||||||
|
// Syntax:
|
||||||
|
// - Uses proto3 syntax for modern Protocol Buffers features.
|
||||||
|
// - Defines service and message types for CRUD operations.
|
||||||
|
// - Supports repeated fields for listing multiple users.
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
// - Enables strongly-typed, language-agnostic communication between services.
|
||||||
|
// - Provides a contract for backend and API Gateway integration.
|
||||||
|
// - Facilitates code generation for gRPC servers and clients.
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// protoc-gen-go v1.36.7
|
||||||
|
// protoc v6.31.1
|
||||||
|
// source: user.proto
|
||||||
|
|
||||||
|
package userpb
|
||||||
|
|
||||||
|
import (
|
||||||
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||||
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||||
|
emptypb "google.golang.org/protobuf/types/known/emptypb"
|
||||||
|
reflect "reflect"
|
||||||
|
sync "sync"
|
||||||
|
unsafe "unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Verify that this generated code is sufficiently up-to-date.
|
||||||
|
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||||
|
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||||
|
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||||
|
)
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
|
||||||
|
Email string `protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"`
|
||||||
|
Bio string `protobuf:"bytes,4,opt,name=bio,proto3" json:"bio,omitempty"`
|
||||||
|
AvatarUrl string `protobuf:"bytes,5,opt,name=avatar_url,json=avatarUrl,proto3" json:"avatar_url,omitempty"`
|
||||||
|
CreatedAt int64 `protobuf:"varint,6,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
|
||||||
|
UpdatedAt int64 `protobuf:"varint,7,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *User) Reset() {
|
||||||
|
*x = User{}
|
||||||
|
mi := &file_user_proto_msgTypes[0]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *User) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*User) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *User) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_proto_msgTypes[0]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use User.ProtoReflect.Descriptor instead.
|
||||||
|
func (*User) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_proto_rawDescGZIP(), []int{0}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *User) GetId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *User) GetUsername() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Username
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *User) GetEmail() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Email
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *User) GetBio() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Bio
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *User) GetAvatarUrl() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.AvatarUrl
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *User) GetCreatedAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.CreatedAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *User) GetUpdatedAt() int64 {
|
||||||
|
if x != nil {
|
||||||
|
return x.UpdatedAt
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateUserRequest struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
|
||||||
|
Email string `protobuf:"bytes,2,opt,name=email,proto3" json:"email,omitempty"`
|
||||||
|
Bio string `protobuf:"bytes,3,opt,name=bio,proto3" json:"bio,omitempty"`
|
||||||
|
AvatarUrl string `protobuf:"bytes,4,opt,name=avatar_url,json=avatarUrl,proto3" json:"avatar_url,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreateUserRequest) Reset() {
|
||||||
|
*x = CreateUserRequest{}
|
||||||
|
mi := &file_user_proto_msgTypes[1]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreateUserRequest) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*CreateUserRequest) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *CreateUserRequest) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_proto_msgTypes[1]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use CreateUserRequest.ProtoReflect.Descriptor instead.
|
||||||
|
func (*CreateUserRequest) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_proto_rawDescGZIP(), []int{1}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreateUserRequest) GetUsername() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Username
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreateUserRequest) GetEmail() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Email
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreateUserRequest) GetBio() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Bio
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreateUserRequest) GetAvatarUrl() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.AvatarUrl
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateUserResponse struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreateUserResponse) Reset() {
|
||||||
|
*x = CreateUserResponse{}
|
||||||
|
mi := &file_user_proto_msgTypes[2]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreateUserResponse) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*CreateUserResponse) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *CreateUserResponse) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_proto_msgTypes[2]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use CreateUserResponse.ProtoReflect.Descriptor instead.
|
||||||
|
func (*CreateUserResponse) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_proto_rawDescGZIP(), []int{2}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *CreateUserResponse) GetUser() *User {
|
||||||
|
if x != nil {
|
||||||
|
return x.User
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetUserRequest struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetUserRequest) Reset() {
|
||||||
|
*x = GetUserRequest{}
|
||||||
|
mi := &file_user_proto_msgTypes[3]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetUserRequest) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*GetUserRequest) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *GetUserRequest) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_proto_msgTypes[3]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use GetUserRequest.ProtoReflect.Descriptor instead.
|
||||||
|
func (*GetUserRequest) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_proto_rawDescGZIP(), []int{3}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetUserRequest) GetId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetUserResponse struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetUserResponse) Reset() {
|
||||||
|
*x = GetUserResponse{}
|
||||||
|
mi := &file_user_proto_msgTypes[4]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetUserResponse) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*GetUserResponse) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *GetUserResponse) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_proto_msgTypes[4]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use GetUserResponse.ProtoReflect.Descriptor instead.
|
||||||
|
func (*GetUserResponse) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_proto_rawDescGZIP(), []int{4}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *GetUserResponse) GetUser() *User {
|
||||||
|
if x != nil {
|
||||||
|
return x.User
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateUserRequest struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
Username string `protobuf:"bytes,2,opt,name=username,proto3" json:"username,omitempty"`
|
||||||
|
Email string `protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"`
|
||||||
|
Bio string `protobuf:"bytes,4,opt,name=bio,proto3" json:"bio,omitempty"`
|
||||||
|
AvatarUrl string `protobuf:"bytes,5,opt,name=avatar_url,json=avatarUrl,proto3" json:"avatar_url,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateUserRequest) Reset() {
|
||||||
|
*x = UpdateUserRequest{}
|
||||||
|
mi := &file_user_proto_msgTypes[5]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateUserRequest) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*UpdateUserRequest) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *UpdateUserRequest) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_proto_msgTypes[5]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use UpdateUserRequest.ProtoReflect.Descriptor instead.
|
||||||
|
func (*UpdateUserRequest) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_proto_rawDescGZIP(), []int{5}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateUserRequest) GetId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateUserRequest) GetUsername() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Username
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateUserRequest) GetEmail() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Email
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateUserRequest) GetBio() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Bio
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateUserRequest) GetAvatarUrl() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.AvatarUrl
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type UpdateUserResponse struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
User *User `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateUserResponse) Reset() {
|
||||||
|
*x = UpdateUserResponse{}
|
||||||
|
mi := &file_user_proto_msgTypes[6]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateUserResponse) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*UpdateUserResponse) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *UpdateUserResponse) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_proto_msgTypes[6]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use UpdateUserResponse.ProtoReflect.Descriptor instead.
|
||||||
|
func (*UpdateUserResponse) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_proto_rawDescGZIP(), []int{6}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpdateUserResponse) GetUser() *User {
|
||||||
|
if x != nil {
|
||||||
|
return x.User
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteUserRequest struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DeleteUserRequest) Reset() {
|
||||||
|
*x = DeleteUserRequest{}
|
||||||
|
mi := &file_user_proto_msgTypes[7]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DeleteUserRequest) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*DeleteUserRequest) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *DeleteUserRequest) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_proto_msgTypes[7]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use DeleteUserRequest.ProtoReflect.Descriptor instead.
|
||||||
|
func (*DeleteUserRequest) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_proto_rawDescGZIP(), []int{7}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *DeleteUserRequest) GetId() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.Id
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListUsersRequest struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Page int32 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"`
|
||||||
|
PageSize int32 `protobuf:"varint,2,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListUsersRequest) Reset() {
|
||||||
|
*x = ListUsersRequest{}
|
||||||
|
mi := &file_user_proto_msgTypes[8]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListUsersRequest) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ListUsersRequest) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *ListUsersRequest) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_proto_msgTypes[8]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use ListUsersRequest.ProtoReflect.Descriptor instead.
|
||||||
|
func (*ListUsersRequest) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_proto_rawDescGZIP(), []int{8}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListUsersRequest) GetPage() int32 {
|
||||||
|
if x != nil {
|
||||||
|
return x.Page
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListUsersRequest) GetPageSize() int32 {
|
||||||
|
if x != nil {
|
||||||
|
return x.PageSize
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type ListUsersResponse struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Users []*User `protobuf:"bytes,1,rep,name=users,proto3" json:"users,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListUsersResponse) Reset() {
|
||||||
|
*x = ListUsersResponse{}
|
||||||
|
mi := &file_user_proto_msgTypes[9]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListUsersResponse) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*ListUsersResponse) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *ListUsersResponse) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_user_proto_msgTypes[9]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use ListUsersResponse.ProtoReflect.Descriptor instead.
|
||||||
|
func (*ListUsersResponse) Descriptor() ([]byte, []int) {
|
||||||
|
return file_user_proto_rawDescGZIP(), []int{9}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *ListUsersResponse) GetUsers() []*User {
|
||||||
|
if x != nil {
|
||||||
|
return x.Users
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var File_user_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
|
const file_user_proto_rawDesc = "" +
|
||||||
|
"\n" +
|
||||||
|
"\n" +
|
||||||
|
"user.proto\x12\x04user\x1a\x1bgoogle/protobuf/empty.proto\"\xb7\x01\n" +
|
||||||
|
"\x04User\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\tR\x02id\x12\x1a\n" +
|
||||||
|
"\busername\x18\x02 \x01(\tR\busername\x12\x14\n" +
|
||||||
|
"\x05email\x18\x03 \x01(\tR\x05email\x12\x10\n" +
|
||||||
|
"\x03bio\x18\x04 \x01(\tR\x03bio\x12\x1d\n" +
|
||||||
|
"\n" +
|
||||||
|
"avatar_url\x18\x05 \x01(\tR\tavatarUrl\x12\x1d\n" +
|
||||||
|
"\n" +
|
||||||
|
"created_at\x18\x06 \x01(\x03R\tcreatedAt\x12\x1d\n" +
|
||||||
|
"\n" +
|
||||||
|
"updated_at\x18\a \x01(\x03R\tupdatedAt\"v\n" +
|
||||||
|
"\x11CreateUserRequest\x12\x1a\n" +
|
||||||
|
"\busername\x18\x01 \x01(\tR\busername\x12\x14\n" +
|
||||||
|
"\x05email\x18\x02 \x01(\tR\x05email\x12\x10\n" +
|
||||||
|
"\x03bio\x18\x03 \x01(\tR\x03bio\x12\x1d\n" +
|
||||||
|
"\n" +
|
||||||
|
"avatar_url\x18\x04 \x01(\tR\tavatarUrl\"4\n" +
|
||||||
|
"\x12CreateUserResponse\x12\x1e\n" +
|
||||||
|
"\x04user\x18\x01 \x01(\v2\n" +
|
||||||
|
".user.UserR\x04user\" \n" +
|
||||||
|
"\x0eGetUserRequest\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\tR\x02id\"1\n" +
|
||||||
|
"\x0fGetUserResponse\x12\x1e\n" +
|
||||||
|
"\x04user\x18\x01 \x01(\v2\n" +
|
||||||
|
".user.UserR\x04user\"\x86\x01\n" +
|
||||||
|
"\x11UpdateUserRequest\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\tR\x02id\x12\x1a\n" +
|
||||||
|
"\busername\x18\x02 \x01(\tR\busername\x12\x14\n" +
|
||||||
|
"\x05email\x18\x03 \x01(\tR\x05email\x12\x10\n" +
|
||||||
|
"\x03bio\x18\x04 \x01(\tR\x03bio\x12\x1d\n" +
|
||||||
|
"\n" +
|
||||||
|
"avatar_url\x18\x05 \x01(\tR\tavatarUrl\"4\n" +
|
||||||
|
"\x12UpdateUserResponse\x12\x1e\n" +
|
||||||
|
"\x04user\x18\x01 \x01(\v2\n" +
|
||||||
|
".user.UserR\x04user\"#\n" +
|
||||||
|
"\x11DeleteUserRequest\x12\x0e\n" +
|
||||||
|
"\x02id\x18\x01 \x01(\tR\x02id\"C\n" +
|
||||||
|
"\x10ListUsersRequest\x12\x12\n" +
|
||||||
|
"\x04page\x18\x01 \x01(\x05R\x04page\x12\x1b\n" +
|
||||||
|
"\tpage_size\x18\x02 \x01(\x05R\bpageSize\"5\n" +
|
||||||
|
"\x11ListUsersResponse\x12 \n" +
|
||||||
|
"\x05users\x18\x01 \x03(\v2\n" +
|
||||||
|
".user.UserR\x05users2\xc4\x02\n" +
|
||||||
|
"\vUserService\x12?\n" +
|
||||||
|
"\n" +
|
||||||
|
"CreateUser\x12\x17.user.CreateUserRequest\x1a\x18.user.CreateUserResponse\x126\n" +
|
||||||
|
"\aGetUser\x12\x14.user.GetUserRequest\x1a\x15.user.GetUserResponse\x12?\n" +
|
||||||
|
"\n" +
|
||||||
|
"UpdateUser\x12\x17.user.UpdateUserRequest\x1a\x18.user.UpdateUserResponse\x12=\n" +
|
||||||
|
"\n" +
|
||||||
|
"DeleteUser\x12\x17.user.DeleteUserRequest\x1a\x16.google.protobuf.Empty\x12<\n" +
|
||||||
|
"\tListUsers\x12\x16.user.ListUsersRequest\x1a\x17.user.ListUsersResponseB\x0eZ\f/user;userpbb\x06proto3"
|
||||||
|
|
||||||
|
var (
|
||||||
|
file_user_proto_rawDescOnce sync.Once
|
||||||
|
file_user_proto_rawDescData []byte
|
||||||
|
)
|
||||||
|
|
||||||
|
func file_user_proto_rawDescGZIP() []byte {
|
||||||
|
file_user_proto_rawDescOnce.Do(func() {
|
||||||
|
file_user_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_user_proto_rawDesc), len(file_user_proto_rawDesc)))
|
||||||
|
})
|
||||||
|
return file_user_proto_rawDescData
|
||||||
|
}
|
||||||
|
|
||||||
|
var file_user_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
|
||||||
|
var file_user_proto_goTypes = []any{
|
||||||
|
(*User)(nil), // 0: user.User
|
||||||
|
(*CreateUserRequest)(nil), // 1: user.CreateUserRequest
|
||||||
|
(*CreateUserResponse)(nil), // 2: user.CreateUserResponse
|
||||||
|
(*GetUserRequest)(nil), // 3: user.GetUserRequest
|
||||||
|
(*GetUserResponse)(nil), // 4: user.GetUserResponse
|
||||||
|
(*UpdateUserRequest)(nil), // 5: user.UpdateUserRequest
|
||||||
|
(*UpdateUserResponse)(nil), // 6: user.UpdateUserResponse
|
||||||
|
(*DeleteUserRequest)(nil), // 7: user.DeleteUserRequest
|
||||||
|
(*ListUsersRequest)(nil), // 8: user.ListUsersRequest
|
||||||
|
(*ListUsersResponse)(nil), // 9: user.ListUsersResponse
|
||||||
|
(*emptypb.Empty)(nil), // 10: google.protobuf.Empty
|
||||||
|
}
|
||||||
|
var file_user_proto_depIdxs = []int32{
|
||||||
|
0, // 0: user.CreateUserResponse.user:type_name -> user.User
|
||||||
|
0, // 1: user.GetUserResponse.user:type_name -> user.User
|
||||||
|
0, // 2: user.UpdateUserResponse.user:type_name -> user.User
|
||||||
|
0, // 3: user.ListUsersResponse.users:type_name -> user.User
|
||||||
|
1, // 4: user.UserService.CreateUser:input_type -> user.CreateUserRequest
|
||||||
|
3, // 5: user.UserService.GetUser:input_type -> user.GetUserRequest
|
||||||
|
5, // 6: user.UserService.UpdateUser:input_type -> user.UpdateUserRequest
|
||||||
|
7, // 7: user.UserService.DeleteUser:input_type -> user.DeleteUserRequest
|
||||||
|
8, // 8: user.UserService.ListUsers:input_type -> user.ListUsersRequest
|
||||||
|
2, // 9: user.UserService.CreateUser:output_type -> user.CreateUserResponse
|
||||||
|
4, // 10: user.UserService.GetUser:output_type -> user.GetUserResponse
|
||||||
|
6, // 11: user.UserService.UpdateUser:output_type -> user.UpdateUserResponse
|
||||||
|
10, // 12: user.UserService.DeleteUser:output_type -> google.protobuf.Empty
|
||||||
|
9, // 13: user.UserService.ListUsers:output_type -> user.ListUsersResponse
|
||||||
|
9, // [9:14] is the sub-list for method output_type
|
||||||
|
4, // [4:9] is the sub-list for method input_type
|
||||||
|
4, // [4:4] is the sub-list for extension type_name
|
||||||
|
4, // [4:4] is the sub-list for extension extendee
|
||||||
|
0, // [0:4] is the sub-list for field type_name
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { file_user_proto_init() }
|
||||||
|
func file_user_proto_init() {
|
||||||
|
if File_user_proto != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
type x struct{}
|
||||||
|
out := protoimpl.TypeBuilder{
|
||||||
|
File: protoimpl.DescBuilder{
|
||||||
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
|
RawDescriptor: unsafe.Slice(unsafe.StringData(file_user_proto_rawDesc), len(file_user_proto_rawDesc)),
|
||||||
|
NumEnums: 0,
|
||||||
|
NumMessages: 10,
|
||||||
|
NumExtensions: 0,
|
||||||
|
NumServices: 1,
|
||||||
|
},
|
||||||
|
GoTypes: file_user_proto_goTypes,
|
||||||
|
DependencyIndexes: file_user_proto_depIdxs,
|
||||||
|
MessageInfos: file_user_proto_msgTypes,
|
||||||
|
}.Build()
|
||||||
|
File_user_proto = out.File
|
||||||
|
file_user_proto_goTypes = nil
|
||||||
|
file_user_proto_depIdxs = nil
|
||||||
|
}
|
||||||
294
proto/user/user_grpc.pb.go
Normal file
294
proto/user/user_grpc.pb.go
Normal file
@@ -0,0 +1,294 @@
|
|||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// File: user.proto
|
||||||
|
//
|
||||||
|
// This Protocol Buffers file defines the gRPC contract for the UserService.
|
||||||
|
// It includes service definitions for creating, retrieving, updating, deleting,
|
||||||
|
// and listing users. Each RPC method has corresponding request and response
|
||||||
|
// messages. The syntax follows proto3 conventions and uses message types for
|
||||||
|
// structured data exchange between microservices.
|
||||||
|
//
|
||||||
|
// Syntax:
|
||||||
|
// - Uses proto3 syntax for modern Protocol Buffers features.
|
||||||
|
// - Defines service and message types for CRUD operations.
|
||||||
|
// - Supports repeated fields for listing multiple users.
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
// - Enables strongly-typed, language-agnostic communication between services.
|
||||||
|
// - Provides a contract for backend and API Gateway integration.
|
||||||
|
// - Facilitates code generation for gRPC servers and clients.
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// - protoc-gen-go-grpc v1.5.1
|
||||||
|
// - protoc v6.31.1
|
||||||
|
// source: user.proto
|
||||||
|
|
||||||
|
package userpb
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
codes "google.golang.org/grpc/codes"
|
||||||
|
status "google.golang.org/grpc/status"
|
||||||
|
emptypb "google.golang.org/protobuf/types/known/emptypb"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
// Requires gRPC-Go v1.64.0 or later.
|
||||||
|
const _ = grpc.SupportPackageIsVersion9
|
||||||
|
|
||||||
|
const (
|
||||||
|
UserService_CreateUser_FullMethodName = "/user.UserService/CreateUser"
|
||||||
|
UserService_GetUser_FullMethodName = "/user.UserService/GetUser"
|
||||||
|
UserService_UpdateUser_FullMethodName = "/user.UserService/UpdateUser"
|
||||||
|
UserService_DeleteUser_FullMethodName = "/user.UserService/DeleteUser"
|
||||||
|
UserService_ListUsers_FullMethodName = "/user.UserService/ListUsers"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserServiceClient is the client API for UserService service.
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
type UserServiceClient interface {
|
||||||
|
CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*CreateUserResponse, error)
|
||||||
|
GetUser(ctx context.Context, in *GetUserRequest, opts ...grpc.CallOption) (*GetUserResponse, error)
|
||||||
|
UpdateUser(ctx context.Context, in *UpdateUserRequest, opts ...grpc.CallOption) (*UpdateUserResponse, error)
|
||||||
|
DeleteUser(ctx context.Context, in *DeleteUserRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
|
||||||
|
ListUsers(ctx context.Context, in *ListUsersRequest, opts ...grpc.CallOption) (*ListUsersResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type userServiceClient struct {
|
||||||
|
cc grpc.ClientConnInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUserServiceClient(cc grpc.ClientConnInterface) UserServiceClient {
|
||||||
|
return &userServiceClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *userServiceClient) CreateUser(ctx context.Context, in *CreateUserRequest, opts ...grpc.CallOption) (*CreateUserResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(CreateUserResponse)
|
||||||
|
err := c.cc.Invoke(ctx, UserService_CreateUser_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *userServiceClient) GetUser(ctx context.Context, in *GetUserRequest, opts ...grpc.CallOption) (*GetUserResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(GetUserResponse)
|
||||||
|
err := c.cc.Invoke(ctx, UserService_GetUser_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *userServiceClient) UpdateUser(ctx context.Context, in *UpdateUserRequest, opts ...grpc.CallOption) (*UpdateUserResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(UpdateUserResponse)
|
||||||
|
err := c.cc.Invoke(ctx, UserService_UpdateUser_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *userServiceClient) DeleteUser(ctx context.Context, in *DeleteUserRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(emptypb.Empty)
|
||||||
|
err := c.cc.Invoke(ctx, UserService_DeleteUser_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *userServiceClient) ListUsers(ctx context.Context, in *ListUsersRequest, opts ...grpc.CallOption) (*ListUsersResponse, error) {
|
||||||
|
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||||
|
out := new(ListUsersResponse)
|
||||||
|
err := c.cc.Invoke(ctx, UserService_ListUsers_FullMethodName, in, out, cOpts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserServiceServer is the server API for UserService service.
|
||||||
|
// All implementations must embed UnimplementedUserServiceServer
|
||||||
|
// for forward compatibility.
|
||||||
|
type UserServiceServer interface {
|
||||||
|
CreateUser(context.Context, *CreateUserRequest) (*CreateUserResponse, error)
|
||||||
|
GetUser(context.Context, *GetUserRequest) (*GetUserResponse, error)
|
||||||
|
UpdateUser(context.Context, *UpdateUserRequest) (*UpdateUserResponse, error)
|
||||||
|
DeleteUser(context.Context, *DeleteUserRequest) (*emptypb.Empty, error)
|
||||||
|
ListUsers(context.Context, *ListUsersRequest) (*ListUsersResponse, error)
|
||||||
|
mustEmbedUnimplementedUserServiceServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnimplementedUserServiceServer must be embedded to have
|
||||||
|
// forward compatible implementations.
|
||||||
|
//
|
||||||
|
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||||
|
// pointer dereference when methods are called.
|
||||||
|
type UnimplementedUserServiceServer struct{}
|
||||||
|
|
||||||
|
func (UnimplementedUserServiceServer) CreateUser(context.Context, *CreateUserRequest) (*CreateUserResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method CreateUser not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedUserServiceServer) GetUser(context.Context, *GetUserRequest) (*GetUserResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method GetUser not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedUserServiceServer) UpdateUser(context.Context, *UpdateUserRequest) (*UpdateUserResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method UpdateUser not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedUserServiceServer) DeleteUser(context.Context, *DeleteUserRequest) (*emptypb.Empty, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method DeleteUser not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedUserServiceServer) ListUsers(context.Context, *ListUsersRequest) (*ListUsersResponse, error) {
|
||||||
|
return nil, status.Errorf(codes.Unimplemented, "method ListUsers not implemented")
|
||||||
|
}
|
||||||
|
func (UnimplementedUserServiceServer) mustEmbedUnimplementedUserServiceServer() {}
|
||||||
|
func (UnimplementedUserServiceServer) testEmbeddedByValue() {}
|
||||||
|
|
||||||
|
// UnsafeUserServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||||
|
// Use of this interface is not recommended, as added methods to UserServiceServer will
|
||||||
|
// result in compilation errors.
|
||||||
|
type UnsafeUserServiceServer interface {
|
||||||
|
mustEmbedUnimplementedUserServiceServer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterUserServiceServer(s grpc.ServiceRegistrar, srv UserServiceServer) {
|
||||||
|
// If the following call pancis, it indicates UnimplementedUserServiceServer was
|
||||||
|
// embedded by pointer and is nil. This will cause panics if an
|
||||||
|
// unimplemented method is ever invoked, so we test this at initialization
|
||||||
|
// time to prevent it from happening at runtime later due to I/O.
|
||||||
|
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||||
|
t.testEmbeddedByValue()
|
||||||
|
}
|
||||||
|
s.RegisterService(&UserService_ServiceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _UserService_CreateUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(CreateUserRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(UserServiceServer).CreateUser(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: UserService_CreateUser_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(UserServiceServer).CreateUser(ctx, req.(*CreateUserRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _UserService_GetUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(GetUserRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(UserServiceServer).GetUser(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: UserService_GetUser_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(UserServiceServer).GetUser(ctx, req.(*GetUserRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _UserService_UpdateUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(UpdateUserRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(UserServiceServer).UpdateUser(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: UserService_UpdateUser_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(UserServiceServer).UpdateUser(ctx, req.(*UpdateUserRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _UserService_DeleteUser_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(DeleteUserRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(UserServiceServer).DeleteUser(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: UserService_DeleteUser_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(UserServiceServer).DeleteUser(ctx, req.(*DeleteUserRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _UserService_ListUsers_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||||
|
in := new(ListUsersRequest)
|
||||||
|
if err := dec(in); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if interceptor == nil {
|
||||||
|
return srv.(UserServiceServer).ListUsers(ctx, in)
|
||||||
|
}
|
||||||
|
info := &grpc.UnaryServerInfo{
|
||||||
|
Server: srv,
|
||||||
|
FullMethod: UserService_ListUsers_FullMethodName,
|
||||||
|
}
|
||||||
|
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||||
|
return srv.(UserServiceServer).ListUsers(ctx, req.(*ListUsersRequest))
|
||||||
|
}
|
||||||
|
return interceptor(ctx, in, info, handler)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserService_ServiceDesc is the grpc.ServiceDesc for UserService service.
|
||||||
|
// It's only intended for direct use with grpc.RegisterService,
|
||||||
|
// and not to be introspected or modified (even as a copy)
|
||||||
|
var UserService_ServiceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "user.UserService",
|
||||||
|
HandlerType: (*UserServiceServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{
|
||||||
|
{
|
||||||
|
MethodName: "CreateUser",
|
||||||
|
Handler: _UserService_CreateUser_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "GetUser",
|
||||||
|
Handler: _UserService_GetUser_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "UpdateUser",
|
||||||
|
Handler: _UserService_UpdateUser_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "DeleteUser",
|
||||||
|
Handler: _UserService_DeleteUser_Handler,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
MethodName: "ListUsers",
|
||||||
|
Handler: _UserService_ListUsers_Handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Streams: []grpc.StreamDesc{},
|
||||||
|
Metadata: "user.proto",
|
||||||
|
}
|
||||||
33
services/auth-service/Dockerfile
Normal file
33
services/auth-service/Dockerfile
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
FROM golang:1.24-alpine AS build
|
||||||
|
RUN apk add --no-cache git ca-certificates protobuf-dev
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# use repo-level go.mod so modules are resolvable (build.context must be repo root)
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# install Go protoc plugins
|
||||||
|
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && \
|
||||||
|
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
|
||||||
|
|
||||||
|
# copy service sources and proto files into the image
|
||||||
|
COPY services/auth-service ./services/auth-service
|
||||||
|
COPY proto ./proto
|
||||||
|
|
||||||
|
# generate proto files
|
||||||
|
RUN mkdir -p proto/auth proto/user proto/post && \
|
||||||
|
export PATH=/go/bin:$PATH && \
|
||||||
|
protoc --go_out=proto --go_opt=paths=source_relative \
|
||||||
|
--go-grpc_out=proto --go-grpc_opt=paths=source_relative \
|
||||||
|
--proto_path=proto \
|
||||||
|
proto/auth.proto proto/user.proto proto/post.proto && \
|
||||||
|
ls -la proto/auth/ proto/user/ proto/post/
|
||||||
|
|
||||||
|
# build a static binary for the auth service
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /usr/local/bin/auth-service ./services/auth-service/cmd
|
||||||
|
|
||||||
|
FROM alpine:3.20
|
||||||
|
RUN apk add --no-cache ca-certificates
|
||||||
|
COPY --from=build /usr/local/bin/auth-service /usr/local/bin/auth-service
|
||||||
|
EXPOSE 50051
|
||||||
|
ENTRYPOINT ["/usr/local/bin/auth-service"]
|
||||||
43
services/auth-service/cmd/main.go
Normal file
43
services/auth-service/cmd/main.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
pb "go-microservices/proto/auth"
|
||||||
|
|
||||||
|
"go-microservices/services/auth-service/internal/database"
|
||||||
|
"go-microservices/services/auth-service/internal/repository"
|
||||||
|
"go-microservices/services/auth-service/internal/server"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("Starting Auth Service...")
|
||||||
|
port := os.Getenv("PORT")
|
||||||
|
if port == "" {
|
||||||
|
port = "50051"
|
||||||
|
}
|
||||||
|
lis, err := net.Listen("tcp", ":"+port)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to listen: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := database.Init()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to init database: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
repo := repository.NewRepository(db)
|
||||||
|
srv := server.NewAuthServer(repo)
|
||||||
|
|
||||||
|
grpcServer := grpc.NewServer()
|
||||||
|
pb.RegisterAuthServiceServer(grpcServer, srv)
|
||||||
|
log.Printf("Auth Service listening on %s", port)
|
||||||
|
if err := grpcServer.Serve(lis); err != nil {
|
||||||
|
log.Fatalf("Failed to serve: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
1
services/auth-service/config/config.yml
Normal file
1
services/auth-service/config/config.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
This is the configuration file for the Auth Service microservice.
|
||||||
22
services/auth-service/config/env.go
Normal file
22
services/auth-service/config/env.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Env struct {
|
||||||
|
Port int
|
||||||
|
JWTSecret string
|
||||||
|
TokenDuration int
|
||||||
|
DatabaseURL string
|
||||||
|
RedisAddr string
|
||||||
|
RedisPassword string
|
||||||
|
RedisDB int
|
||||||
|
EmailHost string
|
||||||
|
EmailPort int
|
||||||
|
EmailUsername string
|
||||||
|
EmailPassword string
|
||||||
|
EmailFrom string
|
||||||
|
FrontendURL string
|
||||||
|
}
|
||||||
28
services/auth-service/internal/database/database.go
Normal file
28
services/auth-service/internal/database/database.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go-microservices/services/auth-service/internal/models"
|
||||||
|
|
||||||
|
"gorm.io/driver/postgres"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Init() (*gorm.DB, error) {
|
||||||
|
dsn := os.Getenv("DATABASE_URL")
|
||||||
|
if dsn == "" {
|
||||||
|
dsn = "host=localhost user=postgres password=postgres dbname=postgres port=5432 sslmode=disable TimeZone=UTC"
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := db.AutoMigrate(&models.Auth{}, &models.Test{}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return db, nil
|
||||||
|
}
|
||||||
23
services/auth-service/internal/models/models.go
Normal file
23
services/auth-service/internal/models/models.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Auth struct {
|
||||||
|
gorm.Model
|
||||||
|
Username string `gorm:"uniqueIndex;not null"`
|
||||||
|
Email string `gorm:"uniqueIndex;not null"`
|
||||||
|
Password string `gorm:"not null"`
|
||||||
|
VerificationToken string `json:"-"`
|
||||||
|
ResetToken string `json:"-"`
|
||||||
|
ResetTokenExpiry time.Time `json:"-"`
|
||||||
|
Role string `gorm:"type:varchar(50);default:user" json:"role,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Test struct {
|
||||||
|
gorm.Model
|
||||||
|
Content string `gorm:"type:text;not null"`
|
||||||
|
}
|
||||||
63
services/auth-service/internal/repository/repository.go
Normal file
63
services/auth-service/internal/repository/repository.go
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go-microservices/services/auth-service/internal/models"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Repository struct {
|
||||||
|
DB *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRepository(db *gorm.DB) *Repository {
|
||||||
|
return &Repository{DB: db}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Repository) CreateAuth(a *models.Auth) error {
|
||||||
|
return r.DB.Create(a).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Repository) GetAuthByEmail(email string) (*models.Auth, error) {
|
||||||
|
var a models.Auth
|
||||||
|
if err := r.DB.Where("email = ?", email).First(&a).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Repository) GetAuthByID(id uint) (*models.Auth, error) {
|
||||||
|
var a models.Auth
|
||||||
|
if err := r.DB.First(&a, id).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Repository) CreateTest(t *models.Test) error {
|
||||||
|
return r.DB.Create(t).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Repository) ListTests() ([]models.Test, error) {
|
||||||
|
var tests []models.Test
|
||||||
|
if err := r.DB.Order("id desc").Find(&tests).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return tests, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Repository) GetTestByID(id uint) (*models.Test, error) {
|
||||||
|
var t models.Test
|
||||||
|
if err := r.DB.First(&t, id).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &t, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Repository) UpdateTest(t *models.Test) error {
|
||||||
|
return r.DB.Save(t).Error
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Repository) DeleteTest(id uint) error {
|
||||||
|
return r.DB.Delete(&models.Test{}, id).Error
|
||||||
|
}
|
||||||
210
services/auth-service/internal/server/server.go
Normal file
210
services/auth-service/internal/server/server.go
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
pb "go-microservices/proto/auth"
|
||||||
|
"go-microservices/services/auth-service/internal/models"
|
||||||
|
"go-microservices/services/auth-service/internal/repository"
|
||||||
|
"go-microservices/services/auth-service/internal/utils"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AuthServer struct {
|
||||||
|
pb.UnimplementedAuthServiceServer
|
||||||
|
repo *repository.Repository
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAuthServer(repo *repository.Repository) *AuthServer {
|
||||||
|
return &AuthServer{repo: repo}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AuthServer) SignUp(ctx context.Context, req *pb.SignUpRequest) (*pb.SignUpResponse, error) {
|
||||||
|
hashed, err := bcrypt.GenerateFromPassword([]byte(req.Password), bcrypt.DefaultCost)
|
||||||
|
if err != nil {
|
||||||
|
return nil, status.Errorf(codes.Internal, "failed to hash password: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
auth := &models.Auth{
|
||||||
|
Username: req.Username,
|
||||||
|
Email: req.Email,
|
||||||
|
Password: string(hashed),
|
||||||
|
Role: "user", // default role (proto SignUpRequest doesn't include role)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := s.repo.CreateAuth(auth); err != nil {
|
||||||
|
return nil, status.Errorf(codes.Internal, "failed to create user: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
userID := fmt.Sprintf("%d", auth.ID)
|
||||||
|
return &pb.SignUpResponse{UserId: userID, Message: "registered"}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AuthServer) SignIn(ctx context.Context, req *pb.SignInRequest) (*pb.SignInResponse, error) {
|
||||||
|
auth, err := s.repo.GetAuthByEmail(req.Email)
|
||||||
|
if err != nil || auth == nil {
|
||||||
|
return nil, status.Errorf(codes.Unauthenticated, "invalid credentials")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := bcrypt.CompareHashAndPassword([]byte(auth.Password), []byte(req.Password)); err != nil {
|
||||||
|
return nil, status.Errorf(codes.Unauthenticated, "invalid credentials")
|
||||||
|
}
|
||||||
|
|
||||||
|
accessToken, refreshToken, err := utils.GenerateJWT(*auth)
|
||||||
|
if err != nil {
|
||||||
|
return nil, status.Errorf(codes.Internal, "failed to generate tokens: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
userID := fmt.Sprintf("%d", auth.ID)
|
||||||
|
return &pb.SignInResponse{
|
||||||
|
AccessToken: accessToken,
|
||||||
|
RefreshToken: refreshToken,
|
||||||
|
UserId: userID,
|
||||||
|
Message: "logged in",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AuthServer) ValidateToken(ctx context.Context, req *pb.ValidateTokenRequest) (*pb.ValidateTokenResponse, error) {
|
||||||
|
claims, err := utils.ValidateJWT(req.Token, false)
|
||||||
|
if err != nil {
|
||||||
|
return &pb.ValidateTokenResponse{Valid: false, UserId: "", Message: "invalid token"}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var userID string
|
||||||
|
if sub, ok := claims["sub"]; ok {
|
||||||
|
switch v := sub.(type) {
|
||||||
|
case string:
|
||||||
|
userID = v
|
||||||
|
case float64:
|
||||||
|
userID = strconv.FormatFloat(v, 'f', 0, 64)
|
||||||
|
default:
|
||||||
|
userID = fmt.Sprintf("%v", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if userID == "" {
|
||||||
|
return &pb.ValidateTokenResponse{Valid: false, UserId: "", Message: "invalid token"}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.ValidateTokenResponse{Valid: true, UserId: userID, Message: "valid"}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AuthServer) GetUserInfo(ctx context.Context, req *pb.GetUserInfoRequest) (*pb.GetUserInfoResponse, error) {
|
||||||
|
// expect req.UserId (proto field user_id)
|
||||||
|
if req.UserId == "" {
|
||||||
|
return nil, status.Errorf(codes.InvalidArgument, "user id required")
|
||||||
|
}
|
||||||
|
u64, err := strconv.ParseUint(req.UserId, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, status.Errorf(codes.InvalidArgument, "invalid user id: %v", err)
|
||||||
|
}
|
||||||
|
user, err := s.repo.GetAuthByID(uint(u64))
|
||||||
|
if err != nil || user == nil {
|
||||||
|
return nil, status.Errorf(codes.NotFound, "user not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &pb.GetUserInfoResponse{
|
||||||
|
UserId: fmt.Sprintf("%d", user.ID),
|
||||||
|
Username: user.Username,
|
||||||
|
Email: user.Email,
|
||||||
|
Roles: []string{user.Role},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateTest creates a simple Test record in the database
|
||||||
|
func (s *AuthServer) CreateTest(ctx context.Context, req *pb.CreateTestRequest) (*pb.CreateTestResponse, error) {
|
||||||
|
if req.Content == "" {
|
||||||
|
return nil, status.Errorf(codes.InvalidArgument, "content required")
|
||||||
|
}
|
||||||
|
t := &models.Test{Content: req.Content}
|
||||||
|
if err := s.repo.CreateTest(t); err != nil {
|
||||||
|
return nil, status.Errorf(codes.Internal, "failed to create test: %v", err)
|
||||||
|
}
|
||||||
|
return &pb.CreateTestResponse{
|
||||||
|
Test: &pb.Test{
|
||||||
|
Id: uint64(t.ID),
|
||||||
|
Content: t.Content,
|
||||||
|
CreatedAt: t.CreatedAt.Format(time.RFC3339),
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListTests returns recent test records
|
||||||
|
func (s *AuthServer) ListTests(ctx context.Context, req *pb.ListTestsRequest) (*pb.ListTestsResponse, error) {
|
||||||
|
tests, err := s.repo.ListTests()
|
||||||
|
if err != nil {
|
||||||
|
return nil, status.Errorf(codes.Internal, "failed to list tests: %v", err)
|
||||||
|
}
|
||||||
|
resp := &pb.ListTestsResponse{Tests: make([]*pb.Test, 0, len(tests))}
|
||||||
|
for _, t := range tests {
|
||||||
|
resp.Tests = append(resp.Tests, &pb.Test{
|
||||||
|
Id: uint64(t.ID),
|
||||||
|
Content: t.Content,
|
||||||
|
CreatedAt: t.CreatedAt.Format(time.RFC3339),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTest retrieves a single test by ID
|
||||||
|
func (s *AuthServer) GetTest(ctx context.Context, req *pb.GetTestRequest) (*pb.GetTestResponse, error) {
|
||||||
|
if req.Id == 0 {
|
||||||
|
return nil, status.Errorf(codes.InvalidArgument, "test id required")
|
||||||
|
}
|
||||||
|
t, err := s.repo.GetTestByID(uint(req.Id))
|
||||||
|
if err != nil || t == nil {
|
||||||
|
return nil, status.Errorf(codes.NotFound, "test not found")
|
||||||
|
}
|
||||||
|
return &pb.GetTestResponse{
|
||||||
|
Test: &pb.Test{
|
||||||
|
Id: uint64(t.ID),
|
||||||
|
Content: t.Content,
|
||||||
|
CreatedAt: t.CreatedAt.Format(time.RFC3339),
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateTest updates an existing test
|
||||||
|
func (s *AuthServer) UpdateTest(ctx context.Context, req *pb.UpdateTestRequest) (*pb.UpdateTestResponse, error) {
|
||||||
|
if req.Id == 0 {
|
||||||
|
return nil, status.Errorf(codes.InvalidArgument, "test id required")
|
||||||
|
}
|
||||||
|
if req.Content == "" {
|
||||||
|
return nil, status.Errorf(codes.InvalidArgument, "content required")
|
||||||
|
}
|
||||||
|
t, err := s.repo.GetTestByID(uint(req.Id))
|
||||||
|
if err != nil || t == nil {
|
||||||
|
return nil, status.Errorf(codes.NotFound, "test not found")
|
||||||
|
}
|
||||||
|
t.Content = req.Content
|
||||||
|
if err := s.repo.UpdateTest(t); err != nil {
|
||||||
|
return nil, status.Errorf(codes.Internal, "failed to update test: %v", err)
|
||||||
|
}
|
||||||
|
return &pb.UpdateTestResponse{
|
||||||
|
Test: &pb.Test{
|
||||||
|
Id: uint64(t.ID),
|
||||||
|
Content: t.Content,
|
||||||
|
CreatedAt: t.CreatedAt.Format(time.RFC3339),
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteTest deletes a test by ID
|
||||||
|
func (s *AuthServer) DeleteTest(ctx context.Context, req *pb.DeleteTestRequest) (*pb.DeleteTestResponse, error) {
|
||||||
|
if req.Id == 0 {
|
||||||
|
return nil, status.Errorf(codes.InvalidArgument, "test id required")
|
||||||
|
}
|
||||||
|
if err := s.repo.DeleteTest(uint(req.Id)); err != nil {
|
||||||
|
return nil, status.Errorf(codes.Internal, "failed to delete test: %v", err)
|
||||||
|
}
|
||||||
|
return &pb.DeleteTestResponse{
|
||||||
|
Success: true,
|
||||||
|
Message: "test deleted",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
101
services/auth-service/internal/utils/utils.go
Normal file
101
services/auth-service/internal/utils/utils.go
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go-microservices/services/auth-service/internal/models"
|
||||||
|
|
||||||
|
"github.com/golang-jwt/jwt/v4"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
accessTokenSecret []byte
|
||||||
|
refreshTokenSecret []byte
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
access := os.Getenv("JWT_ACCESS_SECRET")
|
||||||
|
if access == "" {
|
||||||
|
access = os.Getenv("JWT_SECRET")
|
||||||
|
}
|
||||||
|
refresh := os.Getenv("JWT_REFRESH_SECRET")
|
||||||
|
if refresh == "" {
|
||||||
|
refresh = os.Getenv("JWT_SECRET")
|
||||||
|
}
|
||||||
|
|
||||||
|
accessTokenSecret = []byte(access)
|
||||||
|
refreshTokenSecret = []byte(refresh)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenerateJWT generates an access token and refresh token for the provided user.
|
||||||
|
// The function expects the provided models.Auth (or models.User) to have ID, Email and Role fields.
|
||||||
|
func GenerateJWT(user models.Auth) (string, string, error) {
|
||||||
|
accessClaims := jwt.MapClaims{
|
||||||
|
"sub": user.ID,
|
||||||
|
"email": user.Email,
|
||||||
|
"role": user.Role,
|
||||||
|
"exp": time.Now().Add(15 * time.Minute).Unix(),
|
||||||
|
"iat": time.Now().Unix(),
|
||||||
|
}
|
||||||
|
|
||||||
|
accessToken := jwt.NewWithClaims(jwt.SigningMethodHS256, accessClaims)
|
||||||
|
signedAccessToken, err := accessToken.SignedString(accessTokenSecret)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error generating access token:", err)
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshClaims := jwt.MapClaims{
|
||||||
|
"sub": user.ID,
|
||||||
|
"exp": time.Now().Add(7 * 24 * time.Hour).Unix(),
|
||||||
|
"iat": time.Now().Unix(),
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshToken := jwt.NewWithClaims(jwt.SigningMethodHS256, refreshClaims)
|
||||||
|
signedRefreshToken, err := refreshToken.SignedString(refreshTokenSecret)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Error generating refresh token:", err)
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return signedAccessToken, signedRefreshToken, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidateJWT parses and validates the provided token string.
|
||||||
|
// If isRefreshToken is true, the refresh secret is used; otherwise the access secret is used.
|
||||||
|
func ValidateJWT(tokenString string, isRefreshToken bool) (jwt.MapClaims, error) {
|
||||||
|
secret := accessTokenSecret
|
||||||
|
if isRefreshToken {
|
||||||
|
secret = refreshTokenSecret
|
||||||
|
}
|
||||||
|
|
||||||
|
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
|
||||||
|
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||||
|
return nil, jwt.NewValidationError("invalid signing method", jwt.ValidationErrorSignatureInvalid)
|
||||||
|
}
|
||||||
|
return secret, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
claims, ok := token.Claims.(jwt.MapClaims)
|
||||||
|
if !ok || !token.Valid {
|
||||||
|
return nil, errors.New("invalid token")
|
||||||
|
}
|
||||||
|
return claims, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GenerateRandomToken returns a 128-bit random hex token (32 chars).
|
||||||
|
func GenerateRandomToken() string {
|
||||||
|
bytes := make([]byte, 16)
|
||||||
|
_, err := rand.Read(bytes)
|
||||||
|
if err != nil {
|
||||||
|
panic("Failed to generate random token")
|
||||||
|
}
|
||||||
|
return hex.EncodeToString(bytes)
|
||||||
|
}
|
||||||
33
services/post-service/Dockerfile
Normal file
33
services/post-service/Dockerfile
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
FROM golang:1.24-alpine AS build
|
||||||
|
RUN apk add --no-cache git ca-certificates protobuf-dev
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# use repo-level go.mod so modules are resolvable
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# install Go protoc plugins
|
||||||
|
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && \
|
||||||
|
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
|
||||||
|
|
||||||
|
# copy service sources and proto files
|
||||||
|
COPY services/post-service ./services/post-service
|
||||||
|
COPY proto ./proto
|
||||||
|
|
||||||
|
# generate proto files
|
||||||
|
RUN mkdir -p proto/auth proto/user proto/post && \
|
||||||
|
export PATH=/go/bin:$PATH && \
|
||||||
|
protoc --go_out=proto --go_opt=paths=source_relative \
|
||||||
|
--go-grpc_out=proto --go-grpc_opt=paths=source_relative \
|
||||||
|
--proto_path=proto \
|
||||||
|
proto/auth.proto proto/user.proto proto/post.proto && \
|
||||||
|
ls -la proto/auth/ proto/user/ proto/post/
|
||||||
|
|
||||||
|
# build static binary
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /usr/local/bin/post-service ./services/post-service/cmd
|
||||||
|
|
||||||
|
FROM alpine:3.20
|
||||||
|
RUN apk add --no-cache ca-certificates
|
||||||
|
COPY --from=build /usr/local/bin/post-service /usr/local/bin/post-service
|
||||||
|
EXPOSE 50053
|
||||||
|
ENTRYPOINT ["/usr/local/bin/post-service"]
|
||||||
40
services/post-service/cmd/main.go
Normal file
40
services/post-service/cmd/main.go
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
pb "go-microservices/proto/post"
|
||||||
|
"go-microservices/services/post-service/internal/database"
|
||||||
|
"go-microservices/services/post-service/internal/repository"
|
||||||
|
"go-microservices/services/post-service/internal/server"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("Starting Post Service...")
|
||||||
|
port := os.Getenv("PORT")
|
||||||
|
if port == "" {
|
||||||
|
port = "50053"
|
||||||
|
}
|
||||||
|
lis, err := net.Listen("tcp", ":"+port)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to listen: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := database.Init()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to init database: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
repo := repository.NewRepository(db)
|
||||||
|
|
||||||
|
grpcServer := grpc.NewServer()
|
||||||
|
pb.RegisterPostServiceServer(grpcServer, server.NewPostServer(repo))
|
||||||
|
log.Printf("Post Service listening on %s", port)
|
||||||
|
if err := grpcServer.Serve(lis); err != nil {
|
||||||
|
log.Fatalf("Failed to serve: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
1
services/post-service/config/config.yml
Normal file
1
services/post-service/config/config.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
This is the configuration file for the Post Service microservice.
|
||||||
22
services/post-service/config/env.go
Normal file
22
services/post-service/config/env.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Env struct {
|
||||||
|
Port int
|
||||||
|
JWTSecret string
|
||||||
|
TokenDuration int
|
||||||
|
DatabaseURL string
|
||||||
|
RedisAddr string
|
||||||
|
RedisPassword string
|
||||||
|
RedisDB int
|
||||||
|
EmailHost string
|
||||||
|
EmailPort int
|
||||||
|
EmailUsername string
|
||||||
|
EmailPassword string
|
||||||
|
EmailFrom string
|
||||||
|
FrontendURL string
|
||||||
|
}
|
||||||
22
services/post-service/internal/database/database.go
Normal file
22
services/post-service/internal/database/database.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"gorm.io/driver/postgres"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Init() (*gorm.DB, error) {
|
||||||
|
dsn := os.Getenv("DATABASE_URL")
|
||||||
|
if dsn == "" {
|
||||||
|
dsn = "host=localhost user=postgres password=postgres dbname=postgres port=5432 sslmode=disable TimeZone=UTC"
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return db, nil
|
||||||
|
}
|
||||||
7
services/post-service/internal/models/models.go
Normal file
7
services/post-service/internal/models/models.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
// TODO: Add database models for post service
|
||||||
|
// Example models:
|
||||||
|
// - Post model for blog posts
|
||||||
|
// - Comment model for post comments
|
||||||
|
// - Category model for post categorization
|
||||||
7
services/post-service/internal/repository/repository.go
Normal file
7
services/post-service/internal/repository/repository.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
// TODO: Add database repository implementations
|
||||||
|
// Example repositories:
|
||||||
|
// - PostRepository for post data access
|
||||||
|
// - CommentRepository for comment management
|
||||||
|
// - CategoryRepository for category management
|
||||||
13
services/post-service/internal/repository/repository_impl.go
Normal file
13
services/post-service/internal/repository/repository_impl.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Repository struct {
|
||||||
|
DB *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRepository(db *gorm.DB) *Repository {
|
||||||
|
return &Repository{DB: db}
|
||||||
|
}
|
||||||
47
services/post-service/internal/server/server.go
Normal file
47
services/post-service/internal/server/server.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
pb "go-microservices/proto/post"
|
||||||
|
"go-microservices/services/post-service/internal/repository"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/types/known/emptypb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PostServer struct {
|
||||||
|
pb.UnimplementedPostServiceServer
|
||||||
|
repo *repository.Repository
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPostServer(repo *repository.Repository) *PostServer {
|
||||||
|
return &PostServer{repo: repo}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PostServer) CreatePost(ctx context.Context, req *pb.CreatePostRequest) (*pb.CreatePostResponse, error) {
|
||||||
|
// TODO: Implement create post logic
|
||||||
|
post := &pb.Post{Id: "1", AuthorId: req.AuthorId, Title: req.Title, Content: req.Content, CreatedAt: 0, UpdatedAt: 0}
|
||||||
|
return &pb.CreatePostResponse{Post: post}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PostServer) GetPost(ctx context.Context, req *pb.GetPostRequest) (*pb.GetPostResponse, error) {
|
||||||
|
// TODO: Implement get post logic
|
||||||
|
post := &pb.Post{Id: req.Id, AuthorId: "author", Title: "title", Content: "content", CreatedAt: 0, UpdatedAt: 0}
|
||||||
|
return &pb.GetPostResponse{Post: post}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PostServer) UpdatePost(ctx context.Context, req *pb.UpdatePostRequest) (*pb.UpdatePostResponse, error) {
|
||||||
|
// TODO: Implement update post logic
|
||||||
|
post := &pb.Post{Id: req.Id, AuthorId: "author", Title: req.Title, Content: req.Content, CreatedAt: 0, UpdatedAt: 0}
|
||||||
|
return &pb.UpdatePostResponse{Post: post}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PostServer) DeletePost(ctx context.Context, req *pb.DeletePostRequest) (*emptypb.Empty, error) {
|
||||||
|
// TODO: Implement delete post logic
|
||||||
|
return &emptypb.Empty{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PostServer) ListPosts(ctx context.Context, req *pb.ListPostsRequest) (*pb.ListPostsResponse, error) {
|
||||||
|
// TODO: Implement list posts logic
|
||||||
|
posts := []*pb.Post{}
|
||||||
|
return &pb.ListPostsResponse{Posts: posts}, nil
|
||||||
|
}
|
||||||
33
services/user-service/Dockerfile
Normal file
33
services/user-service/Dockerfile
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
FROM golang:1.24-alpine AS build
|
||||||
|
RUN apk add --no-cache git ca-certificates protobuf-dev
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# use repo-level go.mod so modules are resolvable
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# install Go protoc plugins
|
||||||
|
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && \
|
||||||
|
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
|
||||||
|
|
||||||
|
# copy service sources and proto files
|
||||||
|
COPY services/user-service ./services/user-service
|
||||||
|
COPY proto ./proto
|
||||||
|
|
||||||
|
# generate proto files
|
||||||
|
RUN mkdir -p proto/auth proto/user proto/post && \
|
||||||
|
export PATH=/go/bin:$PATH && \
|
||||||
|
protoc --go_out=proto --go_opt=paths=source_relative \
|
||||||
|
--go-grpc_out=proto --go-grpc_opt=paths=source_relative \
|
||||||
|
--proto_path=proto \
|
||||||
|
proto/auth.proto proto/user.proto proto/post.proto && \
|
||||||
|
ls -la proto/auth/ proto/user/ proto/post/
|
||||||
|
|
||||||
|
# build static binary
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /usr/local/bin/user-service ./services/user-service/cmd
|
||||||
|
|
||||||
|
FROM alpine:3.20
|
||||||
|
RUN apk add --no-cache ca-certificates
|
||||||
|
COPY --from=build /usr/local/bin/user-service /usr/local/bin/user-service
|
||||||
|
EXPOSE 50052
|
||||||
|
ENTRYPOINT ["/usr/local/bin/user-service"]
|
||||||
39
services/user-service/cmd/main.go
Normal file
39
services/user-service/cmd/main.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
pb "go-microservices/proto/user"
|
||||||
|
"go-microservices/services/user-service/internal/database"
|
||||||
|
"go-microservices/services/user-service/internal/repository"
|
||||||
|
"go-microservices/services/user-service/internal/server"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println("Starting User Service...")
|
||||||
|
port := os.Getenv("PORT")
|
||||||
|
if port == "" {
|
||||||
|
port = "50052"
|
||||||
|
}
|
||||||
|
lis, err := net.Listen("tcp", ":"+port)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to listen: %v", err)
|
||||||
|
}
|
||||||
|
db, err := database.Init()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to init database: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
repo := repository.NewRepository(db)
|
||||||
|
|
||||||
|
grpcServer := grpc.NewServer()
|
||||||
|
pb.RegisterUserServiceServer(grpcServer, server.NewUserServer(repo))
|
||||||
|
log.Printf("User Service listening on %s", port)
|
||||||
|
if err := grpcServer.Serve(lis); err != nil {
|
||||||
|
log.Fatalf("Failed to serve: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
1
services/user-service/config/config.yml
Normal file
1
services/user-service/config/config.yml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
This is the configuration file for the User Service microservice. It defines the settings and parameters used by the service at runtime.
|
||||||
22
services/user-service/config/env.go
Normal file
22
services/user-service/config/env.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Env struct {
|
||||||
|
Port int
|
||||||
|
JWTSecret string
|
||||||
|
TokenDuration int
|
||||||
|
DatabaseURL string
|
||||||
|
RedisAddr string
|
||||||
|
RedisPassword string
|
||||||
|
RedisDB int
|
||||||
|
EmailHost string
|
||||||
|
EmailPort int
|
||||||
|
EmailUsername string
|
||||||
|
EmailPassword string
|
||||||
|
EmailFrom string
|
||||||
|
FrontendURL string
|
||||||
|
}
|
||||||
28
services/user-service/internal/database/database.go
Normal file
28
services/user-service/internal/database/database.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"go-microservices/services/user-service/internal/models"
|
||||||
|
|
||||||
|
"gorm.io/driver/postgres"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Init() (*gorm.DB, error) {
|
||||||
|
dsn := os.Getenv("DATABASE_URL")
|
||||||
|
if dsn == "" {
|
||||||
|
dsn = "host=localhost user=postgres password=postgres dbname=postgres port=5432 sslmode=disable TimeZone=UTC"
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := db.AutoMigrate(&models.User{}, &models.Client{}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return db, nil
|
||||||
|
}
|
||||||
27
services/user-service/internal/models/models.go
Normal file
27
services/user-service/internal/models/models.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Client struct {
|
||||||
|
gorm.Model
|
||||||
|
Name string
|
||||||
|
Email string `gorm:"uniqueIndex;not null"`
|
||||||
|
Active bool `gorm:"default:true"`
|
||||||
|
Address string
|
||||||
|
}
|
||||||
|
|
||||||
|
type User struct {
|
||||||
|
gorm.Model
|
||||||
|
Email string `gorm:"uniqueIndex;not null"`
|
||||||
|
Name string
|
||||||
|
Role string `gorm:"default:User"`
|
||||||
|
Active bool `gorm:"default:true"`
|
||||||
|
Username string `gorm:"uniqueIndex"`
|
||||||
|
Address string
|
||||||
|
PhoneNumber string
|
||||||
|
ProfilePhoto []byte `gorm:"type:bytea"`
|
||||||
|
ClientID *uint
|
||||||
|
Client *Client
|
||||||
|
}
|
||||||
7
services/user-service/internal/repository/repository.go
Normal file
7
services/user-service/internal/repository/repository.go
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
// TODO: Add database repository implementations
|
||||||
|
// Example repositories:
|
||||||
|
// - UserRepository for user data access
|
||||||
|
// - ProfileRepository for profile management
|
||||||
|
// - PreferenceRepository for user settings
|
||||||
13
services/user-service/internal/repository/repository_impl.go
Normal file
13
services/user-service/internal/repository/repository_impl.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package repository
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Repository struct {
|
||||||
|
DB *gorm.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRepository(db *gorm.DB) *Repository {
|
||||||
|
return &Repository{DB: db}
|
||||||
|
}
|
||||||
49
services/user-service/internal/server/server.go
Normal file
49
services/user-service/internal/server/server.go
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package server
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
pb "go-microservices/proto/user"
|
||||||
|
|
||||||
|
"go-microservices/services/user-service/internal/repository"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/types/known/emptypb"
|
||||||
|
)
|
||||||
|
|
||||||
|
type UserServer struct {
|
||||||
|
pb.UnimplementedUserServiceServer
|
||||||
|
repo *repository.Repository
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUserServer(repo *repository.Repository) *UserServer {
|
||||||
|
return &UserServer{repo: repo}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UserServer) CreateUser(ctx context.Context, req *pb.CreateUserRequest) (*pb.CreateUserResponse, error) {
|
||||||
|
// TODO: Implement create user logic
|
||||||
|
user := &pb.User{Id: "1", Username: req.Username, Email: req.Email, Bio: req.Bio, AvatarUrl: req.AvatarUrl, CreatedAt: 0, UpdatedAt: 0}
|
||||||
|
return &pb.CreateUserResponse{User: user}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UserServer) GetUser(ctx context.Context, req *pb.GetUserRequest) (*pb.GetUserResponse, error) {
|
||||||
|
// TODO: Implement get user logic
|
||||||
|
user := &pb.User{Id: req.Id, Username: "user", Email: "user@example.com", Bio: "bio", AvatarUrl: "", CreatedAt: 0, UpdatedAt: 0}
|
||||||
|
return &pb.GetUserResponse{User: user}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UserServer) UpdateUser(ctx context.Context, req *pb.UpdateUserRequest) (*pb.UpdateUserResponse, error) {
|
||||||
|
// TODO: Implement update user logic
|
||||||
|
user := &pb.User{Id: req.Id, Username: req.Username, Email: req.Email, Bio: req.Bio, AvatarUrl: req.AvatarUrl, CreatedAt: 0, UpdatedAt: 0}
|
||||||
|
return &pb.UpdateUserResponse{User: user}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UserServer) DeleteUser(ctx context.Context, req *pb.DeleteUserRequest) (*emptypb.Empty, error) {
|
||||||
|
// TODO: Implement delete user logic
|
||||||
|
return &emptypb.Empty{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UserServer) ListUsers(ctx context.Context, req *pb.ListUsersRequest) (*pb.ListUsersResponse, error) {
|
||||||
|
// TODO: Implement list users logic
|
||||||
|
users := []*pb.User{}
|
||||||
|
return &pb.ListUsersResponse{Users: users}, nil
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user