various things
This commit is contained in:
parent
53f6d75fc1
commit
95fecdb9db
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.vscode
|
41
cmd/server/main.go
Normal file
41
cmd/server/main.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"git.home.dutchellie.nl/DutchEllie/proper-website-2/internal/pages"
|
||||||
|
"git.home.dutchellie.nl/DutchEllie/proper-website-2/internal/templatelib"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
port := os.Getenv("SRV_PORT")
|
||||||
|
if port == "" {
|
||||||
|
msg := `Website writen in Go!
|
||||||
|
|
||||||
|
Please include all the proper environment variables:
|
||||||
|
- "SRV_PORT" <number of the exposing port>
|
||||||
|
`
|
||||||
|
fmt.Println(msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
address := ":" + port
|
||||||
|
|
||||||
|
lib, err := templatelib.NewTemplateLibrary("../../website/templates")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
router, _ := setupRouter(lib)
|
||||||
|
|
||||||
|
router.Run(address)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupRouter(lib templatelib.TemplateLibrary) (*gin.Engine, error) {
|
||||||
|
router := gin.Default()
|
||||||
|
|
||||||
|
pages.RegisterHandlers(router.Group("/"), pages.NewService(pages.NewRepository(&lib)))
|
||||||
|
return router, nil
|
||||||
|
}
|
22
go.mod
Normal file
22
go.mod
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
module git.home.dutchellie.nl/DutchEllie/proper-website-2
|
||||||
|
|
||||||
|
go 1.17
|
||||||
|
|
||||||
|
require github.com/gin-gonic/gin v1.7.7
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
|
github.com/go-playground/locales v0.13.0 // indirect
|
||||||
|
github.com/go-playground/universal-translator v0.17.0 // indirect
|
||||||
|
github.com/go-playground/validator/v10 v10.4.1 // indirect
|
||||||
|
github.com/golang/protobuf v1.3.3 // indirect
|
||||||
|
github.com/json-iterator/go v1.1.9 // indirect
|
||||||
|
github.com/leodido/go-urn v1.2.0 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.12 // indirect
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
|
||||||
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 // indirect
|
||||||
|
github.com/ugorji/go/codec v1.1.7 // indirect
|
||||||
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.2.8 // indirect
|
||||||
|
)
|
54
go.sum
Normal file
54
go.sum
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
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/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||||
|
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||||
|
github.com/gin-gonic/gin v1.7.7 h1:3DoBmSbJbZAWqXJC3SLjAPfutPJJRN1U5pALB7EeTTs=
|
||||||
|
github.com/gin-gonic/gin v1.7.7/go.mod h1:axIBovoeJpVj8S3BwE0uPMTeReE4+AfFtqpqaZ1qq1U=
|
||||||
|
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
|
||||||
|
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
|
||||||
|
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
|
||||||
|
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
|
||||||
|
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
|
||||||
|
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
|
||||||
|
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
|
||||||
|
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
|
||||||
|
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
|
||||||
|
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||||
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
|
||||||
|
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
|
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
|
||||||
|
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
|
||||||
|
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||||
|
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
|
||||||
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
|
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||||
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
|
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
|
||||||
|
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
||||||
|
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
|
||||||
|
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
|
||||||
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
|
||||||
|
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||||
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
24
internal/pages/repository.go
Normal file
24
internal/pages/repository.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package pages
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"html/template"
|
||||||
|
|
||||||
|
"git.home.dutchellie.nl/DutchEllie/proper-website-2/internal/templatelib"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Repository interface {
|
||||||
|
Page(ctx context.Context, name string) (*template.Template, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewRepository(lib *templatelib.TemplateLibrary) Repository {
|
||||||
|
return repository{lib}
|
||||||
|
}
|
||||||
|
|
||||||
|
type repository struct {
|
||||||
|
library *templatelib.TemplateLibrary
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r repository) Page(ctx context.Context, name string) (*template.Template, error) {
|
||||||
|
return r.library.Templates[name], nil
|
||||||
|
}
|
26
internal/pages/routes.go
Normal file
26
internal/pages/routes.go
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
package pages
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RegisterHandlers(r *gin.RouterGroup, service Service) {
|
||||||
|
res := resource{service}
|
||||||
|
|
||||||
|
r.GET("/index", res.getindex)
|
||||||
|
}
|
||||||
|
|
||||||
|
type resource struct {
|
||||||
|
service Service
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r resource) getindex(c *gin.Context) {
|
||||||
|
page, err := r.service.Page(c.Request.Context(), "index")
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatus(http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
page.template.Execute(c.Writer, nil)
|
||||||
|
}
|
31
internal/pages/service.go
Normal file
31
internal/pages/service.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package pages
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"html/template"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Service interface {
|
||||||
|
Page(ctx context.Context, name string) (Page, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Page struct {
|
||||||
|
template *template.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
type service struct {
|
||||||
|
repository Repository
|
||||||
|
//logger log.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewService(r Repository) Service {
|
||||||
|
return service{r}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s service) Page(ctx context.Context, name string) (Page, error) {
|
||||||
|
page, err := s.repository.Page(ctx, name)
|
||||||
|
if err != nil {
|
||||||
|
return Page{}, err
|
||||||
|
}
|
||||||
|
return Page{page}, nil
|
||||||
|
}
|
46
internal/templatelib/library.go
Normal file
46
internal/templatelib/library.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package templatelib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"html/template"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TemplateLibrary struct {
|
||||||
|
Templates map[string]*template.Template
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTemplateLibrary(dir string) (TemplateLibrary, error) {
|
||||||
|
t := make(map[string]*template.Template)
|
||||||
|
|
||||||
|
pages, err := filepath.Glob(filepath.Join(dir, "*.page.tmpl"))
|
||||||
|
if err != nil {
|
||||||
|
return TemplateLibrary{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, page := range pages {
|
||||||
|
name := filepath.Base(page)
|
||||||
|
ts, err := template.ParseFiles(page)
|
||||||
|
if err != nil {
|
||||||
|
return TemplateLibrary{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the ParseGlob method to add any 'layout' templates to the
|
||||||
|
// template set (in our case, it's just the 'base' layout at the
|
||||||
|
// moment).
|
||||||
|
ts, err = ts.ParseGlob(filepath.Join(dir, "*.layout.tmpl"))
|
||||||
|
if err != nil {
|
||||||
|
return TemplateLibrary{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the ParseGlob method to add any 'partial' templates to the
|
||||||
|
// template set (in our case, it's just the 'footer' partial at the
|
||||||
|
// moment).
|
||||||
|
ts, err = ts.ParseGlob(filepath.Join(dir, "*.partial.tmpl"))
|
||||||
|
if err != nil {
|
||||||
|
return TemplateLibrary{}, err
|
||||||
|
}
|
||||||
|
t[name] = ts
|
||||||
|
}
|
||||||
|
|
||||||
|
return TemplateLibrary{Templates: t}, nil
|
||||||
|
}
|
30
test-website/base.html
Normal file
30
test-website/base.html
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link rel="stylesheet" href="static/style.css">
|
||||||
|
<link rel="stylesheet" href="anisha.css?family=anisha">
|
||||||
|
<title>Index</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="header">
|
||||||
|
Internetica Galactica
|
||||||
|
</div>
|
||||||
|
<div class="main">
|
||||||
|
<div class="navbar">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="content">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
<!-- After you're done, find a way to credit the graphics creators!
|
||||||
|
https://dokodemo.neocities.org/materials/index.html BACKGROUND
|
||||||
|
https://dokodemo.neocities.org/
|
||||||
|
https://neo-neighborhoods.neocities.org/SiliconValley/6603/ COOL SHIT
|
||||||
|
https://fontcity.neocities.org/ FOR THE FONT-->
|
1
test-website/static/anisha.css
Normal file
1
test-website/static/anisha.css
Normal file
File diff suppressed because one or more lines are too long
BIN
test-website/static/images/008.gif
Normal file
BIN
test-website/static/images/008.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.4 KiB |
BIN
test-website/static/images/background_star.gif
Normal file
BIN
test-website/static/images/background_star.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.7 KiB |
20
test-website/static/style.css
Normal file
20
test-website/static/style.css
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
html {
|
||||||
|
background-image: url(images/background_star.gif);
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
width: 900px;
|
||||||
|
position: relative;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
color:aliceblue;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
border: 3px solid;
|
||||||
|
border-radius: 4px;
|
||||||
|
border-color: rgb(252, 230, 255);
|
||||||
|
background-color: rgb(54, 39, 48);
|
||||||
|
font-size: 5em;
|
||||||
|
font-family: anisha;
|
||||||
|
}
|
16
website/templates/base.layout.tmpl
Normal file
16
website/templates/base.layout.tmpl
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
{{ define "base" }}
|
||||||
|
<!doctype html>
|
||||||
|
<html lang='en'>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||||
|
<title>{{template "title" .}}</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<h1></h1>
|
||||||
|
</header>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
|
||||||
|
{{ end }}
|
0
website/templates/index.page.tmpl
Normal file
0
website/templates/index.page.tmpl
Normal file
Loading…
Reference in New Issue
Block a user