Giter VIP home page Giter VIP logo

go-base's Introduction

Golang项目基础库

配置管理

封装Viper库,可直接解析项目当前或父级conf目录下面的config.yaml配置文件;

Example

simple demo auto parse config file

import "github.com/deng00/go-base/config"
configIns := config.GetConfigFromLocal()
configIns.GetString("level")

日志管理

封装Zap日志库,减少不必要的配置项;

提供输出日志到多种渠道: Console、本地文件、日志中心(待完成);

增加实时告警,当前支持DingDing告警;

可自动根据配置文件初始化日志服务,只需在配置中配置告警渠道即可实现自动告警;

日志示例

simple demo show log on console

import "github.com/deng00/go-base/logging"
logConfig := &logging.LogConfig{}
logConfig.EnableDebug()
logConfig.EnableHandlerFile()
logger := logging.GetLogger("testServiceName", logConfig).Sugar()
logger.Info("info", logging.String("url", "https://www.baidu.com"))

Send alert realtime and save log to file, files will create under current dir logs named as the service name you set. Single log file max size up to 1 GB .

logConfig := &logging.LogConfig{}
logConfig.EnableHandlerStd()
logConfig.SetAlertChannel(logging.NewDingDingAlertChanel("XXX"))
logConfig.SetAlertLevel(logging.ErrorLevel)
logger := logging.GetLogger("testServiceName", logConfig).Sugar()
logger.Errorf("info key %s", "value")

根据使用配置实例自动初始化:

configIns := config.GetConfigFromLocal()
LogConfig := logging.GetLogConfig(configIns)
logger := logging.GetLogger("testServiceName", logConfig).Sugar()
logger.Infof("info key %s", "value")

服务注册

封装consul服务,提供自动服务注册和发现;

提供动态配置文件管理,当consul的配置(key)修改后本地服务config实例自动同步;

日志管理Manager

All in One

var configIns = &config.Config{}
configManager := config.Manager{}
_ = configManager.Init("go-base-demo")
configIns = configManager.GetIns()
LogConfig := logging.GetLogConfig(configIns)
logger := logging.GetLogger("test", LogConfig)
logger.Error("test send alert")

配置告警使用的场景,配置文件格式格式:

log:
  handlerStd: true
  handlerFile: true
  fileDir: logs
  level: info
  alert:
    level: error
    channel: dingding
    channel_param: 机器人Token

go-base's People

Contributors

cs-danny avatar deng00 avatar threeandtwo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.