mirror of
https://github.com/mainnika/nikita-tokarch-uk.git
synced 2026-05-25 01:03:35 +00:00
Move templates to an internal package
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
!cmd
|
!cmd
|
||||||
!nginx
|
!nginx
|
||||||
!pkg
|
!pkg
|
||||||
|
!templates
|
||||||
!web
|
!web
|
||||||
!go.mod
|
!go.mod
|
||||||
!go.sum
|
!go.sum
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ RUN dnf install -yq golang
|
|||||||
|
|
||||||
COPY go.mod .
|
COPY go.mod .
|
||||||
COPY go.sum .
|
COPY go.sum .
|
||||||
|
COPY templates/go.mod templates/go.mod
|
||||||
|
COPY templates/go.sum templates/go.sum
|
||||||
|
|
||||||
RUN --mount=type=cache,id=gopath,target=${GOPATH} \
|
RUN --mount=type=cache,id=gopath,target=${GOPATH} \
|
||||||
go mod \
|
go mod \
|
||||||
@@ -18,6 +20,7 @@ ARG APP_VERSION=containerized
|
|||||||
|
|
||||||
COPY cmd cmd
|
COPY cmd cmd
|
||||||
COPY pkg pkg
|
COPY pkg pkg
|
||||||
|
COPY templates templates
|
||||||
|
|
||||||
RUN --mount=type=cache,id=gopath,target=${GOPATH} \
|
RUN --mount=type=cache,id=gopath,target=${GOPATH} \
|
||||||
go build \
|
go build \
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
|
|
||||||
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/templates"
|
||||||
|
|
||||||
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/config"
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/config"
|
||||||
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/ghost/v4api/httpclient"
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/ghost/v4api/httpclient"
|
||||||
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/routes"
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/routes"
|
||||||
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/templates"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "nightly"
|
var Version = "nightly"
|
||||||
@@ -52,7 +53,7 @@ func main() {
|
|||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
templateFuncs := &templates.Funcs{Version: Version, Site: config.Site}
|
templateFuncs := &templates.Funcs{Version: Version, YandexKey: config.Site.YandexKey}
|
||||||
err = templates.Load(templateFuncs)
|
err = templates.Load(templateFuncs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ module code.tokarch.uk/mainnika/nikita-tokarch-uk
|
|||||||
|
|
||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
|
replace code.tokarch.uk/mainnika/nikita-tokarch-uk/templates => ./templates
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
code.tokarch.uk/mainnika/nikita-tokarch-uk/templates v0.0.0-00010101000000-000000000000
|
||||||
github.com/jackwhelpton/fasthttp-routing/v2 v2.0.0
|
github.com/jackwhelpton/fasthttp-routing/v2 v2.0.0
|
||||||
github.com/mailru/easyjson v0.7.7
|
github.com/mailru/easyjson v0.7.7
|
||||||
github.com/sirupsen/logrus v1.8.1
|
github.com/sirupsen/logrus v1.8.1
|
||||||
|
|||||||
+2
-1
@@ -6,9 +6,10 @@ import (
|
|||||||
routing "github.com/jackwhelpton/fasthttp-routing/v2"
|
routing "github.com/jackwhelpton/fasthttp-routing/v2"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
|
|
||||||
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/templates"
|
||||||
|
|
||||||
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/content"
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/content"
|
||||||
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/ghost/params"
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/ghost/params"
|
||||||
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/templates"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// relativeRedirectBytes makes a relative redirect by using http Location header
|
// relativeRedirectBytes makes a relative redirect by using http Location header
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
routing "github.com/jackwhelpton/fasthttp-routing/v2"
|
routing "github.com/jackwhelpton/fasthttp-routing/v2"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
|
|
||||||
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/templates"
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/templates"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ routing.DataWriter = (*TemplateWriter)(nil)
|
var _ routing.DataWriter = (*TemplateWriter)(nil)
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ import (
|
|||||||
routing "github.com/jackwhelpton/fasthttp-routing/v2"
|
routing "github.com/jackwhelpton/fasthttp-routing/v2"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
|
|
||||||
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/templates"
|
||||||
|
|
||||||
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/config"
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/config"
|
||||||
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/ghost"
|
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/ghost"
|
||||||
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/templates"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Routes is the main handler that contains all routes handlers
|
// Routes is the main handler that contains all routes handlers
|
||||||
|
|||||||
@@ -4,13 +4,12 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"code.tokarch.uk/mainnika/nikita-tokarch-uk/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Funcs struct {
|
type Funcs struct {
|
||||||
Version string
|
Version string
|
||||||
Site config.Site
|
|
||||||
|
YandexKey string
|
||||||
|
|
||||||
compiledJSAppURL string
|
compiledJSAppURL string
|
||||||
|
|
||||||
@@ -58,7 +57,7 @@ func (f *Funcs) getBlogURL() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *Funcs) getYaKey() string {
|
func (f *Funcs) getYaKey() string {
|
||||||
return f.Site.YandexKey
|
return f.YandexKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use returns a func map with template helpers functions
|
// Use returns a func map with template helpers functions
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
module code.tokarch.uk/mainnika/nikita-tokarch-uk/templates
|
||||||
|
|
||||||
|
go 1.17
|
||||||
|
|
||||||
|
require github.com/sirupsen/logrus v1.8.1
|
||||||
|
|
||||||
|
require golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||||
|
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
|
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
|
||||||
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@@ -21,10 +21,10 @@ import (
|
|||||||
//go:embed analytics.go.tmpl
|
//go:embed analytics.go.tmpl
|
||||||
var content embed.FS
|
var content embed.FS
|
||||||
|
|
||||||
// List of compiled go-templates
|
// Templates is a container of compiled templates
|
||||||
var Templates *template.Template = template.New("")
|
var Templates *template.Template = template.New("")
|
||||||
|
|
||||||
// Load embeded templates
|
// Load embedded templates
|
||||||
func Load(funcs *Funcs) (err error) {
|
func Load(funcs *Funcs) (err error) {
|
||||||
|
|
||||||
Templates.Funcs(funcs.Use())
|
Templates.Funcs(funcs.Use())
|
||||||
Reference in New Issue
Block a user