Welcome to GoTAL, a Go-based enterprise project. This project utilizes a robust architecture suitable for scalable and efficient web services.
- Golang environment setup
- http server + grpc server (microservices)
- MySQL and Redis services running
- Necessary environment variables set for MySQL and Redis configurations
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β Frontend β β Frontend β β Frontend β ...... (Different Roles Of Clients)
β (Customer) β β (Admin) β β (Robot) β
βββββββββ¬ββββββββ βββββββββ¬ββββββββ βββββββββ¬ββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β BFF β β BFF β β BFF β
β (Controller β β (Controller β β (Controller β
β + Service) β β + Service) β β + Service) β
βββββββββ¬ββββββββ βββββββββ¬ββββββββ βββββββββ¬ββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β Store Layer β β Store Layer β β Store Layer β
β (gRPC Client) β β (gRPC Client) β β (gRPC Client) β
βββββββββ¬ββββββββ βββββββββ¬ββββββββ βββββββββ¬ββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β Backend gRPC β β Backend gRPC β β Backend gRPC β
β Services β β Services β β Services β
β(Service + β β(Service + β β(Service + β
β Store) β β Store) β β Store) β
βββββββββββββββββ βββββββββββββββββ βββββββββββββββββ
β β β
βββββββββββββββββββββββββ΄ββββββββββββββββββββββββ
β
βΌ
βββββββββββββ
β Database β
βββββββββββββ
βββ CHANGELOG
βββ CONTRIBUTING.md
βββ LICENSE
βββ Makefile
βββ README.md
βββ api
βββ build
βββ cert
β βββ apiserver-key.pem
β βββ apiserver.pem
β βββ san.cnf
β βββ server.crt
β βββ server.csr
β βββ server.key
βββ cmd
β βββ apiserver
β β βββ stdout
β β βββ apiserver
β β βββ apiserver.go
β βββ authzserver
β β βββ authzserver
β β βββ authzserver.go
β βββ redis_test
β β βββ main
β β βββ main.go
β β βββ redis_test
β βββ rpc_test
β β βββ main.go
β βββ user_service
β βββ user.go
β βββ user_service
βββ configs
β βββ apiserver-client.yaml
β βββ authzserver.yaml
β βββ user-service.yaml
βββ deployments
βββ docs
βββ githooks
βββ go.mod
βββ go.sum
βββ image.png
βββ init
βββ init.sh
βββ internal
β βββ apiserver
β β βββ app.go
β β βββ auth.go
β β βββ config
β β βββ controller
β β βββ grpc.go
β β βββ options
β β βββ router.go
β β βββ run.go
β β βββ server.go
β β βββ service
β β βββ store
β βββ authzserver
β β βββ app.go
β β βββ config
β β βββ options
β β βββ run.go
β β βββ server.go
β βββ pkg
β β βββ code
β β βββ errors
β β βββ logger
β β βββ middleware
β β βββ options
β β βββ response
β β βββ server
β β βββ util
β β βββ validation
β βββ proto
β β βββ options
β β βββ user
β βββ user_service
β βββ app.go
β βββ config
β βββ doc.go
β βββ grpc.go
β βββ options
β βββ router.go
β βββ run.go
β βββ server.go
β βββ service
β βββ store
βββ logs
β βββ apiserver.error.log
β βββ apiserver.log
β βββ user_service
β βββ user.error.log
β βββ user.log
βββ pkg
β βββ app
β β βββ app.go
β β βββ cmd.go
β β βββ config.go
β β βββ help.go
β β βββ option.go
β βββ cache
β β βββ cache.go
β β βββ redis.go
β βββ cli
β βββ db
β β βββ mysql.go
β β βββ plugin.go
β βββ log
β β βββ context.go
β β βββ encoder.go
β β βββ log.go
β β βββ options.go
β β βββ types.go
β βββ shutdown
β β βββ managers
β β βββ shutdown.go
β βββ util
β β βββ common
β β βββ flag
β β βββ term
β βββ validator
βββ test
β βββ ratelimiter-test.sh
βββ third_party
βββ tools
61 directories, 64 files
-
Building the API server: Navigate to the API server directory:
cd /Users/huanghaitao/gotal/cmd/apiserver
Build the API server:
go build
-
Starting the Server: Run the API server with the specified configuration:
./apiserver --config ../../configs/apiserver.yaml
This will initialize the server with various configurations as shown in your provided start-up log.
After the section on starting the server, the following detailed configurations are applied:
server:
mode: debug # Modes: release, debug, test. Default is release.
healthz: true # Enable health check, setting up /healthz route. Default is true.
middlewares: recovery,logger,secure,nocache,cors,dump # List of gin middlewares.
grpc:
bind-address: 0.0.0.0 # IP address for gRPC. Default is 0.0.0.0.
bind-port: 8082 # Port for gRPC. Default is 8081.
insecure:
bind-address: 0.0.0.0 # IP address for insecure binding. Default is 127.0.0.1.
bind-port: 8884 # Non-secure port. Default is 8080.
secure:
bind-address: 0.0.0.0 # IP address for HTTPS. Default is 0.0.0.0.
bind-port: 8445 # Port for HTTPS. Default is 8443.
tls:
cert-key:
cert-file: /Users/huanghaitao/gotal/cert/apiserver.pem # Certificate file path.
private-key-file: /Users/huanghaitao/gotal/cert/apiserver-key.pem # Private key file path.
mysql:
host: 127.0..0.1 # MySQL server address.
username: root # MySQL username.
password: # MySQL password.
database: db # Database name.
max-idle-connections: 100 # Max idle connections.
max-open-connections: 100 # Max open connections.
max-connection-life-time: 10s # Connection lifetime.
log-level: 4 # Log level.
redis:
host: 127.0.0.1 # Redis host.
port: 6379 # Redis port.
password: # Redis password.
# Additional configuration details can be specified here.
jwt:
realm: JWT # JWT realm identifier.
key: # Secret key.
timeout: 24h # Token expiration time.
max-refresh: 24h # Token refresh time.
feature:
enable-metrics: true # Enable metrics at /metrics.
profiling: true # Enable performance analysis at /debug/pprof/.
ratelimit:
requests-per-second: 1 # Requests per second per user.
burst-size: 20 # Maximum burst size.
custom-limits:
"/test-response":
requests-per-second: 1.5 # Requests per second for specific endpoint.
burst-size: 10 # Burst size for specific endpoint.
log:
name: apiserver # Logger name.
development: true # Development mode.
level: debug # Log level.
format: console # Log format.
enable-color: true # Color output.
disable-caller: false # Caller information.
disable-stacktrace: false # Stack trace.
output-paths: /Users/huanghaitao/gotal/logs/apiserver.log # Output paths.
error-output-paths: /Users/huanghaitao/gotal/logs/apiserver.error.log # Error log paths.
This detailed configuration will ensure that your GoTAL API server is set up with the specific settings required for its operation. These settings include server modes, service bindings, database connections, logging, and more, ensuring a comprehensive and robust setup for your enterprise-grade application.
The server's behavior is controlled by various flags and options. These include but are not limited to:
- gRPC Configurations: Address, port, message size limits.
- MySQL and Redis Configurations: Host, port, authentication, pooling settings.
- JWT Settings: Key, timeout, refresh settings.
- Server Mode: Including debug, test, and release modes.
Detailed flag descriptions are available in the start-up log section of this README.
The project is structured into several layers to promote separation of concerns and maintainability:
- Controller Layer: Handles HTTP requests, invoking the appropriate services.
- Service Layer: Contains business logic and interacts with the repository layer.
- Repository Layer: Responsible for data access and storage management.
- Cobra & Viper: Used for building CLI and managing configuration files.
- Validator: Ensures that incoming requests meet the defined constraints.
- Middleware: Includes authentication, logging, CORS, rate limiting, etc.
- Logging: Structured logging for tracing and monitoring.
- MySQL & Redis: Used for data storage and caching.
Refer to CONTRIBUTING.md
for guidelines on how to contribute to this project.
This project is licensed under the terms mentioned in LICENSE
.
For a detailed changelog, see CHANGELOG
.
This README provides a basic overview of GoTAL. For detailed documentation, refer to the docs
directory.