GithubHelp home page GithubHelp logo

goworkeryyt / go-core Goto Github PK

View Code? Open in Web Editor NEW
55.0 2.0 3.0 451 KB

go-core 是 go web 应用开发脚手架,从全局配置文件读取,zap日志组件始化,gorm数据库连接初始化,redis客户端初始化,http server启动等。最终实现简化流程、提高效率、统一规范。

License: Apache License 2.0

Go 100.00%
zap gorm database redis

go-core's Introduction

go-core

介绍

go-core 是 go web 应用开发脚手架,从全局配置文件读取,zap日志组件始化,gorm数据库连接初始化,redis客户端初始化,http server启动等。最终实现简化流程、提高效率、统一规范。

安装

go get -u github.com/goworkeryyt/go-core

例子

默认的程序根目录下必须包含 resources 文件夹,且文件夹内必须有 active.yaml和四种不同环境的开发文件至少一种 配置文件参考 https://github.com/goworkeryyt/go-config 库的resources目录下的配置文件

├── resources(项目整合配置文件示例)
│   ├── active.yaml      配置指定要激活启用的配置文件
│   └── dev_config.yaml  开发环境配置文件
│   └── fat_config.yaml  功能验收测试环境配置文件
│   └── pro_config.yaml  生产环境配置文件
│   └── uat_config.yaml  用户验收测试环境配置文件
package main

import (
	"github.com/gin-gonic/gin"
	"github.com/goworkeryyt/go-config"
	"github.com/goworkeryyt/go-config/env"
	"github.com/goworkeryyt/go-core/db"
	"github.com/goworkeryyt/go-core/global"
	"github.com/goworkeryyt/go-core/mqtt"
	"github.com/goworkeryyt/go-core/redis"
	"github.com/goworkeryyt/go-core/srun"
	"github.com/goworkeryyt/go-core/zap"
)

func main() {

	// 获取程序运行环境,默认会读取 resources/active.yaml 文件中配置的运行环境
	global.ENV = env.Active()

	// 获取全局配置,默认根据运行环境加载对应配置文件
	global.CONFIG = goconfig.GlobalConfig()

	// 初始化zap日志
	global.LOG = zap.Zap()

	// 初始化数据库连接
	global.DB = db.Gorm()

	// 初始化 redis 客户端
	global.REDIS = redis.Redis()

	// 初始化 mqtt
	global.MQTT = mqtt.DefaultMqtt("111111")

	// 获取配置文件原始内容,这样方便在程序中全局拿到自己定义的配置子项
	global.VP = global.CONFIG.Viper

	// 启动 http 服务
	r := gin.Default()
	// 健康监测
	r.GET("/health", func(c *gin.Context) {
		c.JSON(200, "ok")
	})
	// 启动服务
	srun.RunHttpServer(r)
}

go-core's People

Contributors

goworkeryyt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

go-core's Issues

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.