package
1.0.0-dev1
Repository: https://github.com/ghostbb-io/g-api.git
Documentation: pkg.go.dev

# README

gormx

  • 支持連線多種資料庫,目前支援mssql,mysql,pgsql。
  • 使用redis進行查詢緩存
  • 使用zap進行log輸出

使用方法

package main

import (
    "github.com/Ghostbb-io/g-api/pkg/gormx"
	"github.com/Ghostbb-io/g-api/pkg/gormx/gorm-cache/config"
	"github.com/Ghostbb-io/g-api/pkg/gormx/gorm-cache/gzap"
	"github.com/Ghostbb-io/g-api/pkg/gormx/gorm-cache/storage"
)

func main() {
	zapConfig := gzap.Config{
		Level:         "info",
		Prefix:        "[Gorm] ",
		Format:        "console", // console or json
		Director:      "/log",
		EncodeLevel:   "LowercaseLevelEncoder",
		StacktraceKey: "stacktrace",
		MaxAge:        5,
		ShowLine:      true,
		LogInConsole:  false,
	}

	// database 設定
	dbConfig := &gormx.Config{
		DBType:       gormx.Mysql,
		Dsn:          "gormx:123456@tcp(localhost:3306)/dbname",
		MaxIdleConns: 10,
		MaxOpenConns: 100,
		LogMode:      "info",
		UseZap:       true,
		Zap:          gormx.Zap{Config: zapConfig},
	}

	// 緩存設定
	cacheConfig := &config.CacheConfig{
		CacheLevel: config.CacheLevelAll,
		CacheStorage: storage.NewRedis(&storage.RedisStoreConfig{
			Client: redis.client,
		}),
		InvalidateWhenUpdate: true,
		CacheTTL:             5000,
		CacheMaxItemCnt:      50,
		DebugMode:            true,
	}

	db, err := gormx.New(dbConfig, cacheConfig)
}

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author

# Structs

No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author