From 9f4133a0fce1d45f8ad69dea58fab64e25096ca1 Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Thu, 8 Aug 2024 14:42:29 -0600 Subject: [PATCH] Adding server Extend functionality --- core/local.go | 15 +++++++++++++++ server/server.go | 11 +++++++++++ validate/template.go | 5 +++++ 3 files changed, 31 insertions(+) diff --git a/core/local.go b/core/local.go index 6fea1cd..739f792 100644 --- a/core/local.go +++ b/core/local.go @@ -68,3 +68,18 @@ func GetSessionGlobalLocalizer(c echo.Context) *localizer.Localizer { lang := GetLang(c) return localizer.GetGlobal(lang) } + +// PageData holds translations for html template values +type PageData struct { + Title string + Data map[string]string +} + +// NewPageData returns a new PageData instance +func NewPageData(title string) *PageData { + return &PageData{ + Title: title, + Data: make(map[string]string), + } + +} diff --git a/server/server.go b/server/server.go index 2de8c34..3ced1d9 100644 --- a/server/server.go +++ b/server/server.go @@ -61,6 +61,12 @@ func (a *appInfo) Version() string { return a.version } +// Extension is an interface to add on to the Server instance via a 3rd +// party module +type Extension interface { + Extend(gserver *Server) (*Server, error) +} + // GraphQL is a holder for a graphql schema and options type GraphQL struct { Schema graphql.ExecutableSchema @@ -486,6 +492,11 @@ func (s *Server) addDefaultTemplateData() { s.AddStaticVar("BaseURI", s.Config.BaseURI()) } +// Extend will apply the given Extension interface +func (s *Server) Extend(ext Extension) (*Server, error) { + return ext.Extend(s) +} + // WithSchema Adds a GraphQL schema for this server. The second parameter // shall be the list of scopes, as strings, which are supported by this // schema. This function configures routes for the router; all middlewares diff --git a/validate/template.go b/validate/template.go index ce80fcd..6569931 100644 --- a/validate/template.go +++ b/validate/template.go @@ -32,6 +32,11 @@ type ( protect bool allowed []string } + + // TemplateRenderFunc defines a function to render a template. The `code` variable is the + // response status code. The `name` is the template name. The `data` variable should be what + // is passed to the template engine for use inside the templates. + TemplateRenderFunc func(c echo.Context, code int, name string, data interface{}) error ) // NewTemplate returns a *Template instance -- 2.45.2