added admin page, adjusted way of creating posts
This commit is contained in:
20
utils/admin_hash.go
Normal file
20
utils/admin_hash.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
)
|
||||
|
||||
func LoadAdminHash(path string) string {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
panic("Could not find DSN for database...")
|
||||
}
|
||||
defer file.Close()
|
||||
reader := bufio.NewScanner(file)
|
||||
// The dsn should be the first line of the file
|
||||
if reader.Scan() {
|
||||
return reader.Text()
|
||||
}
|
||||
panic(path + " is empty...")
|
||||
}
|
||||
27
utils/serve_page.go
Normal file
27
utils/serve_page.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Returns a handler function to serve a page based on the template that is inputted
|
||||
func ServePage(temp string) gin.HandlerFunc {
|
||||
title := strings.Split(temp, ".")[0]
|
||||
if title == "index" {
|
||||
// Index is the home page so we don't care
|
||||
title = ""
|
||||
} else {
|
||||
// Else title it accordingly
|
||||
title = " | " + title
|
||||
}
|
||||
return func(c *gin.Context) {
|
||||
c.HTML(
|
||||
http.StatusOK,
|
||||
temp,
|
||||
struct{ Title string }{Title: title},
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user