identity.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * @description:
  3. * @Author: CP
  4. * @Date: 2020-08-23 23:09:38
  5. * @FilePath: \construction_management\web\middleware\identity\identity.go
  6. */
  7. package identity
  8. import (
  9. "time"
  10. "github.com/kataras/iris/v12"
  11. "go.mod/bootstrap"
  12. )
  13. // New returns a new handler which adds some headers and view data
  14. // describing the application, i.e the owner, the startup time.
  15. func New(b *bootstrap.Bootstrapper) iris.Handler {
  16. return func(ctx iris.Context) {
  17. // response headers
  18. ctx.Header("App-Name", b.AppName)
  19. ctx.Header("App-Owner", b.AppOwner)
  20. ctx.Header("App-Since", time.Since(b.AppSpawnDate).String())
  21. //ctx.Header("Server", "Iris: https://iris-go.com")
  22. // view data if ctx.View or c.Tmpl = "$page.html" will be called next.
  23. ctx.ViewData("AppName", b.AppName)
  24. ctx.ViewData("AppOwner", b.AppOwner)
  25. ctx.Values().Set("csrf.Form", "csrfToken")
  26. //ctx.ViewData("csrf.Form", "csrfToken")
  27. ctx.Next()
  28. }
  29. }
  30. // Configure creates a new identity middleware and registers that to the app.
  31. func Configure(b *bootstrap.Bootstrapper) {
  32. h := New(b)
  33. b.UseGlobal(h)
  34. }