-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Faiz Jazadi <[email protected]>
- Loading branch information
Showing
9 changed files
with
111 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module codeberg.org/fj/lcat.dev | ||
|
||
go 1.19 | ||
|
||
require github.com/mattn/go-sqlite3 v1.14.18 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/mattn/go-sqlite3 v1.14.18 h1:JL0eqdCOq6DJVNPSvArO/bIV9/P7fbGrV00LZHc+5aI= | ||
github.com/mattn/go-sqlite3 v1.14.18/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
package constants | ||
|
||
const ( | ||
DefaultListenAddr = ":8080" | ||
DefaultListenAddr = ":8080" | ||
DefaultTemplatesDir = "web" | ||
DefaultDatabasePath = "db.sqlite3" | ||
DefaultDebug = false | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package views | ||
|
||
import ( | ||
"html/template" | ||
"path" | ||
) | ||
|
||
const Index = "index" | ||
|
||
type Manager struct { | ||
templates map[string]*template.Template | ||
templatesDir string | ||
alwaysCompile bool | ||
} | ||
|
||
func NewManager(templatesDir string, alwaysCompile bool) *Manager { | ||
t := new(Manager) | ||
t.templates = make(map[string]*template.Template) | ||
t.templatesDir = templatesDir | ||
t.alwaysCompile = alwaysCompile | ||
t.compile() | ||
return t | ||
} | ||
|
||
func (t *Manager) templateFilename(filename string) string { | ||
return path.Join(t.templatesDir, filename) | ||
} | ||
|
||
func (t *Manager) compile() { | ||
t.templates[Index] = template.Must(template.ParseFiles(t.templateFilename("index.html"))) | ||
} | ||
|
||
func (t *Manager) Get(name string) *template.Template { | ||
if t.alwaysCompile { | ||
t.compile() | ||
} | ||
return t.templates[name] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters