absolute paths are the way of the light

main v0.1.0
Nick Dumas 1 year ago
parent 781a718e42
commit 5619fbfe5b

@ -5,12 +5,12 @@ import (
"flag" "flag"
"fmt" "fmt"
"io/fs" "io/fs"
"log"
"net/http"
"os" "os"
"path/filepath" "path/filepath"
"strings"
// "log"
"net/http"
"strconv" "strconv"
"strings"
"code.ndumas.com/ndumas/badges" "code.ndumas.com/ndumas/badges"
"github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5"
@ -30,7 +30,8 @@ func NewBadgeRenderer(fontDir string) (*BadgeRenderer, error) {
root := os.DirFS(fontDir) root := os.DirFS(fontDir)
err := fs.WalkDir(root, ".", func(path string, d fs.DirEntry, err error) error { err := fs.WalkDir(root, ".", func(path string, d fs.DirEntry, err error) error {
if strings.HasSuffix(path, ".ttf") { if strings.HasSuffix(path, ".ttf") {
br.Fonts[filepath.Base(path)] = path absFont := filepath.Join(fontDir, path)
br.Fonts[filepath.Base(path)] = absFont
} }
return nil return nil
}) })
@ -133,18 +134,24 @@ func (br *BadgeRenderer) renderBadge(w http.ResponseWriter, r *http.Request) {
} }
} }
var (
port int
fontsDir string
)
func main() { func main() {
var (
port int
fontsDir string
)
flag.IntVar(&port, "port", 8484, "http listening port") flag.IntVar(&port, "port", 8484, "http listening port")
flag.StringVar(&fontsDir, "fonts", "fonts/", "directory containing ttf files") flag.StringVar(&fontsDir, "fonts", "fonts/", "directory containing ttf files")
flag.Parse() flag.Parse()
br, err := NewBadgeRenderer(fontsDir) absFontDir, err := filepath.Abs(fontsDir)
if err != nil {
log.Fatalf("error building absolute font dir path: %s\n", err)
}
log.Println("absFontDir:", absFontDir)
br, err := NewBadgeRenderer(absFontDir)
if err != nil { if err != nil {
fmt.Println("couldn't create renderer", err) fmt.Println("couldn't create renderer", err)
return return

Loading…
Cancel
Save