File tree 4 files changed +13
-16
lines changed
4 files changed +13
-16
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ import (
28
28
)
29
29
30
30
const (
31
- version = "v0.0.1 "
31
+ version = "v0.0.4 "
32
32
)
33
33
34
34
var (
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import (
19
19
"fmt"
20
20
"os"
21
21
"strings"
22
+ "text/template"
22
23
"vimbin/internal/config"
23
24
"vimbin/internal/handlers"
24
25
"vimbin/internal/server"
@@ -48,10 +49,11 @@ var serveCmd = &cobra.Command{
48
49
}
49
50
50
51
// Read the HTML template file
51
- htmlTemplate , err := os . ReadFile ( "web/templates/index.html" )
52
+ htmlTemplate , err := template . ParseFS ( server . StaticFS , "web/templates/index.html" )
52
53
if err != nil {
53
- panic (err )
54
+ log . Fatal (). Err (err )
54
55
}
56
+
55
57
config .App .HtmlTemplate = htmlTemplate
56
58
57
59
// Parse the configuration
Original file line number Diff line number Diff line change 1
1
package config
2
2
3
- import "sync"
3
+ import (
4
+ "sync"
5
+ "text/template"
6
+ )
4
7
5
8
// App is the global configuration instance.
6
9
var App Config
7
10
8
11
// Config represents the application configuration.
9
12
type Config struct {
10
- HtmlTemplate [] byte `yaml:"-"` // HtmlTemplate contains the HTML template content.
11
- Server Server `yaml:"server"` // Server represents the server configuration.
12
- Storage Storage `yaml:"storage"` // Storage represents the storage configuration.
13
+ HtmlTemplate * template. Template `yaml:"-"` // HtmlTemplate contains the HTML template content.
14
+ Server Server `yaml:"server"` // Server represents the server configuration.
15
+ Storage Storage `yaml:"storage"` // Storage represents the storage configuration.
13
16
}
14
17
15
18
// Web represents the web configuration.
Original file line number Diff line number Diff line change 1
1
package handlers
2
2
3
3
import (
4
- "html/template"
5
4
"net/http"
6
5
"vimbin/internal/config"
7
6
"vimbin/internal/server"
@@ -30,14 +29,7 @@ func Home(w http.ResponseWriter, r *http.Request) {
30
29
Content : config .App .Storage .Content .Get (),
31
30
}
32
31
33
- tmpl , err := template .New ("index" ).Parse (string (config .App .HtmlTemplate ))
34
- if err != nil {
35
- http .Error (w , err .Error (), http .StatusInternalServerError )
36
- return
37
- }
38
-
39
- err = tmpl .Execute (w , page )
40
- if err != nil {
32
+ if err := config .App .HtmlTemplate .Execute (w , page ); err != nil {
41
33
http .Error (w , err .Error (), http .StatusInternalServerError )
42
34
}
43
35
}
You can’t perform that action at this time.
0 commit comments