Created
February 14, 2019 02:16
-
-
Save bsdelf/a9600071803559f416611f1e1c8154b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"fmt" | |
"net/http" | |
"github.com/gin-gonic/gin" | |
"github.com/kataras/iris" | |
"github.com/astaxie/beego" | |
"github.com/astaxie/beego/context" | |
) | |
// wrk -t10 -c100 -d15s http://localhost:8080/ping | |
func main() { | |
if len(os.Args) != 2 { | |
fmt.Println("Usage:", os.Args[0], "<framework>") | |
return | |
} | |
switch os.Args[1] { | |
case "gin": { | |
gin.SetMode(gin.ReleaseMode) | |
gin.DisableConsoleColor() | |
engine := gin.New() | |
engine.GET("/ping", func(c *gin.Context) { | |
c.JSON(http.StatusOK, gin.H{"data": "pong"}) | |
}) | |
engine.Run(":8080") | |
} | |
case "iris": { | |
app := iris.New() | |
app.Get("/ping", func(ctx iris.Context) { | |
ctx.JSON(iris.Map{"data": "pong"}) | |
}) | |
app.Run(iris.Addr(":8080")) | |
} | |
case "beego": { | |
beego.BConfig.RunMode = "prod" | |
beego.Get("/ping", func(ctx *context.Context) { | |
ctx.Output.JSON(map[string]string{"data": "pong"}, false, true) | |
}) | |
beego.Run(":8080") | |
} | |
default: { | |
fmt.Println("Unknown framework") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment