github.com/volts-dev/volts@v0.0.0-20240120094013-5e9c65924106/demo/web/volts_restful/main.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/volts-dev/volts"
     5  	"github.com/volts-dev/volts/router"
     6  	"github.com/volts-dev/volts/server"
     7  )
     8  
     9  type (
    10  	ctrls struct {
    11  		//这里写中间件
    12  	}
    13  )
    14  
    15  func (action ctrls) Get(hd *router.THttpContext) {
    16  	hd.Info("Middleware")
    17  	hd.Respond([]byte("Middleware"))
    18  }
    19  
    20  func (action ctrls) Post(hd *router.THttpContext) {
    21  	hd.Info("Before")
    22  	hd.Respond([]byte("Before"))
    23  }
    24  
    25  func (action ctrls) delete(hd *router.THttpContext) {
    26  	hd.Info("After")
    27  	hd.Respond([]byte("After"))
    28  }
    29  
    30  func main() {
    31  	r := router.New()
    32  	//r.RegisterMiddleware(event.NewEvent())
    33  	r.Url("REST", "/ctrls", new(ctrls))
    34  
    35  	srv := server.New()
    36  
    37  	// serve as a http server
    38  	app := volts.New(
    39  		volts.Server(srv),
    40  		volts.Debug(),
    41  	)
    42  	app.Run()
    43  }