You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.2KB

  1. package main
  2. import (
  3. "time"
  4. "github.com/kataras/iris/v12"
  5. "github.com/kataras/iris/v12/mvc"
  6. )
  7. // Optional deprecated X-API-XXX headers for version 1.
  8. var opts = mvc.DeprecationOptions{
  9. WarnMessage: "deprecated, see <this link>",
  10. DeprecationDate: time.Now().UTC(),
  11. DeprecationInfo: "a bigger version is available, see <this link> for more information",
  12. }
  13. func main() {
  14. app := newApp()
  15. // See main_test.go for request examples.
  16. app.Listen(":8080")
  17. }
  18. func newApp() *iris.Application {
  19. app := iris.New()
  20. dataRouter := app.Party("/data")
  21. {
  22. m := mvc.New(dataRouter)
  23. m.Handle(new(v1Controller), mvc.Version("1.0.0"), mvc.Deprecated(opts))
  24. m.Handle(new(v2Controller), mvc.Version("2.3.0"))
  25. m.Handle(new(v3Controller), mvc.Version(">=3.0.0 <4.0.0"))
  26. m.Handle(new(noVersionController)) // or if missing it will respond with 501 version not found.
  27. }
  28. return app
  29. }
  30. type v1Controller struct{}
  31. func (c *v1Controller) Get() string {
  32. return "data (v1.x)"
  33. }
  34. type v2Controller struct{}
  35. func (c *v2Controller) Get() string {
  36. return "data (v2.x)"
  37. }
  38. type v3Controller struct{}
  39. func (c *v3Controller) Get() string {
  40. return "data (v3.x)"
  41. }
  42. type noVersionController struct{}
  43. func (c *noVersionController) Get() string {
  44. return "data"
  45. }