mirror of
https://github.com/JustKato/FreePad.git
synced 2026-02-24 00:00:46 +02:00
* Basics realized
This commit is contained in:
9
go.mod
9
go.mod
@@ -2,11 +2,4 @@ module github.com/JustKato/FreePad
|
|||||||
|
|
||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
require (
|
require github.com/gin-gonic/gin v1.7.7
|
||||||
github.com/gin-gonic/gin v1.7.7
|
|
||||||
github.com/go-sql-driver/mysql v1.6.0
|
|
||||||
github.com/golang-migrate/migrate/v4 v4.15.2
|
|
||||||
github.com/mattn/go-sqlite3 v1.14.13
|
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
|
|
||||||
github.com/ulule/limiter/v3 v3.10.0
|
|
||||||
)
|
|
||||||
|
|||||||
33
lib/helper/helper_main.go
Normal file
33
lib/helper/helper_main.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetDomainBase() string {
|
||||||
|
domainBase, domainExists := os.LookupEnv("DOMAIN_BASE")
|
||||||
|
|
||||||
|
if !domainExists {
|
||||||
|
os.Setenv("DOMAIN_BASE", "http://localhost:8080")
|
||||||
|
domainBase = "http://localhost:8080"
|
||||||
|
}
|
||||||
|
|
||||||
|
return domainBase
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetCacheMapLimit() int {
|
||||||
|
cacheMapLimit, domainExists := os.LookupEnv("CACHE_MAP_LIMIT")
|
||||||
|
|
||||||
|
if !domainExists {
|
||||||
|
os.Setenv("CACHE_MAP_LIMIT", "25")
|
||||||
|
cacheMapLimit = "25"
|
||||||
|
}
|
||||||
|
|
||||||
|
rez, err := strconv.Atoi(cacheMapLimit)
|
||||||
|
if err != nil {
|
||||||
|
return 25
|
||||||
|
}
|
||||||
|
|
||||||
|
return rez
|
||||||
|
}
|
||||||
28
lib/routes/routes_home.go
Normal file
28
lib/routes/routes_home.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package routes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/JustKato/FreePad/lib/helper"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func HomeRoutes(router *gin.Engine) {
|
||||||
|
|
||||||
|
router.GET("/", func(c *gin.Context) {
|
||||||
|
c.HTML(200, "index.html", gin.H{
|
||||||
|
"title": "HomePage",
|
||||||
|
"domain_base": helper.GetDomainBase(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
router.GET("/:post", func(c *gin.Context) {
|
||||||
|
// Get the post we are looking for.
|
||||||
|
postName := c.Param("post")
|
||||||
|
|
||||||
|
c.HTML(200, "page.html", gin.H{
|
||||||
|
"title": postName,
|
||||||
|
"post_content": "",
|
||||||
|
"domain_base": helper.GetDomainBase(),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
6
lib/types/types_post.go
Normal file
6
lib/types/types_post.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type Post struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
}
|
||||||
4
main.go
4
main.go
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/JustKato/FreePad/lib/routes"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,6 +22,9 @@ func main() {
|
|||||||
// Load in static path
|
// Load in static path
|
||||||
router.Static("/static", "static/")
|
router.Static("/static", "static/")
|
||||||
|
|
||||||
|
// Add Routes
|
||||||
|
routes.HomeRoutes(router)
|
||||||
|
|
||||||
router.Run(":8080")
|
router.Run(":8080")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user