ego

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: MIT Imports: 2 Imported by: 0

README

说明

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

特性

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

Getting Started

  • Install
go get github.com/zutim/ego
  • main
package main

import (
	"github.com/zutim/ego"
	"github.com/zutim/ego/component"
	"github.com/gin-gonic/gin"
	"google.golang.org/grpc"
	"net/http"
)

func main() {
	Run(ego.ServerRunOptions{HttpAddr: ":8080", HttpTraceHeader: "trace", RPCAddr: ":8081"})
}

func Run(options ego.ServerRunOptions) {
	aggregator := ego.NewAggregatorServer()
	aggregator.WithComponent(component.NewCache(), component.NewLogger())

	httpServer := ego.NewHTTPServer(options.HttpAddr).
		EnablePprofHandler().
		EnableAvailableHealthCheck().
		EnableSwaggerHandler().
		EnableCorsMiddleware().
		EnableTraceMiddleware(options.HttpTraceHeader).
		WithNotFoundHandler(func(ctx *gin.Context) {
			ctx.String(http.StatusNotFound, "404 Not Found")
		}).
		RegisterRouteLoader(func(router *gin.Engine) {
			router.GET("/", func(ctx *gin.Context) {
				ctx.String(http.StatusOK, "home")
			})
		})

	grpcServer := ego.NewGRPCServer(options.RPCAddr).RegisterService(func(s *grpc.Server) {
		// pb.RegisterGreeterServer(s, &HelloService{})
	})

	aggregator.WithServer(httpServer, grpcServer)

	aggregator.Run()
}

文档

详细文档地址:https://zutim.github.io

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAggregatorServer added in v1.0.1

func NewAggregatorServer() *aggregator.Aggregator

NewAggregator creates a new Aggregator instance

func NewGRPCServer added in v1.0.1

func NewGRPCServer(addr string) *server.RPCServer

func NewHTTPServer added in v1.0.1

func NewHTTPServer(addr string) *server.HTTPServer

func NewWebsocketServer added in v1.0.1

func NewWebsocketServer(addr string) *server.WebSocketServer

Types

type ServerRunOptions added in v1.0.1

type ServerRunOptions struct {
	HttpAddr        string
	HttpTraceHeader string
	RPCAddr         string
	WebSocketAddr   string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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