快速开始

    创建项目

    1. import (
    2. "github.com/gin-gonic/gin"
    3. "github.com/gotomicro/ego/core/elog"
    4. "github.com/gotomicro/ego/server/egin"
    5. )
    6. func main() {
    7. if err := ego.New().Serve(func() *egin.Component {
    8. server := egin.Load("server.http").Build()
    9. server.GET("/hello", func(ctx *gin.Context) {
    10. ctx.JSON(200, "Hello Ego")
    11. return
    12. }()).Run(); err != nil {
    13. elog.Panic("startup", elog.Any("err", err))
    14. }
    15. }
    • 在项目中增加config.toml配置文件,内容如下
    1. [server.http]
    2. port = 9001
    3. host = "0.0.0.0"