golory

package module
v0.0.0-...-8d6c2a3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

README

golory

Build Status Go Report Card License

Documentation

Overview

Package golory is ALL IN ONE package for go software development with best practice usages support

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// Error occurred when parse configuration
	ErrParseCfg = errors.New("parse cfg failed")
)

Exported errors

Functions

func Boot

func Boot(cfg interface{}) error

Boot initiate components from configuration file or binary content. Toml, Json, Yaml supported.

Example
package main

import (
	"fmt"
	"github.com/1pb-club/golory"
)

func main() {
	cfg := `
	[golory]
   		[golory.logger.default]
   			debug = true
   			level = "info"
   			path = "./default.log"
	`
	fmt.Println(golory.Boot([]byte(cfg)))
}
Output:

<nil>

func Shutdown

func Shutdown() error

Shutdown close components

Types

type GormCfg

type GormCfg struct {
	Debug    bool
	Engine   string                 // Database type, default: mysql
	Username string                 // Database Username
	Password string                 // Database Password (requires User)
	Net      string                 // Database Network type
	Addr     string                 // Database Network address (requires Net)
	DBName   string                 // Database name
	Params   map[string]interface{} //  mysql suffix params ,See in detail:https://github.com/go-sql-driver/mysql#parameters

	TablePrefix string // database table prefix

	SingularTable bool          // Set true to disable table name's pluralization globally
	MaxOpenConn   int           // Maximum connection of database
	MaxIdleConn   int           // Maximum idle connection number of database
	MaxLifetime   time.Duration // The maximum time of a single connection in a database
}

GormCfg is sql config struct

type GormClient

type GormClient struct {
	*gorm.DB
}

GormClient contains information for current db connection

func Gorm

func Gorm(name string) *GormClient

Gorm return a *GromClient by name

type LoggerCfg

type LoggerCfg struct {
	Debug bool
	Level string
	Path  string
}

LoggerCfg configurations

type LoggerClient

type LoggerClient struct {
	*zap.Logger
}

LoggerClient wrapped zapper TODO: for dynamic config & more log api

func Logger

func Logger(name string) *LoggerClient

Logger return a log.Logger by name

Example
package main

import (
	"fmt"
	"github.com/1pb-club/golory"
)

func main() {
	cfg := `
		[golory]
   			[golory.logger.golory]
   				debug = true
   				level = "error"
   				path = "golory.log"
			[golory.logger.default]
   				debug = true
   				level = "info"
   				path = "default.log"
	`
	if err := golory.Boot([]byte(cfg)); err != nil {
		fmt.Printf("boot golory failed, %s", err)
	}

	fmt.Println(golory.Logger("golory") == nil)
	fmt.Println(golory.Logger("default") == nil)
}
Output:

false
false

type RedisCfg

type RedisCfg struct {
	Addr string
}

RedisCfg wrapped go-redis options and some other golory options

type RedisClient

type RedisClient struct {
	*redis.Client
}

RedisClient wrapped go-redis RedisClient

func Redis

func Redis(name string) *RedisClient

Redis return a redis.Client by name

Example
package main

import (
	"fmt"
	"github.com/1pb-club/golory"
)

func main() {
	cfg := `
	[golory]
		[golory.redis.default]
		  Addr = "127.0.0.1:6379"
		[golory.redis.user]
		  Addr = "127.0.0.1:6479"
	`
	if err := golory.Boot([]byte(cfg)); err != nil {
		fmt.Printf("boot golory failed, %s", err)
	}
	fmt.Println(golory.Redis("default") == nil)
	fmt.Println(golory.Redis("no-this-user") == nil)
}
Output:

false
true

type TDengineCfg

type TDengineCfg struct {
	Username string // Database Username
	Password string // Database Password (requires User)
	Addr     string // Database Network address
	DBName   string // Database name
}

TDengineCfg wrapped tdengine options and some other golory options

type TDengineClient

type TDengineClient struct {
	*sql.DB
}

TDengineClient wrapped go-redis TDengineClient

func TDengine

func TDengine(name string) *TDengineClient

TDengine return *TDengineClient by name

Example
package main

import (
	"fmt"
	"github.com/1pb-club/golory"
)

func main() {
	cfg := `
	[golory]
		[golory.tdengine.default]
		  username = "root"
		  password = "taosdata"
		  addr = "192.168.1.99:6030"
		  DBName = "top1"
	`
	if err := golory.Boot([]byte(cfg)); err != nil {
		fmt.Printf("boot golory failed, %s", err)
	}
	fmt.Println(golory.TDengine("default") == nil)
}
Output:

false

Jump to

Keyboard shortcuts

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