embed_off.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //go:build !embed
  2. // Package web provides embedded web assets for the application.
  3. package web
  4. import (
  5. "context"
  6. "errors"
  7. "net/http"
  8. "github.com/gin-gonic/gin"
  9. )
  10. // PublicSettingsProvider is an interface to fetch public settings
  11. // This stub is needed for compilation when frontend is not embedded
  12. type PublicSettingsProvider interface {
  13. GetPublicSettingsForInjection(ctx context.Context) (any, error)
  14. }
  15. // FrontendServer is a stub for non-embed builds
  16. type FrontendServer struct{}
  17. // NewFrontendServer returns an error when frontend is not embedded
  18. func NewFrontendServer(settingsProvider PublicSettingsProvider) (*FrontendServer, error) {
  19. return nil, errors.New("frontend not embedded")
  20. }
  21. // InvalidateCache is a no-op for non-embed builds
  22. func (s *FrontendServer) InvalidateCache() {}
  23. // Middleware returns a handler that returns 404 for non-embed builds
  24. func (s *FrontendServer) Middleware() gin.HandlerFunc {
  25. return func(c *gin.Context) {
  26. c.String(http.StatusNotFound, "Frontend not embedded. Build with -tags embed to include frontend.")
  27. c.Abort()
  28. }
  29. }
  30. func ServeEmbeddedFrontend() gin.HandlerFunc {
  31. return func(c *gin.Context) {
  32. c.String(http.StatusNotFound, "Frontend not embedded. Build with -tags embed to include frontend.")
  33. c.Abort()
  34. }
  35. }
  36. func HasEmbeddedFrontend() bool {
  37. return false
  38. }