@@ -3,11 +3,14 @@ package main
3
3
import (
4
4
"fmt"
5
5
"html/template"
6
+ "io/fs"
6
7
"log"
7
8
"net/http"
8
9
"os"
9
10
"time"
10
11
12
+ "embed"
13
+
11
14
"github.com/alextanhongpin/go-gin-starter/config"
12
15
"github.com/diggerhq/digger/backend/controllers"
13
16
"github.com/diggerhq/digger/backend/middleware"
@@ -22,6 +25,9 @@ import (
22
25
// based on https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications
23
26
var Version = "dev"
24
27
28
+ //go:embed templates
29
+ var templates embed.FS
30
+
25
31
func main () {
26
32
27
33
initLogging ()
@@ -53,8 +59,6 @@ func main() {
53
59
54
60
r .Use (sentrygin .New (sentrygin.Options {Repanic : true }))
55
61
56
- r .Static ("/static" , "./templates/static" )
57
-
58
62
r .GET ("/health" , func (c * gin.Context ) {
59
63
c .JSON (http .StatusOK , gin.H {
60
64
"build_date" : cfg .GetString ("build_date" ),
@@ -70,7 +74,17 @@ func main() {
70
74
},
71
75
})
72
76
73
- r .LoadHTMLGlob ("templates/*.tmpl" )
77
+ if _ , err := os .Stat ("templates" ); err != nil {
78
+ matches , _ := fs .Glob (templates , "templates/*.tmpl" )
79
+ for _ , match := range matches {
80
+ r .LoadHTMLFiles (match )
81
+ }
82
+ r .StaticFS ("/static" , http .FS (templates ))
83
+ } else {
84
+ r .Static ("/static" , "./templates/static" )
85
+ r .LoadHTMLGlob ("templates/*.tmpl" )
86
+ }
87
+
74
88
r .GET ("/" , web .RedirectToLoginOrProjects )
75
89
76
90
r .POST ("/github-app-webhook" , controllers .GithubAppWebHook )
0 commit comments