func main() { flag.Parse() iris.Use(logger.New(iris.Logger())) iris.Use(cors.DefaultCors()) iris.Get("/", controller.Index) iris.Get("/course/:courseID/:lessonID", controller.GetCourse) iris.Post("/submit/:classID/:courseID/:lessonID/:qn", controller.SubmitCode) fmt.Printf("listen on %s\n", *port) iris.Listen(*port) }
func main() { // register global middleware, you can pass more than one handler comma separated iris.UseFunc(func(c *iris.Context) { fmt.Println("(1)Global logger: %s", c.PathString()) c.Next() }) // register a global structed iris.Handler as middleware myglobal := MyGlobalMiddlewareStructed{loggerId: "my logger id"} iris.Use(myglobal) // register route's middleware iris.Get("/home", func(c *iris.Context) { fmt.Println("(1)HOME logger for /home") c.Next() }, func(c *iris.Context) { fmt.Println("(2)HOME logger for /home") c.Next() }, func(c *iris.Context) { c.Write("Hello from /home") }) println("Iris is listening on :8080") iris.Listen("8080") }
func main() { iris.Use(recovery.Handler) iris.Get("/", func(ctx *iris.Context) { ctx.Write("Hi, let's panic") panic("Don't worry, be happy!!") }) iris.Listen(":8000") }
func main() { // set the global middlewares iris.Use(logger.New()) // register the routes & the public API registerAPI() // start the server iris.Listen("127.0.0.1:8080") }
func main() { iris.Use(utils.NewIrisRecoverMiddleware(&logger.DefaultLogger{})) iris.Listen(fmt.Sprintf(`:%s`, config.GetAPIPort())) }