Member Service is an open-source microservice developed in Go that handles user authentication, registration, and login. It integrates various use cases and scenarios related to user management.
- User Registration
- User Login
- User Authentication
- Password Update
- OAuth2.0 Integration (Google)
- gRPC Service for Authorization
- Automatic Database Creation
- Containerized Deployment
- Go (version 1.16 or later)
- PostgreSQL
- Redis
- Clone the repository:
https://github.com/iamsad5566/member_service_frame.git
- Navigate to the project directory:
cd member_service_frame
- Build:
go build
The application uses a configuration file (example_config.yml
) to store various settings. Here's an overview of the configuration options:
-
valid_login: Number of days before a user's login expires (default: 14).
-
member_service:
- host: Host for the Member Service (censored in the example).
- port: Port for the Member Service (default: 888).
- RESTfulPort: Port for the RESTful API (default: 8112).
- gRPCPort: Port for the gRPC service (default: 8113).
-
jwt:
- secret_key: Secret key for JSON Web Tokens (censored in the example).
- token_expire: Token expiration time in seconds (default: 86400, which is 24 hours).
-
db:
- psql:
- account: PostgreSQL database account (censored in the example).
- password: PostgreSQL database password (censored in the example).
- host: PostgreSQL database host (censored in the example).
- port: PostgreSQL database port (default: 5433).
- maxIdleConns: Maximum number of idle connections in the PostgreSQL connection pool (default: 20).
- maxOpenConns: Maximum number of open connections in the PostgreSQL connection pool (default: 20).
- maxLifeMinute: Maximum life time (in minutes) for connections in the PostgreSQL connection pool (default: 10).
- redis:
- password: Redis password (censored in the example).
- host: Redis host (censored in the example).
- port: Redis port (default: 6379).
- psql:
-
logConfig:
- level: Log level (default: info).
- filename: Log file name (default: logs/viper_zap_gin.log).
- maxsize: Maximum size of the log file in megabytes (default: 1).
- max_age: Maximum age of log files in days (default: 30).
- max_backups: Maximum number of old log files to keep (default: 5).
-
oauth2
- google:
- client_id: Google OAuth2.0 client ID (censored in the example).
- client_secret: Google OAuth2.0 client secret (censored in the example).
- google:
Note
Please note that the sensitive values (e.g., passwords, secrets) are censored in the provided example for security reasons.
If you prefer to use the open-source version of the setting implementation, you can follow these steps:
- Rename the
example_config.yml
file toconfig.yml
and modify the path inconfig.getRoot()
. - Update the configuration values according to your environment.
Alternatively, you can use the private setconf
repository (this repository only be applied by the author) for setting management. In this case, you'll need to replace the config.Setting
object with your own implementation.
After configuring the settings, you can run the application with the following command:
./member_service_frame
This will start the Member Service, which includes the RESTful API, gRPC service, and automatic database creation (if the database doesn't exist).
The Member Service provides a Swagger UI for API documentation. You can access it at http://localhost:8080/swagger/index.html
(replace 8080
with the configured port if different).
The Member Service can be deployed using Docker containers. One Dockerfile is provided:
- Dockerfile: For building and running the application.
To build the Docker image, run the following command:
docker build --build-arg GITHUB_TOKEN=<your_github_token> --build-arg LATEST_SETCONF_VERSION=<setconf_version> -t member_service .
Replace <your_github_token>
with your GitHub personal access token and <setconf_version>
with the latest version of the setconf repository. By the way, if you decide to use the open-source implementation of the config setting, please remove everything related to setconf
and GOPRIVATE
in the Dockerfile
, and ./github/workflows/ci-cd.yml
, ./github/workflows/test.yml
.
After building the Docker image, you can run the container with the following command:
docker run -d --name member_service -p 8080:8080 member_service
This will start the Member Service container and map port 8080 to the host.
The Member Service includes GitHub Actions workflows for Continuous Integration (CI) and Continuous Deployment (CD).
The CI workflow (auto test
) is triggered on every push to the main
branch. It performs the following steps:
- Checks out the source code
- Sets up the
GOPRIVATE
environment variable - Logs in to the GitHub Package Registry
- Builds the test Docker image (passing the GitHub Token and
setconf
version as build arguments) - Runs the tests inside the Docker container
The CD workflow (CI/CD
) is triggered when a new release is published. It performs the following steps:
- Checks out the source code
- Sets up the
GOPRIVATE
environment variable - Logs in to the GitHub Package Registry and Docker Hub
- Builds the Docker image (passing the GitHub Token and
setconf
version as build arguments) - Tags and pushes the Docker image to Docker Hub
- Deploys the Docker image to a remote server via SSH
Note
Please note that you'll need to configure the required GitHub Secrets (TOKEN, LATEST_SETCONF_VERSION, REMOTE_HOST, SSH_PRIVATE_KEY, DOCKER_USERNAME, and DOCKER_PASSWORD) for the workflows to work correctly.
Contributions to the Member Service are welcome! If you find any issues or want to add new features, please open an issue or submit a pull request.
The Member Service is open-source software released under the MIT License.