@@ -52,7 +52,7 @@ type LibationsPageData struct {
52
52
53
53
// parseTemplates is used to parse templates from the embedded FS, and ensure that the
54
54
// 'StringJoin' function is available to the templates.
55
- func parseTemplates () * template.Template {
55
+ func parseTemplates () ( * template.Template , error ) {
56
56
// Create an fs.FS from the embedded filesystem
57
57
files , err := fs .Sub (templateFS , "templates" )
58
58
if err != nil {
@@ -62,8 +62,13 @@ func parseTemplates() *template.Template {
62
62
63
63
funcMap := template.FuncMap {"StringsJoin" : strings .Join }
64
64
tmpl := template .New ("" ).Funcs (funcMap )
65
- tmpl , _ = tmpl .ParseFS (files , "*.html" , "icons/*.svg" )
66
- return tmpl
65
+
66
+ tmpl , err = tmpl .ParseFS (files , "*.html" , "icons/*.svg" )
67
+ if err != nil {
68
+ return nil , err
69
+ }
70
+
71
+ return tmpl , nil
67
72
}
68
73
69
74
// parseRecipes attempts to read and parse recipes either from a path specified at the CLI,
@@ -103,7 +108,11 @@ func libationsMux(drinks []Drink, files fs.FS) *http.ServeMux {
103
108
// Serve static files from our embedded filesystem using http.Fileserver
104
109
mux .Handle ("/static/" , http .StripPrefix ("/static/" , http .FileServer (http .FS (files ))))
105
110
106
- templates := parseTemplates ()
111
+ templates , err := parseTemplates ()
112
+ if err != nil {
113
+ slog .Error ("failed to parse templates from filesystem" , "error" , err .Error ())
114
+ os .Exit (1 )
115
+ }
107
116
108
117
// Render the templates with the drinks/time data.
109
118
mux .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
@@ -196,32 +205,36 @@ func main() {
196
205
// Create an fs.FS from the embedded filesystem
197
206
files , err := fs .Sub (staticFS , "static" )
198
207
if err != nil {
199
- slog .Error (err .Error ())
208
+ slog .Error ("failed to access static files in embedded filesystem" , "error" , err .Error ())
200
209
os .Exit (1 )
201
210
}
202
211
203
212
drinks , err := parseRecipes (* recipesFile )
204
213
if err != nil {
205
- slog .Error (err .Error ())
214
+ slog .Error ("failed to parse recipes" , "error" , err .Error ())
206
215
os .Exit (1 )
207
216
}
208
217
209
218
var listener * net.Listener
210
219
if * local {
211
220
listener , err = localListener (* addr )
221
+ if err != nil {
222
+ slog .Error ("failed to create local listener" , "error" , err .Error ())
223
+ os .Exit (1 )
224
+ }
212
225
} else {
213
226
listener , err = tailscaleListener (* hostname , * tsnetLogs )
214
- }
215
-
216
- if err != nil {
217
- slog .Error (err .Error ())
218
- os .Exit (1 )
227
+ if err != nil {
228
+ slog .Error ("failed to create tailscale listener" , "error" , err .Error ())
229
+ os .Exit (1 )
230
+ }
219
231
}
220
232
221
233
mux := libationsMux (drinks , files )
222
234
223
235
slog .Info (fmt .Sprintf ("starting listener on %s" , * addr ))
224
236
if err = http .Serve (* listener , mux ); err != nil {
225
- slog .Error (err .Error ())
237
+ slog .Error ("failed to start http server" , "error" , err .Error ())
238
+ os .Exit (1 )
226
239
}
227
240
}
0 commit comments