ego

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: MIT Imports: 1 Imported by: 4

README

说明

简单易用又强大的微服务golang框架。

特性

  • http服务
  • 定时任务
  • 丰富的中间件:请求日志、JWT认证,跨域,Recover,全局链路
  • 集成Redis,Mysql,Jwt,Etcd客户端等基础组件
  • 配置项
  • 参数验证器
  • curl组件
  • Swagger

安装

go get -u github.com/ebar-go/ego

示例

  • 配置文件
server:
  name: demo
http:
  port: 8085
  • main.go
package main
import (
	"github.com/ebar-go/ego"
	"github.com/ebar-go/ego/component/log"
	"github.com/ebar-go/ego/http/middleware"
	"github.com/ebar-go/ego/http/response"
	"github.com/ebar-go/egu"
	"github.com/gin-gonic/gin"
)
func main() {
	// 初始化应用
	app := ego.App()
	// 加载配置文件
	egu.SecurePanic(app.LoadConfig("./app.yaml"))
	// 初始化路由
	egu.SecurePanic(app.LoadRouter(func (router *gin.Engine,logger *log.Logger,)  {
		// 引入跨域、recover、请求日志三个中间件
		router.Use(middleware.CORS, middleware.Recover, middleware.RequestLog(logger))
		router.GET("index", func(ctx *gin.Context) {
			// 记录日志
			logger.Info("test", log.Context{"hello":"world"})
			// 输出响应
			response.WrapContext(ctx).Success(nil)
		})
	}))
	// 启动http服务
	app.ServeHTTP()
	// 启动应用
	app.Run()
}
  • 通过go run main.go启动服务
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /index                    --> main.initRouter.func1 (6 handlers)
2021-03-29 00:23:01.786178 I | Listening and serving HTTP on :8085

访问localhost:8085/index验证结果。

文档

详细文档地址:https://ebar-go.github.io

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func App added in v1.0.0

func App() *app.App

Types

This section is empty.

Directories

Path Synopsis
component
log
trace
Trace 基于goroutine的编号,实现共享全局唯一ID,用于串联业务线的上下文
Trace 基于goroutine的编号,实现共享全局唯一ID,用于串联业务线的上下文
examples
echo Module
grpc Module
response
r 基于gin的Context,实现响应数据结构体 集成全局traceID
r 基于gin的Context,实现响应数据结构体 集成全局traceID

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳