mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
embed assets in binry
This commit is contained in:
parent
4bc9a71061
commit
6a25589751
6 changed files with 19 additions and 9 deletions
|
|
@ -8,11 +8,14 @@ Manage your holiday rental
|
|||
- [x] Add line items
|
||||
- [x] Read from the database
|
||||
- [x] Build the pdf invoice
|
||||
- [ ] Build the pdf report
|
||||
- [ ] Refactor the env variable calls to a Config struct with proper defaults
|
||||
- [x] Refactor handlers to call their dependencies instead of taking them from the Server struct
|
||||
- [ ] Embed mandatory assets, css in the executable
|
||||
- [x] Embed mandatory assets, css in the executable
|
||||
- [ ] Calendar to store new booking in calendar
|
||||
- [ ] Seed the database with the existing data before using the new system with customer data
|
||||
- [x] Seed the database with the existing data before using the new system with customer data
|
||||
- [ ] Create a dashboard page with the Host details, bookings and revenue this month
|
||||
- [ ] Edit campaigns and lines
|
||||
|
||||
## Built With
|
||||
|
||||
|
|
|
|||
1
assets/js/htmx.js
Normal file
1
assets/js/htmx.js
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -2,6 +2,7 @@ package server
|
|||
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
|
@ -24,12 +25,13 @@ type Server struct {
|
|||
bs *booking.Service
|
||||
ps *pdf.PdfService
|
||||
hc *config.Host
|
||||
fs *embed.FS
|
||||
addr string
|
||||
}
|
||||
|
||||
func New(bs *booking.Service, ps *pdf.PdfService, hc *config.Host) *Server {
|
||||
func New(fs *embed.FS, bs *booking.Service, ps *pdf.PdfService, hc *config.Host) *Server {
|
||||
s := &Server{
|
||||
Router: NewRouter(),
|
||||
Router: NewRouter(*fs),
|
||||
bs: bs,
|
||||
ps: ps,
|
||||
hc: hc,
|
||||
|
|
@ -67,7 +69,7 @@ func renderTempl(c echo.Context, status int, t templ.Component) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func NewRouter() *echo.Echo {
|
||||
func NewRouter(fs embed.FS) *echo.Echo {
|
||||
e := echo.New()
|
||||
// config
|
||||
e.HideBanner = true
|
||||
|
|
@ -80,7 +82,7 @@ func NewRouter() *echo.Echo {
|
|||
e.Use(middleware.Recover())
|
||||
e.Use(middleware.Secure())
|
||||
// static assets
|
||||
e.Static("/static", "assets")
|
||||
e.StaticFS("/static", echo.MustSubFS(fs, "assets"))
|
||||
|
||||
return e
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ templ BaseLayout() {
|
|||
<meta name="description" content="AI assistant to help you improve your management"/>
|
||||
<link rel="icon" href="/static/img/favicon.svg"/>
|
||||
<link rel="stylesheet" href="/static/css/pico.min.css"/>
|
||||
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
|
||||
<script src="/static/js/htmx.js"></script>
|
||||
</head>
|
||||
<body hx-boost="true">
|
||||
<nav class="container-fluid">
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ func BaseLayout() templ.Component {
|
|||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype html><html lang=\"en\"><head><title>RentEase | Your Property Management System</title><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><meta name=\"description\" content=\"AI assistant to help you improve your management\"><link rel=\"icon\" href=\"/static/img/favicon.svg\"><link rel=\"stylesheet\" href=\"/static/css/pico.min.css\"><script src=\"https://unpkg.com/htmx.org@1.9.10\"></script></head><body hx-boost=\"true\"><nav class=\"container-fluid\"><ul><li><a href=\"/\"><b>🏨 RentEase </b></a></li></ul><ul><li><a href=\"/bookings\">Bookings</a></li><li><a href=\"/reports\">Reports</a></li><li><a href=\"/bookings/new\" role=\"button\">New Booking</a></li></ul></nav><main class=\"container\">")
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype html><html lang=\"en\"><head><title>RentEase | Your Property Management System</title><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><meta name=\"description\" content=\"AI assistant to help you improve your management\"><link rel=\"icon\" href=\"/static/img/favicon.svg\"><link rel=\"stylesheet\" href=\"/static/css/pico.min.css\"><script src=\"/static/js/htmx.js\"></script></head><body hx-boost=\"true\"><nav class=\"container-fluid\"><ul><li><a href=\"/\"><b>🏨 RentEase </b></a></li></ul><ul><li><a href=\"/bookings\">Bookings</a></li><li><a href=\"/reports\">Reports</a></li><li><a href=\"/bookings/new\" role=\"button\">New Booking</a></li></ul></nav><main class=\"container\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
|
|
|
|||
6
main.go
6
main.go
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
|
|
@ -14,6 +15,9 @@ import (
|
|||
"github.com/rjNemo/rentease/internal/server"
|
||||
)
|
||||
|
||||
//go:embed assets
|
||||
var static embed.FS
|
||||
|
||||
func init() {
|
||||
if os.Getenv("ENV") != "PROD" {
|
||||
err := godotenv.Load(".env")
|
||||
|
|
@ -34,5 +38,5 @@ func main() {
|
|||
log.Fatalf("error migrating the database %s\n", err)
|
||||
}
|
||||
|
||||
server.New(booking.NewService(db), pdf.NewPdfService(), config.NewHost()).Start()
|
||||
server.New(&static, booking.NewService(db), pdf.NewPdfService(), config.NewHost()).Start()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue