fix(templates) correcting template directory
This commit is contained in:
7
index.go
7
index.go
@@ -2,8 +2,10 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -17,6 +19,8 @@ import (
|
|||||||
"golang.org/x/oauth2/github"
|
"golang.org/x/oauth2/github"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var templatesFS embed.FS
|
||||||
|
|
||||||
type Link struct {
|
type Link struct {
|
||||||
ID string
|
ID string
|
||||||
OriginalURL string
|
OriginalURL string
|
||||||
@@ -43,6 +47,8 @@ func initialize() (*App, error) {
|
|||||||
oauthConfig := initGithubOAuth()
|
oauthConfig := initGithubOAuth()
|
||||||
|
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
|
tmpl := template.Must(template.ParseFS(templatesFS, "templates/*"))
|
||||||
|
router.SetHTMLTemplate(tmpl)
|
||||||
|
|
||||||
return &App{
|
return &App{
|
||||||
DB: db,
|
DB: db,
|
||||||
@@ -80,7 +86,6 @@ func initGithubOAuth() *oauth2.Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (app *App) SetupRoutes() {
|
func (app *App) SetupRoutes() {
|
||||||
app.Router.LoadHTMLGlob("templates/*")
|
|
||||||
app.Router.Static("/static", "./static")
|
app.Router.Static("/static", "./static")
|
||||||
app.Router.GET("/", app.homePage)
|
app.Router.GET("/", app.homePage)
|
||||||
app.Router.POST("/", app.shortenURL)
|
app.Router.POST("/", app.shortenURL)
|
||||||
|
|||||||
Reference in New Issue
Block a user