mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 18:37:05 +00:00
Add a simple Caddy+Iris tutorial 👍
Former-commit-id: 8761afce72aa35b91c9b5a958f1cafc027aabddd
This commit is contained in:
56
_examples/tutorial/caddy/server2/main.go
Normal file
56
_examples/tutorial/caddy/server2/main.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
app := iris.New()
|
||||
|
||||
app.Controller("/user", new(UserController))
|
||||
|
||||
// GET http://localhost:9092/user
|
||||
// GET http://localhost:9092/user/42
|
||||
// POST http://localhost:9092/user
|
||||
// PUT http://localhost:9092/user/42
|
||||
// DELETE http://localhost:9092/user/42
|
||||
// GET http://localhost:9092/user/followers/42
|
||||
app.Run(iris.Addr(":9092"))
|
||||
}
|
||||
|
||||
// UserController is our user example controller.
|
||||
type UserController struct {
|
||||
iris.Controller
|
||||
}
|
||||
|
||||
// Get handles GET /user
|
||||
func (c *UserController) Get() {
|
||||
c.Ctx.Writef("Select all users")
|
||||
}
|
||||
|
||||
// GetBy handles GET /user/42
|
||||
func (c *UserController) GetBy(id int) {
|
||||
c.Ctx.Writef("Select user by ID: %d", id)
|
||||
}
|
||||
|
||||
// Post handles POST /user
|
||||
func (c *UserController) Post() {
|
||||
username := c.Ctx.PostValue("username")
|
||||
c.Ctx.Writef("Create by user with username: %s", username)
|
||||
}
|
||||
|
||||
// PutBy handles PUT /user/42
|
||||
func (c *UserController) PutBy(id int) {
|
||||
c.Ctx.Writef("Update user by ID: %d", id)
|
||||
}
|
||||
|
||||
// DeleteBy handles DELETE /user/42
|
||||
func (c *UserController) DeleteBy(id int) {
|
||||
c.Ctx.Writef("Delete user by ID: %d", id)
|
||||
}
|
||||
|
||||
// GetFollowersBy handles GET /user/followers/42
|
||||
func (c *UserController) GetFollowersBy(id int) {
|
||||
c.Ctx.Writef("Select all followers by user ID: %d", id)
|
||||
}
|
||||
Reference in New Issue
Block a user