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.

data.go 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package middleware
  4. import (
  5. "context"
  6. "time"
  7. "code.gitea.io/gitea/modules/setting"
  8. )
  9. // ContextDataStore represents a data store
  10. type ContextDataStore interface {
  11. GetData() ContextData
  12. }
  13. type ContextData map[string]any
  14. func (ds ContextData) GetData() ContextData {
  15. return ds
  16. }
  17. func (ds ContextData) MergeFrom(other ContextData) ContextData {
  18. for k, v := range other {
  19. ds[k] = v
  20. }
  21. return ds
  22. }
  23. const ContextDataKeySignedUser = "SignedUser"
  24. type contextDataKeyType struct{}
  25. var contextDataKey contextDataKeyType
  26. func WithContextData(c context.Context) context.Context {
  27. return context.WithValue(c, contextDataKey, make(ContextData, 10))
  28. }
  29. func GetContextData(c context.Context) ContextData {
  30. if ds, ok := c.Value(contextDataKey).(ContextData); ok {
  31. return ds
  32. }
  33. return nil
  34. }
  35. func CommonTemplateContextData() ContextData {
  36. return ContextData{
  37. "IsLandingPageHome": setting.LandingPageURL == setting.LandingPageHome,
  38. "IsLandingPageExplore": setting.LandingPageURL == setting.LandingPageExplore,
  39. "IsLandingPageOrganizations": setting.LandingPageURL == setting.LandingPageOrganizations,
  40. "ShowRegistrationButton": setting.Service.ShowRegistrationButton,
  41. "ShowMilestonesDashboardPage": setting.Service.ShowMilestonesDashboardPage,
  42. "ShowFooterVersion": setting.Other.ShowFooterVersion,
  43. "DisableDownloadSourceArchives": setting.Repository.DisableDownloadSourceArchives,
  44. "EnableSwagger": setting.API.EnableSwagger,
  45. "EnableOpenIDSignIn": setting.Service.EnableOpenIDSignIn,
  46. "PageStartTime": time.Now(),
  47. "RunModeIsProd": setting.IsProd,
  48. }
  49. }