Skip to content

Commit

Permalink
origin: minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dev committed Dec 26, 2023
1 parent 40cb5e6 commit 167e3f2
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions origin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
"io/fs"
"log/slog"
"net/http"
"os"
Expand All @@ -22,7 +23,8 @@ import (
)

//go:embed public/*
var assetsFs embed.FS
var publicFS embed.FS
var assetsFS fs.FS

const (
DEFAULT_PORT_HTTP = "8080"
Expand All @@ -38,6 +40,10 @@ type Config struct {
httpsLetsEncryptEmail string
}

func init() {
assetsFS, _ = fs.Sub(publicFS, "public")
}

func main() {
// for graceful shutdown
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill,
Expand Down Expand Up @@ -207,7 +213,7 @@ func loadRouter() (router chi.Router) {
}

func IndexHandler(w http.ResponseWriter, req *http.Request) {
file, _ := assetsFs.Open("public/index.html")
file, _ := assetsFS.Open("index.html")
defer file.Close()

fileInfo, _ := file.Stat()
Expand All @@ -221,7 +227,7 @@ func IndexHandler(w http.ResponseWriter, req *http.Request) {
}

func BinHandler(w http.ResponseWriter, req *http.Request) {
file, _ := assetsFs.Open("public/100k.bin")
file, _ := assetsFS.Open("100k.bin")
defer file.Close()

fileInfo, _ := file.Stat()
Expand All @@ -235,7 +241,7 @@ func BinHandler(w http.ResponseWriter, req *http.Request) {
}

func CssHandler(w http.ResponseWriter, req *http.Request) {
file, _ := assetsFs.Open("public/100k.css")
file, _ := assetsFS.Open("100k.css")
defer file.Close()

fileInfo, _ := file.Stat()
Expand All @@ -249,7 +255,7 @@ func CssHandler(w http.ResponseWriter, req *http.Request) {
}

func JpgHandler(w http.ResponseWriter, req *http.Request) {
file, _ := assetsFs.Open("public/100k.jpg")
file, _ := assetsFS.Open("100k.jpg")
defer file.Close()

fileInfo, _ := file.Stat()
Expand All @@ -263,7 +269,7 @@ func JpgHandler(w http.ResponseWriter, req *http.Request) {
}

func JsHandler(w http.ResponseWriter, req *http.Request) {
file, _ := assetsFs.Open("public/100k.js")
file, _ := assetsFS.Open("100k.js")
defer file.Close()

fileInfo, _ := file.Stat()
Expand All @@ -277,7 +283,7 @@ func JsHandler(w http.ResponseWriter, req *http.Request) {
}

func NotFoundHandler(w http.ResponseWriter, req *http.Request) {
file, _ := assetsFs.Open("public/404.html")
file, _ := assetsFS.Open("404.html")
defer file.Close()

fileInfo, _ := file.Stat()
Expand Down

0 comments on commit 167e3f2

Please sign in to comment.