example_test.go 740 B

12345678910111213141516171819202122232425262728
  1. package supervisor_test
  2. import (
  3. "go-common/library/net/http/blademaster"
  4. "go-common/library/net/http/blademaster/middleware/supervisor"
  5. "time"
  6. )
  7. // This example create a supervisor middleware instance and attach to a blademaster engine,
  8. // it will allow '/ping' API can be requested with specified policy.
  9. // This example will block all http method except `GET` on '/ping' API in next hour,
  10. // and allow in further.
  11. func Example() {
  12. now := time.Now()
  13. end := now.Add(time.Hour * 1)
  14. spv := supervisor.New(&supervisor.Config{
  15. On: true,
  16. Begin: now,
  17. End: end,
  18. })
  19. engine := blademaster.Default()
  20. engine.Use(spv)
  21. engine.GET("/ping", func(c *blademaster.Context) {
  22. c.String(200, "%s", "pong")
  23. })
  24. engine.Run(":18080")
  25. }