diff --git a/README.md b/README.md index f8c73d0..8a6cf8a 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,16 @@ Repo del server del nuovo sito per il PHC. +### Setup + +Per clonare il progetto usare + +```bash +$ git clone --recursive https://github.com/phc-dm/server-poisson +``` + +L'opzione `--recursive` serve a clonare anche il sottomodule relativo al blog del sito, si può anche omettere però non sarà disponibile la visualizzazione del blog in fase di development. + ## Development Copiare il file `.env.dev` in `.env` per dire al server di lavorare in modalità di development e su quale indirizzo servire il sito. Per avviare il server basta fare @@ -10,3 +20,18 @@ Copiare il file `.env.dev` in `.env` per dire al server di lavorare in modalità go run . ``` +### Environment Variables + +- `MODE` + + Può essere `production` (default) o `development`. + +- `HOST` + + Indirizzo (locale) sul quale servire il sito, di default è `localhost:8000`. + +- `_URL` + + Rappresentano link ad altri servizi forniti, è comodo impostarli così in modo da poter anche provare tutto insieme in locale su varie porte (e poi in produzione i vari url diventano link a sotto-domini del sito principale). + + Per ora ci sono solo `GIT_URL` e `FORUM_URL`. diff --git a/assets/icons/icons8-electronics-100.png b/assets/icons/icons8-electronics-100.png index 0ff2511..2594df4 100644 Binary files a/assets/icons/icons8-electronics-100.png and b/assets/icons/icons8-electronics-100.png differ diff --git a/assets/style.css b/assets/style.css index c7667d6..826ad0c 100644 --- a/assets/style.css +++ b/assets/style.css @@ -5,136 +5,481 @@ /* @import url('https://fonts.googleapis.com/css2?family=Sen&family=Work+Sans:wght@700&display=swap'); */ :root { - --accent-1: royalblue; + --font-title: 'Share', cursive; + --font-text: 'Ubuntu', sans-serif; + --font-mono: 'Ubuntu Mono', monospace; } * { box-sizing: border-box; } -html { - position: relative; -} - html, body { + position: relative; + margin: 0; - min-height: 100vh; - display: flex; - flex-direction: column; + min-height: 100%; - font-family: 'Ubuntu', sans-serif; + width: 100vw; + overflow-x: hidden; + + font-family: var(--font-text); font-weight: 300; font-size: 17px; line-height: 1.25; } +html { + background: white; + + height: 100%; + min-height: 100%; +} + +body { + margin: 0 auto; + padding-bottom: 5rem; + + max-width: 850px; + text-align: justify; + + background: white; +} + +/* Typography */ + h1, h2, h3, h4 { - font-family: 'Share', cursive; + margin: 0; + + font-family: var(--font-title); font-weight: 700; } -a, a:focus, a:visited { - color: #666; - text-decoration: #aaa underline; - padding: 1px 2px; - border-radius: 2px; +p { + margin: 0.75rem 0; } -a:hover { - background: var(--accent-1); - color: white; +p:last-child { + margin-bottom: 0; } -body { - max-width: 100%; - width: 50rem; - margin: 0 auto; - padding: 0 0.5rem; - overflow-y: scroll; -} +/* Elements */ nav { + margin-bottom: 1rem; + display: flex; - align-items: center; - border-bottom: 1px solid #ddd; flex-wrap: wrap; + + border: 4px solid; + border-top: none; + + gap: 2px; + /* border-bottom: 1rem solid black; */ } -.hfill { +.nav-item { flex-grow: 1; + + display: flex; + align-items: center; + justify-content: center; + + height: 2.5rem; + + padding: 0 0.75rem; + margin: -2px; + + font-size: 130%; + font-weight: bold; + + border: 2px solid black; } -.vfill { +.nav-dropdown { flex-grow: 1; + margin: -2px; + + max-width: 100%; + + display: flex; + flex-direction: column; + position: relative; + + z-index: 1; } -.news-list { +.nav-dropdown .label { display: flex; + align-items: center; + justify-content: center; + + width: 100%; + + height: 2.5rem; + + padding: 0 0.75rem; + + font-size: 130%; + font-weight: bold; + + border: 2px solid black; } -.news-list > article { - margin: 1rem; +.nav-dropdown .label .icons8 { + width: 16px; + height: 16px; + + margin-left: 0.5rem; + transform: translate(0, 0.1rem); } -.nav-item:first-child { - font-size: 25px; +.nav-dropdown .dropdown { + position: absolute; + + top: 100%; + width: 100%; + /* margin-bottom: 0.5rem; */ + + display: flex; + flex-direction: column; + + gap: 2px; + + border: 2px solid black; + + background: white; } -.nav-item { - font-family: 'Share', cursive; - font-weight: 700; +.nav-dropdown:not(:hover) .dropdown { + display: none; +} - font-size: 21px; +nav a { + text-decoration: none; } -.nav-item:hover { - background: #f0f0f0; +section { + border: 4px solid; + + padding: 1rem; + margin-bottom: 1rem; } -.nav-item a, .nav-item a:focus, .nav-item a:visited { +header { display: flex; - align-items: center; + width: 100%; justify-content: center; - padding: 0 0.75rem; - height: 3.25rem; + margin: 2.5rem 0; +} + +header .logo { + flex-grow: 1; - color: black; + margin-right: 1rem; + object-fit: contain; + object-position: right; +} + +header .title { + flex-grow: 1; + + display: flex; + flex-direction: column; + justify-content: space-around; +} + +header .title h1 { + font-size: 56px; + display: inline-block; + transform: translate(-0.125rem); +} + +.service-list { + display: flex; + flex-wrap: wrap; + + gap: 0.5rem; +} + +.service { + flex: 1 1 calc(50% - 1rem); + min-width: 300px; + + padding: 1rem 0.75rem; + + /* Brutal */ + border: 2px solid black; +} + +.user-list { + display: flex; + flex-direction: row; + flex-wrap: wrap; + + justify-content: center; + + gap: 0.25rem; +} + +.user { + display: flex; + flex-grow: 1; + + width: calc(50% - 0.25rem / 2); + min-width: 250px; + + align-items: center; + justify-content: space-between; + + padding: 0.125rem 0.25rem; + + border: 2px solid black; +} + +.user h4 { + font-size: 90%; + line-height: 1; + font-family: var(--font-mono); +} + +.user a { text-decoration: none; } -body > div:last-of-type { - margin-bottom: 20rem; +.user a:hover img { + opacity: 0.6; +} + +.user img { + margin: 0.5rem; } footer { position: absolute; bottom: 0; left: 0; + right: 0; + + display: flex; + flex-wrap: wrap; + + align-items: center; + justify-content: center; + + background: black; + color: white; + + border-bottom: none; +} + +footer a, footer a:visited { + color: white; +} + +.footer-item { + padding: 0.5rem; + font-size: 90%; +} + +.search { + display: flex; + align-items: center; + + max-width: 27rem; + margin: 1.5rem auto; + + border: 2px solid black; +} + +#search-field { width: 100%; - height: 3rem; + flex-grow: 1; + + height: 1.75rem; + padding: 0 0.5rem; + + border: none; + border-right: 2px solid black; +} + +.search img { + display: block; + transform: scale(0.8); + + width: 1.75rem; + height: 1.75rem; + + cursor: pointer; +} + +/* Common */ + +img { + display: block; +} + +a, a:visited { + color: black; +} + +a:hover { + color: gray; +} + +hr { + width: 100%; + height: 1rem; + + margin: 1rem 0; + padding: 0; + background: black; + border: none; +} + +ul { + list-style: square; +} + +li { + margin: 0.25rem 0; +} + +form { + margin: 3rem auto; + padding: 0.75rem; + + max-width: 30rem; + border: 4px solid black; +} + +form .row { display: flex; + width: 100%; +} + +form .row:not(:last-child) { + margin-bottom: 0.5rem; +} + +form label { + width: 30%; +} + +form input[type=text], form input[type=password] { + flex-grow: 1; +} + +form button, form input[type=submit] { + margin-top: 0.5rem; +} + +input[type=text], input[type=password] { + font-size: 15px; + + padding: 0 0.2rem; + height: 1.5rem; + + appearance: none; + outline: none; + + border: 2px solid black; +} + +input[type=text]:focus, input[type=password]:focus { + background: #e0e0e0; +} + +button, input[type=submit] { + outline: none; - align-items: center; - justify-content: center; - border-top: 1px solid #ddd; + font-size: 17px; + font-family: var(--font-title); + + padding: 0 4rem; + height: 1.6rem; + + background: black; + color: white; + + border: none; + /* border: 2px solid black; */ + + cursor: pointer; +} + +button:hover, input[type=submit]:hover { + background: #444; +} + +/* Utils */ + +.icons8 { + width: 25px; + height: 25px; + + display: inline-block; + vertical-align: middle; } -.footer-item:not(:last-child)::after { - content: '•'; - margin: 0 1rem; +h2 .icons8 { + transform: translateY(-0.125rem); } -@media screen and (max-width: 600px) { +.hfill { + /* min-height: 0.5rem; */ + flex-grow: 1000; +} - body { - width: 100%; - overflow-x: hidden; +@media screen and (max-width: 850px) { + section, nav { + border-left: none; + border-right: none; } +} - .news-list { +@media screen and (max-width: 30rem) { + form { + border-left: none; + border-right: none; + } +} + +/* Large screen */ +@media screen and (min-width: 421px) { + .nav-dropdown .dropdown { + margin-top: -2px; + } +} + +/* Mobile screen */ +@media screen and (max-width: 420px) and (orientation: portrait) { + nav { flex-direction: column; } + + .nav-dropdown:hover { + padding: 0 0.25rem 0.25rem; + } + + .nav-dropdown, .nav-dropdown .nav-item { + margin: -2px 0; + } + + .nav-item, .nav-dropdown .label { + max-width: 100%; + + border-left: none; + border-right: none; + } + + .nav-dropdown .dropdown { + position: relative; + + border: 4px solid black; + border-top-width: 2px; + } } \ No newline at end of file diff --git a/auth.go b/auth.go index 4689664..5da3de5 100644 --- a/auth.go +++ b/auth.go @@ -1,26 +1,16 @@ package main -// User as in auth-poisson -type User struct { - Username string - UID int - - Name string - Surname string - FullName string - - // ... -} +// "github.com/phc-dm/auth-poisson/user" // AuthService rappresenta un servizio di autenticazione -type AuthService interface { - GetUsers() []User +// type AuthService interface { +// GetUsers() []User - GetUser(username string) User +// GetUser(username string) User - // LoginUser if successful returns the token for this user that will be stored in an HTTP cookie. - LoginUser(username, password string) (string, error) -} +// // LoginUser if successful returns the token for this user that will be stored in an HTTP cookie. +// LoginUser(username, password string) (string, error) +// } // LdapService ... type LdapService struct { diff --git a/config.go b/config.go deleted file mode 100644 index 2ca82bf..0000000 --- a/config.go +++ /dev/null @@ -1,47 +0,0 @@ -package main - -import ( - "log" - "os" - "strings" - - "github.com/joho/godotenv" -) - -type Config struct { - Mode string - Host string - - GitUrl string - ForumUrl string -} - -func stringOrDefault(value, defaultValue string) string { - if len(strings.TrimSpace(value)) == 0 { - return defaultValue - } - - return value -} - -func LoadConfig() *Config { - godotenv.Load() - - log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile) - - Mode := stringOrDefault(os.Getenv("MODE"), "production") - log.Printf("MODE = %v", Mode) - - Host := stringOrDefault(os.Getenv("HOST"), "localhost:8080") - log.Printf("HOST = %v", Host) - - GitUrl := stringOrDefault(os.Getenv("GIT_URL"), "git.phc.dm.unipi.it") - log.Printf("GIT_URL = %v", GitUrl) - - ForumUrl := stringOrDefault(os.Getenv("FORUM_URL"), "forum.phc.dm.unipi.it") - log.Printf("FORUM_URL = %v", ForumUrl) - - return &Config{ - Mode, Host, GitUrl, ForumUrl, - } -} diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..ed0ce24 --- /dev/null +++ b/config/config.go @@ -0,0 +1,41 @@ +package config + +import ( + "log" + "os" + "strings" + + "github.com/joho/godotenv" +) + +var Mode string +var Host string + +var GitUrl string +var ForumUrl string + +func stringOrDefault(value, defaultValue string) string { + if len(strings.TrimSpace(value)) == 0 { + return defaultValue + } + + return value +} + +func LoadConfig() { + godotenv.Load() + + log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile) + + Mode = stringOrDefault(os.Getenv("MODE"), "production") + log.Printf("MODE = %v", Mode) + + Host = stringOrDefault(os.Getenv("HOST"), "localhost:8080") + log.Printf("HOST = %v", Host) + + GitUrl = stringOrDefault(os.Getenv("GIT_URL"), "git.phc.dm.unipi.it") + log.Printf("GIT_URL = %v", GitUrl) + + ForumUrl = stringOrDefault(os.Getenv("FORUM_URL"), "forum.phc.dm.unipi.it") + log.Printf("FORUM_URL = %v", ForumUrl) +} diff --git a/go.mod b/go.mod index 4510bb2..046a90b 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,8 @@ -module git.phc.dm.xxxxx.xx/server-poisson +module github.com/phc-dm/server-poisson go 1.13 require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/go-chi/chi/v5 v5.0.7 // indirect - github.com/joho/godotenv v1.4.0 // indirect - github.com/labstack/echo/v4 v4.1.16 + github.com/go-chi/chi/v5 v5.0.7 + github.com/joho/godotenv v1.4.0 ) diff --git a/go.sum b/go.sum index be96117..fa9e443 100644 --- a/go.sum +++ b/go.sum @@ -1,52 +1,4 @@ -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/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8= github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/labstack/echo/v4 v4.1.16 h1:8swiwjE5Jkai3RPfZoahp8kjVCRNq+y7Q0hPji2Kz0o= -github.com/labstack/echo/v4 v4.1.16/go.mod h1:awO+5TzAjvL8XpibdsfXxPgHr+orhtXZJZIQCVjogKI= -github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0= -github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k= -github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE= -github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= -github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= -github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -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.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= -github.com/valyala/fasttemplate v1.1.0 h1:RZqt0yGBsps8NGvLSGW804QQqCUYYLsaOjTVHy1Ocw4= -github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d h1:1ZiEyfaQIg3Qh0EoqpwAakHVhecoE5wlSg5GjnafJGw= -golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/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-20190813064441-fde4db37ae7a/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/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= -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 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/main.go b/main.go index 8d0966f..68a7402 100644 --- a/main.go +++ b/main.go @@ -4,15 +4,15 @@ import ( "log" "net/http" - "git.phc.dm.xxxxx.xx/server-poisson/utils" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" + "github.com/phc-dm/server-poisson/utils" ) type object map[string]interface{} func main() { - config := LoadConfig() + config.LoadConfig() r := chi.NewRouter() @@ -29,7 +29,7 @@ func main() { // Routes r.Get("/", func(w http.ResponseWriter, r *http.Request) { - err := renderer.Render(w, "home.html", object{"Config": config}) + err := renderer.Render(w, "home.html", object{}) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -37,7 +37,7 @@ func main() { }) r.Get("/utenti", func(w http.ResponseWriter, r *http.Request) { - err := renderer.Render(w, "utenti.html", object{"Config": config}) + err := renderer.Render(w, "utenti.html", object{}) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -45,7 +45,7 @@ func main() { }) r.Get("/login", func(w http.ResponseWriter, r *http.Request) { - err := renderer.Render(w, "login.html", object{"Config": config}) + err := renderer.Render(w, "login.html", object{}) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -53,5 +53,5 @@ func main() { }) log.Printf(`Starting server...`) - http.ListenAndServe(config.Host, r) + http.ListenAndServe(Config.Host, r) } diff --git a/screenshots/localhost_8000_home.png b/screenshots/localhost_8000_home.png new file mode 100644 index 0000000..fe16fde Binary files /dev/null and b/screenshots/localhost_8000_home.png differ diff --git a/screenshots/localhost_8000_login.png b/screenshots/localhost_8000_login.png new file mode 100644 index 0000000..46b2b4f Binary files /dev/null and b/screenshots/localhost_8000_login.png differ diff --git a/screenshots/localhost_8000_utenti.png b/screenshots/localhost_8000_utenti.png new file mode 100644 index 0000000..e02a04a Binary files /dev/null and b/screenshots/localhost_8000_utenti.png differ diff --git a/utils/template_renderer.go b/utils/template_renderer.go index f0d187c..44cdfce 100644 --- a/utils/template_renderer.go +++ b/utils/template_renderer.go @@ -2,12 +2,14 @@ package utils import ( "io" - "os" "text/template" + + "github.com/phc-dm/server-poisson/config" ) // TemplateRenderer holds cached templates for rendering type TemplateRenderer struct { + baseFile string baseTemplate *template.Template templateMap map[string]*template.Template } @@ -15,6 +17,7 @@ type TemplateRenderer struct { // NewTemplateRenderer constructs a template renderer with a base file func NewTemplateRenderer(baseFile string) *TemplateRenderer { return &TemplateRenderer{ + baseFile: baseFile, baseTemplate: template.Must(template.ParseFiles("./views/" + baseFile)), templateMap: make(map[string]*template.Template), } @@ -24,8 +27,15 @@ func NewTemplateRenderer(baseFile string) *TemplateRenderer { func (t *TemplateRenderer) Render(w io.Writer, name string, data interface{}) error { tmpl := t.templateMap[name] - if os.Getenv("MODE") == "development" || tmpl == nil { + if config.Mode == "development" || tmpl == nil { tmpl = template.Must(t.baseTemplate.Clone()) + + if config.Mode == "development" { + tmpl = template.Must(template.ParseFiles("./views/" + t.baseFile)) + } else { + tmpl = template.Must(t.baseTemplate.Clone()) + } + tmpl.ParseFiles("./views/" + name) t.templateMap[name] = tmpl } diff --git a/views/base.html b/views/base.html index d2ad353..c6249ff 100644 --- a/views/base.html +++ b/views/base.html @@ -7,9 +7,29 @@ {{ template "title" . }} - - + + + + + + @@ -19,20 +39,46 @@ - - -