zus-go-common

module
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2026 License: MIT

README

zus-go-common

Shared Go package for ZUS services. Centralizes database and cache connection setup so consuming projects inherit consistent driver versions from a single module.

Installation

go get github.com/TechTeam-ZUS/zus-go-common

Setup

Copy the example env file and fill in your credentials:

cp .env.example .env

Usage

package main

import (
    "log"

    "github.com/TechTeam-ZUS/zus-go-common/common"
)

func main() {
    if err := common.LoadEnv(); err != nil {
        log.Fatal(err)
    }

    mysqlDB, err := common.SetupMySQLConnectionFromEnv()
    if err != nil {
        log.Fatal(err)
    }
    defer mysqlDB.Close()

    pgDB, err := common.SetupPostgreSQLConnectionFromEnv()
    if err != nil {
        log.Fatal(err)
    }
    defer pgDB.Close()

    redisClient, err := common.SetupRedisConnectionFromEnv()
    if err != nil {
        log.Fatal(err)
    }
    defer redisClient.Close()
}

You can also pass explicit config instead of reading from common environment file:

db, err := common.SetupMySQLConnection(common.MySQLConfig{
    Host:     "localhost",
    Port:     "3306",
    User:     "root",
    Password: "secret",
    Database: "myapp",
})

Environment Variables

See .env.example for all supported variables.

Service Required Variables
MySQL MYSQL_DATABASE, MYSQL_PASSWORD
PostgreSQL POSTGRES_DATABASE, POSTGRES_PASSWORD
Redis None (defaults to localhost:6379, DB 0)

API

Function Description
LoadEnv() Load variables from .env
SetupMySQLConnection(cfg) Open and ping a MySQL pool
SetupMySQLConnectionFromEnv() MySQL setup using env vars
SetupPostgreSQLConnection(cfg) Open and ping a PostgreSQL pool
SetupPostgreSQLConnectionFromEnv() PostgreSQL setup using env vars
SetupRedisConnection(cfg) Create and ping a Redis client
SetupRedisConnectionFromEnv() Redis setup using env vars

Directories

Path Synopsis
Package prefixhook provides a redis.Hook that transparently prefixes every key with a fixed namespace (e.g.
Package prefixhook provides a redis.Hook that transparently prefixes every key with a fixed namespace (e.g.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL