From 6707967fb585f27b4477b9b94fe870b2834bbf6d Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Tue, 15 Jul 2025 01:41:18 +0700 Subject: [PATCH] add embed ui --- .DS_Store | Bin 6148 -> 8196 bytes Makefile | 4 +++- cmd/evening_detective/main.go | 20 ++++++++++++++++-- .../static}/admin/assets/index-JqNLMpQx.css | 0 .../static}/admin/assets/index-Tp3gHO58.js | 0 .../static}/admin/favicon.ico | Bin .../static}/admin/index.html | 0 .../user/assets/AboutView-CSIvawM9.css | 0 .../static}/user/assets/AboutView-CZUiJ3Yo.js | 0 .../static}/user/assets/index-BJbIgyMb.css | 0 .../static}/user/assets/index-DkrD2ASU.js | 0 .../static}/user/assets/logo-BnUTTh_g.png | Bin .../static}/user/favicon.ico | Bin .../evening_detective/static}/user/index.html | 0 .../pdf_service}/JetBrainsMono-Medium.ttf | Bin internal/services/pdf_service/service.go | 13 ++++++++++-- static/.DS_Store | Bin 6148 -> 0 bytes 17 files changed, 32 insertions(+), 5 deletions(-) rename {static => cmd/evening_detective/static}/admin/assets/index-JqNLMpQx.css (100%) rename {static => cmd/evening_detective/static}/admin/assets/index-Tp3gHO58.js (100%) rename {static => cmd/evening_detective/static}/admin/favicon.ico (100%) rename {static => cmd/evening_detective/static}/admin/index.html (100%) rename {static => cmd/evening_detective/static}/user/assets/AboutView-CSIvawM9.css (100%) rename {static => cmd/evening_detective/static}/user/assets/AboutView-CZUiJ3Yo.js (100%) rename {static => cmd/evening_detective/static}/user/assets/index-BJbIgyMb.css (100%) rename {static => cmd/evening_detective/static}/user/assets/index-DkrD2ASU.js (100%) rename {static => cmd/evening_detective/static}/user/assets/logo-BnUTTh_g.png (100%) rename {static => cmd/evening_detective/static}/user/favicon.ico (100%) rename {static => cmd/evening_detective/static}/user/index.html (100%) rename {data => internal/services/pdf_service}/JetBrainsMono-Medium.ttf (100%) delete mode 100644 static/.DS_Store diff --git a/.DS_Store b/.DS_Store index f15cd7e1dc87f7abfe00f773fd68c5b745e81b61..619ae1d056002b47a8538fe3d73f60e514558df0 100644 GIT binary patch delta 335 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8E20o2aKKEDn+f@);P?Jah7slXCKtHVbly zv20f0=x1Kc&cQLUfrTHWh?OCcL64z;A%!7rau&P%WPTPkc~*ubm>5hm$ZVjAKY^HU zvKEW6U=l+nLtavOaRJC^pzOBEO>BjnV%60KItnJnhLiuXNi%j#mSUF|?*z&+15E^~ zFAFZp%gN762Z}IGj$qN0WdYio$WX$Nh-weRdZ3DVo6A_3nN_<%R{jSApdbSSFGDd< zLq0>M0|%s|B;_1r+h6=dYb!tczJ W`DHvo7BDbDECbokusNP*4l@8r_ZhkX diff --git a/Makefile b/Makefile index de883b9..1aef011 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,9 @@ run: go run ./cmd/evening_detective/main.go build: - go build -o bin/evening_detective cmd/evening_detective/main.go + rm -rf bin + CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -o bin/evening_detective_macos_arm64 cmd/evening_detective/main.go + CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o bin/evening_detective_macos_amd64 cmd/evening_detective/main.go text_to_story: rm -f ./cmd/text_to_story/story.json diff --git a/cmd/evening_detective/main.go b/cmd/evening_detective/main.go index 6ea05bb..c853fcc 100644 --- a/cmd/evening_detective/main.go +++ b/cmd/evening_detective/main.go @@ -2,11 +2,13 @@ package main import ( "context" + "embed" "evening_detective/internal/app" "evening_detective/internal/config" "evening_detective/internal/services" "evening_detective/internal/services/story_service" proto "evening_detective/proto" + "io/fs" "log" "net" "net/http" @@ -17,6 +19,12 @@ import ( "google.golang.org/grpc/metadata" ) +//go:embed static/user/* +var userFS embed.FS + +//go:embed static/admin/* +var adminFS embed.FS + func main() { // Create a listener on TCP port lis, err := net.Listen("tcp", ":8080") @@ -91,7 +99,11 @@ func main() { }() muxUser := http.NewServeMux() - fileServerUser := http.FileServer(http.Dir("./static/user")) + subUserFS, err := fs.Sub(userFS, "static/user") + if err != nil { + log.Fatalln(err) + } + fileServerUser := http.FileServer(http.FS(subUserFS)) muxUser.Handle("/", fileServerUser) // Serve user web server @@ -101,7 +113,11 @@ func main() { }() muxAdmin := http.NewServeMux() - fileServerAdmin := http.FileServer(http.Dir("./static/admin")) + subAdminFS, err := fs.Sub(adminFS, "static/admin") + if err != nil { + log.Fatalln(err) + } + fileServerAdmin := http.FileServer(http.FS(subAdminFS)) muxAdmin.Handle("/", fileServerAdmin) // Serve admin web server diff --git a/static/admin/assets/index-JqNLMpQx.css b/cmd/evening_detective/static/admin/assets/index-JqNLMpQx.css similarity index 100% rename from static/admin/assets/index-JqNLMpQx.css rename to cmd/evening_detective/static/admin/assets/index-JqNLMpQx.css diff --git a/static/admin/assets/index-Tp3gHO58.js b/cmd/evening_detective/static/admin/assets/index-Tp3gHO58.js similarity index 100% rename from static/admin/assets/index-Tp3gHO58.js rename to cmd/evening_detective/static/admin/assets/index-Tp3gHO58.js diff --git a/static/admin/favicon.ico b/cmd/evening_detective/static/admin/favicon.ico similarity index 100% rename from static/admin/favicon.ico rename to cmd/evening_detective/static/admin/favicon.ico diff --git a/static/admin/index.html b/cmd/evening_detective/static/admin/index.html similarity index 100% rename from static/admin/index.html rename to cmd/evening_detective/static/admin/index.html diff --git a/static/user/assets/AboutView-CSIvawM9.css b/cmd/evening_detective/static/user/assets/AboutView-CSIvawM9.css similarity index 100% rename from static/user/assets/AboutView-CSIvawM9.css rename to cmd/evening_detective/static/user/assets/AboutView-CSIvawM9.css diff --git a/static/user/assets/AboutView-CZUiJ3Yo.js b/cmd/evening_detective/static/user/assets/AboutView-CZUiJ3Yo.js similarity index 100% rename from static/user/assets/AboutView-CZUiJ3Yo.js rename to cmd/evening_detective/static/user/assets/AboutView-CZUiJ3Yo.js diff --git a/static/user/assets/index-BJbIgyMb.css b/cmd/evening_detective/static/user/assets/index-BJbIgyMb.css similarity index 100% rename from static/user/assets/index-BJbIgyMb.css rename to cmd/evening_detective/static/user/assets/index-BJbIgyMb.css diff --git a/static/user/assets/index-DkrD2ASU.js b/cmd/evening_detective/static/user/assets/index-DkrD2ASU.js similarity index 100% rename from static/user/assets/index-DkrD2ASU.js rename to cmd/evening_detective/static/user/assets/index-DkrD2ASU.js diff --git a/static/user/assets/logo-BnUTTh_g.png b/cmd/evening_detective/static/user/assets/logo-BnUTTh_g.png similarity index 100% rename from static/user/assets/logo-BnUTTh_g.png rename to cmd/evening_detective/static/user/assets/logo-BnUTTh_g.png diff --git a/static/user/favicon.ico b/cmd/evening_detective/static/user/favicon.ico similarity index 100% rename from static/user/favicon.ico rename to cmd/evening_detective/static/user/favicon.ico diff --git a/static/user/index.html b/cmd/evening_detective/static/user/index.html similarity index 100% rename from static/user/index.html rename to cmd/evening_detective/static/user/index.html diff --git a/data/JetBrainsMono-Medium.ttf b/internal/services/pdf_service/JetBrainsMono-Medium.ttf similarity index 100% rename from data/JetBrainsMono-Medium.ttf rename to internal/services/pdf_service/JetBrainsMono-Medium.ttf diff --git a/internal/services/pdf_service/service.go b/internal/services/pdf_service/service.go index 5e72e3b..1042322 100644 --- a/internal/services/pdf_service/service.go +++ b/internal/services/pdf_service/service.go @@ -5,14 +5,23 @@ import ( "evening_detective/internal/models" "strings" + "embed" + "github.com/signintech/gopdf" "github.com/skip2/go-qrcode" ) +//go:embed JetBrainsMono-Medium.ttf +var f embed.FS + func CreateTeamsPdf(teams []*models.Team) ([]byte, error) { pdf := &gopdf.GoPdf{} pdf.Start(gopdf.Config{PageSize: *gopdf.PageSizeA4}) // W: 595, H: 842 - if err := pdf.AddTTFFont("main", "data/JetBrainsMono-Medium.ttf"); err != nil { + file, err := f.Open("JetBrainsMono-Medium.ttf") + if err != nil { + return nil, err + } + if err := pdf.AddTTFFontByReader("main", file); err != nil { return nil, err } if err := pdf.SetFont("main", "", 10); err != nil { @@ -42,7 +51,7 @@ func CreateTeamsPdf(teams []*models.Team) ([]byte, error) { } } buffer := &bytes.Buffer{} - _, err := pdf.WriteTo(buffer) + _, err = pdf.WriteTo(buffer) return buffer.Bytes(), err } diff --git a/static/.DS_Store b/static/.DS_Store deleted file mode 100644 index 2fbcbdea445f20e8452b8fca19383af66f7a6da3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5T3176GZ4i!DGN{(bPW_FR|*us}Vh@)Wj4G#;i1{J(NPu`Y>L75?@DW zcDJRa_FAmW!0b0WJCp2wyX+4Dh)F=o`sU$z<0*Mg z<(nEA2wcHRmJRmd9gV@bU;S2^$n*hy{rG+yBQwAZFaxv0fZ4&UrP=8+_mml62ByRS z?GFwrp=YqrsJ0F))Dr-au8~U6rVAnEI0ij~g+^>a5jqu7rwa4L5IPL1>05kBf7!c(X|D=vX zGH2`9;OMM%Q14JlD6Y^rNI^p##TZLR@fxZU^gCoAdIk%P=t1F&fTDp5W?-re`~Xke BVS4}o