Categorygithub.com/TekClinic/MicroService-Lib
modulepackage
0.1.3
Repository: https://github.com/tekclinic/microservice-lib.git
Documentation: pkg.go.dev

# README

MicroService-Lib

The MicroService-Lib package provides essential utilities for managing microservice configurations, including environment-based service parameters, logging, gRPC server/client setup, and token verification.

This package simplifies common tasks in microservice architectures such as service discovery, configuration, and secure communication.

Configurable Environment Variables

This application uses several environment variables to configure various aspects of the microservices, authentication, and logging.

Below is a comprehensive list of these environment variables and their descriptions.

Client-Side Microservice Configuration

These environment variables are used to discover and connect to other microservices.

  • MS_{serviceName}_HOST

    • Description: The hostname of the microservice specified by {serviceName}.
    • Usage: Defines the host for a given microservice.
    • Example: For a service named auth, the variable would be MS_AUTH_HOST.
  • MS_{serviceName}_PORT

    • Description: The port number on which the microservice specified by {serviceName} listens for GRPC requests.
    • Default: "9090"
    • Usage: Defines the port for a given microservice.
    • Example: For a service named auth, the variable would be MS_AUTH_PORT.
  • MS_SECURE_CONN

    • Description: Indicates whether the microservice should use a secure connection to other services.
    • Options: "true" (use secure connection) or "false" (use insecure connection).
    • Default: "false"
    • Usage: Configures the transport security for GRPC connections.

Server-Side Configuration

  • GRPC_PORT

    • Description: The port on which the GRPC server listens to.
    • Default: "9090"
    • Usage: Configures the listening port of the GRPC server.
  • AUTH_ISSUER

    • Description: The URL of the authentication provider.
    • Usage: Specifies the issuer for JWT token verification.
    • Required: Yes

Logging Configuration

  • MS_LOG_MODE
    • Description: Sets the logging mode for the microservice.
    • Options: "debug" (enables debug logging) or any other value (disables debug logging).
    • Default: "dev" mode if not specified.
    • Usage: Controls the verbosity of the logs.

Deployment Mode Configuration

  • MS_MODE
    • Description: Specifies the running mode of the microservice.
    • Options: "dev" (development mode) or "prod" (production mode).
    • Default: "dev"
    • Usage: Determines the mode in which the microservice operates, affecting logging and other settings.

# Functions

CreateBaseServiceServer initiates baseServiceServer with parameters from environment variables.
FetchServiceParameters returns a Service object that describes service named serviceName.
GetDBQueryHook returns a bun.QueryHook that logs queries.
GetGRPCClientOptions returns a list of options for a GRPC client.
GetGRPCServerOptions returns a list of options for a GRPC server.
GetOptionalEnv retrieves the value of the environment variable named by the key.
GetRequiredEnv retrieves the value of the environment variable named by the key.
HasDebugLogging returns true if the microservice logs are set to debug level.
HasSecureConnection returns true if the microservice is running in secure mode.
IsProduction returns true if the microservice is running in production mode.

# Structs

Service defines basic parameters of a microservice for a client.

# Interfaces

BaseServiceServer contains a port on which the server listens for GRPC requests and provides JWT token verification.
Claims contains claims from a token and allows roles-checking for authorization.