Skip to content

Commit 3c06b9d

Browse files
committed
Working with moved files
1 parent 6dee942 commit 3c06b9d

3 files changed

Lines changed: 21 additions & 12 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SVG Analyzer [<img alt="Logo for SVGan" src="cmd/server/static/favicon.svg" height="96" align="right"/>](https://svgan.fileformat.info/)
1+
# SVG Analyzer [<img alt="Logo for SVGan" src="ui/static/favicon.svg" height="96" align="right"/>](https://svgan.fileformat.info/)
22

33
[![deploy](https://github.com/FileFormatInfo/svgan/actions/workflows/gcr-deploy.yaml/badge.svg)](https://github.com/FileFormatInfo/svgan/actions/workflows/gcr-deploy.yaml)
44

cmd/server/server.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"net/http"
55
"os"
66
"strconv"
7+
8+
"github.com/FileFormatInfo/svgan/ui"
79
)
810

911
func main() {
@@ -15,11 +17,11 @@ func main() {
1517
var listenAddress = os.Getenv("ADDRESS")
1618

1719
http.HandleFunc("/status.json", statusHandler)
18-
http.HandleFunc("/robots.txt", staticHandler.ServeHTTP)
19-
http.HandleFunc("/favicon.ico", staticHandler.ServeHTTP)
20-
http.HandleFunc("/favicon.svg", staticHandler.ServeHTTP)
21-
http.HandleFunc("/images/", staticHandler.ServeHTTP)
22-
http.HandleFunc("GET /{$}", staticHandler.ServeHTTP)
20+
http.HandleFunc("/robots.txt", ui.StaticHandler.ServeHTTP)
21+
http.HandleFunc("/favicon.ico", ui.StaticHandler.ServeHTTP)
22+
http.HandleFunc("/favicon.svg", ui.StaticHandler.ServeHTTP)
23+
http.HandleFunc("/images/", ui.StaticHandler.ServeHTTP)
24+
http.HandleFunc("GET /{$}", ui.StaticHandler.ServeHTTP)
2325
http.HandleFunc("POST /{$}", uploadHandler)
2426

2527
err := http.ListenAndServe(listenAddress+":"+strconv.Itoa(listenPort), nil)

ui/staticHandler.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package ui
22

33
import (
44
"embed"
@@ -8,15 +8,22 @@ import (
88

99
//go:embed static
1010
var embeddedFiles embed.FS
11-
var staticHandler = initStaticHandler()
11+
var StaticHandler http.Handler
1212

13-
func initStaticHandler() http.Handler {
13+
func initStaticHandler() (http.Handler, error) {
1414

1515
fsys, err := fs.Sub(embeddedFiles, "static")
1616
if err != nil {
17-
logger.Error("unable to create static file system", "error", err)
18-
panic(err)
17+
return nil, err
1918
}
2019

21-
return http.FileServer(http.FS(fsys))
20+
return http.FileServer(http.FS(fsys)), nil
21+
}
22+
23+
func init() {
24+
var err error
25+
StaticHandler, err = initStaticHandler()
26+
if err != nil {
27+
panic(err)
28+
}
2229
}

0 commit comments

Comments
 (0)