Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
number571 committed Nov 19, 2024
1 parent 4357396 commit 1c2db5d
Show file tree
Hide file tree
Showing 15 changed files with 327 additions and 432 deletions.
12 changes: 1 addition & 11 deletions internal/applications/filesharer/internal/handler/about.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package handler

import (
"html/template"
"net/http"

"github.com/number571/go-peer/pkg/logger"
Expand All @@ -27,17 +26,8 @@ func AboutPage(pLogger logger.ILogger, pCfg config.IConfig) http.HandlerFunc {
return
}

t, err := template.ParseFS(
webui.GetTemplatePath(),
"index.html",
"about.html",
)
if err != nil {
panic("can't load hmtl files")
}

pLogger.PushInfo(logBuilder.WithMessage(http_logger.CLogSuccess))
_ = t.Execute(pW, &sAbout{
_ = webui.MustParseTemplate("index.html", "about.html").Execute(pW, &sAbout{
sTemplate: getTemplate(pCfg),
FAppFullName: "Hidden Lake Filesharer",
FDescription: [3]string{
Expand Down
11 changes: 1 addition & 10 deletions internal/applications/filesharer/internal/handler/error.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package handler

import (
"html/template"
"net/http"

"github.com/number571/go-peer/pkg/logger"
Expand All @@ -23,17 +22,9 @@ func ErrorPage(pLogger logger.ILogger, pCfg config.IConfig, pTitle, pMessage str
logBuilder := http_logger.NewLogBuilder(hlf_settings.CServiceName, pR)

pW.WriteHeader(http.StatusNotFound)
t, err := template.ParseFS(
webui.GetTemplatePath(),
"index.html",
"error.html",
)
if err != nil {
panic("can't load hmtl files")
}

pLogger.PushWarn(logBuilder.WithMessage(pTitle))
_ = t.Execute(pW, &sError{
_ = webui.MustParseTemplate("index.html", "error.html").Execute(pW, &sError{
sTemplate: getTemplate(pCfg),
FTitle: pTitle,
FMessage: pMessage,
Expand Down
12 changes: 1 addition & 11 deletions internal/applications/filesharer/internal/handler/friends.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package handler

import (
"context"
"html/template"
"net/http"
"sort"
"strings"
Expand Down Expand Up @@ -98,16 +97,7 @@ func FriendsPage(

result.FFriends = append(result.FFriends, friendsList...)

t, err := template.ParseFS(
webui.GetTemplatePath(),
"index.html",
"friends.html",
)
if err != nil {
panic("can't load hmtl files")
}

pLogger.PushInfo(logBuilder.WithMessage(http_logger.CLogSuccess))
_ = t.Execute(pW, result)
_ = webui.MustParseTemplate("index.html", "friends.html").Execute(pW, result)
}
}
12 changes: 1 addition & 11 deletions internal/applications/filesharer/internal/handler/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"html/template"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -105,17 +104,8 @@ func SettingsPage(
return
}

t, err := template.ParseFS(
webui.GetTemplatePath(),
"index.html",
"settings.html",
)
if err != nil {
panic("can't load hmtl files")
}

pLogger.PushInfo(logBuilder.WithMessage(http_logger.CLogSuccess))
_ = t.Execute(pW, result)
_ = webui.MustParseTemplate("index.html", "settings.html").Execute(pW, result)
}
}

Expand Down
12 changes: 1 addition & 11 deletions internal/applications/filesharer/internal/handler/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package handler
import (
"context"
"crypto/sha512"
"html/template"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -74,17 +73,8 @@ func StoragePage(
FFilesList: filesList,
}

t, err := template.ParseFS(
webui.GetTemplatePath(),
"index.html",
"filesharer/storage.html",
)
if err != nil {
panic("can't load hmtl files")
}

pLogger.PushInfo(logBuilder.WithMessage(http_logger.CLogSuccess))
_ = t.Execute(pW, result)
_ = webui.MustParseTemplate("index.html", "filesharer/storage.html").Execute(pW, result)
}
}

Expand Down
12 changes: 1 addition & 11 deletions internal/applications/messenger/internal/handler/about.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package handler

import (
"html/template"
"net/http"

"github.com/number571/go-peer/pkg/logger"
Expand All @@ -27,17 +26,8 @@ func AboutPage(pLogger logger.ILogger, pCfg config.IConfig) http.HandlerFunc {
return
}

t, err := template.ParseFS(
webui.GetTemplatePath(),
"index.html",
"about.html",
)
if err != nil {
panic("can't load hmtl files")
}

pLogger.PushInfo(logBuilder.WithMessage(http_logger.CLogSuccess))
_ = t.Execute(pW, &sAbout{
_ = webui.MustParseTemplate("index.html", "about.html").Execute(pW, &sAbout{
sTemplate: getTemplate(pCfg),
FAppFullName: "Hidden Lake Messenger",
FDescription: [3]string{
Expand Down
11 changes: 1 addition & 10 deletions internal/applications/messenger/internal/handler/error.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package handler

import (
"html/template"
"net/http"

"github.com/number571/go-peer/pkg/logger"
Expand All @@ -23,17 +22,9 @@ func ErrorPage(pLogger logger.ILogger, pCfg config.IConfig, pTitle, pMessage str
logBuilder := http_logger.NewLogBuilder(hlm_settings.CServiceName, pR)

pW.WriteHeader(http.StatusNotFound)
t, err := template.ParseFS(
webui.GetTemplatePath(),
"index.html",
"error.html",
)
if err != nil {
panic("can't load hmtl files")
}

pLogger.PushWarn(logBuilder.WithMessage(pTitle))
_ = t.Execute(pW, &sError{
_ = webui.MustParseTemplate("index.html", "error.html").Execute(pW, &sError{
sTemplate: getTemplate(pCfg),
FTitle: pTitle,
FMessage: pMessage,
Expand Down
12 changes: 1 addition & 11 deletions internal/applications/messenger/internal/handler/friends.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package handler

import (
"context"
"html/template"
"net/http"
"sort"
"strings"
Expand Down Expand Up @@ -98,16 +97,7 @@ func FriendsPage(

result.FFriends = append(result.FFriends, friendsList...)

t, err := template.ParseFS(
webui.GetTemplatePath(),
"index.html",
"friends.html",
)
if err != nil {
panic("can't load hmtl files")
}

pLogger.PushInfo(logBuilder.WithMessage(http_logger.CLogSuccess))
_ = t.Execute(pW, result)
_ = webui.MustParseTemplate("index.html", "friends.html").Execute(pW, result)
}
}
12 changes: 1 addition & 11 deletions internal/applications/messenger/internal/handler/friends_chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package handler
import (
"context"
"errors"
"html/template"
"io"
"net/http"
"strings"
Expand Down Expand Up @@ -150,17 +149,8 @@ func FriendsChatPage(
}(),
}

t, err := template.ParseFS(
webui.GetTemplatePath(),
"index.html",
"messenger/chat.html",
)
if err != nil {
panic(err)
}

pLogger.PushInfo(logBuilder.WithMessage(http_logger.CLogSuccess))
_ = t.Execute(pW, res)
_ = webui.MustParseTemplate("index.html", "messenger/chat.html").Execute(pW, res)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package handler

import (
"context"
"html/template"
"net/http"

"github.com/number571/go-peer/pkg/logger"
Expand Down Expand Up @@ -41,15 +40,6 @@ func FriendsUploadPage(
return
}

t, err := template.ParseFS(
webui.GetTemplatePath(),
"index.html",
"messenger/upload.html",
)
if err != nil {
panic("can't load hmtl files")
}

msgLimit, err := utils.GetMessageLimit(pCtx, pHlsClient)
if err != nil {
ErrorPage(pLogger, pCfg, "get_message_size", "get message size (limit)")(pW, pR)
Expand All @@ -63,6 +53,6 @@ func FriendsUploadPage(
}

pLogger.PushInfo(logBuilder.WithMessage(http_logger.CLogSuccess))
_ = t.Execute(pW, res)
_ = webui.MustParseTemplate("index.html", "messenger/upload.html").Execute(pW, res)
}
}
12 changes: 1 addition & 11 deletions internal/applications/messenger/internal/handler/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"html/template"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -105,17 +104,8 @@ func SettingsPage(
return
}

t, err := template.ParseFS(
webui.GetTemplatePath(),
"index.html",
"settings.html",
)
if err != nil {
panic("can't load hmtl files")
}

pLogger.PushInfo(logBuilder.WithMessage(http_logger.CLogSuccess))
_ = t.Execute(pW, result)
_ = webui.MustParseTemplate("index.html", "settings.html").Execute(pW, result)
}
}

Expand Down
9 changes: 9 additions & 0 deletions internal/webui/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package webui

import (
"embed"
"html/template"
"io/fs"
)

Expand All @@ -19,6 +20,14 @@ var (
gEmbededTemplate embed.FS
)

func MustParseTemplate(pPatters ...string) *template.Template {
t, err := template.ParseFS(GetTemplatePath(), pPatters...)
if err != nil {
panic(err)
}
return t
}

func GetStaticPath() fs.FS {
fsys, err := fs.Sub(gEmbededStatic, "static")
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/webui/web_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
)

func TestPath(_ *testing.T) {
_ = GetTemplatePath()
_ = GetStaticPath()
_ = GetTemplatePath()
_ = MustParseTemplate("index.html")
}
2 changes: 1 addition & 1 deletion test/result/badge_codelines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1c2db5d

Please sign in to comment.