-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.go
52 lines (44 loc) · 835 Bytes
/
home.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package handlers
import (
"fmt"
"html/template"
"net/http"
"os"
"github.com/cswank/store/internal/templates"
)
type page struct {
Shopify shopifyAPI
Admin bool
Links []link
Name string
Message string
Head template.HTML
}
type homePage struct {
page
Home template.HTML
}
var (
name = os.Getenv("STORE_NAME")
)
func Home(w http.ResponseWriter, req *http.Request) error {
p := homePage{
page: page{
Links: getNavbarLinks(req),
Admin: Admin(req),
Shopify: shopifyKey,
Name: name,
Head: html["head"],
},
Home: html["home"],
}
return templates.Get("index.html").ExecuteTemplate(w, "base", p)
}
func Redirect(w http.ResponseWriter, req *http.Request) {
http.Redirect(
w,
req,
fmt.Sprintf("https://%s%s", req.Host, req.URL.String()),
http.StatusMovedPermanently,
)
}