ego

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: MIT Imports: 26 Imported by: 82

README

EGO

Go Go Report Card codecov goproxy.cn Release

帮助文档

https://ego.gocn.vip

Quick Start

HelloWorld

import (
   "github.com/gin-gonic/gin"
   "github.com/gotomicro/ego"
   "github.com/gotomicro/ego/core/elog"
   "github.com/gotomicro/ego/server"
   "github.com/gotomicro/ego/server/egin"
)
//  export EGO_DEBUG=true && go run main.go --config=config.toml
func main() {
   if err := ego.New().Serve(func() *egin.Component {
      server := egin.Load("server.http").Build()
      server.GET("/hello", func(ctx *gin.Context) {
         ctx.JSON(200, "Hello EGO")
         return
      })
      return server
   }()).Run(); err != nil {
      elog.Panic("startup", elog.FieldErr(err))
   }
}

使用命令行运行

export EGO_DEBUG=true # 默认日志输出到logs目录,开启dev后日志输出到终端
go run main.go --config=config.toml

如下所示

图片

这个时候我们可以发送一个指令,得到如下结果

➜  helloworld git:(master) ✗ curl http://127.0.0.1:9001/hello
"Hello Ego"%  

更加友好的包编译

使用scripts文件夹里的包编译,可以看到优雅的version提示

图片

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(options ...Option) *ego

New new ego

Types

type Option

type Option func(a *ego)

func WithAfterStopClean

func WithAfterStopClean(fns ...func() error) Option

设置运行后清理

func WithBeforeStopClean

func WithBeforeStopClean(fns ...func() error) Option

设置运行前清理

func WithConfigPrefix

func WithConfigPrefix(configPrefix string) Option

func WithDisableBanner

func WithDisableBanner(disableBanner bool) Option

func WithHang

func WithHang(flag bool) Option

是否允许系统悬挂起来,0 表示不悬挂, 1 表示悬挂。目的是一些脚本操作的时候,不想主线程停止

func WithShutdownSignal added in v0.3.0

func WithShutdownSignal(signals ...os.Signal) Option

func WithStopTimeout added in v0.3.0

func WithStopTimeout(timeout time.Duration) Option

Jump to

Keyboard shortcuts

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