Skip to content

Commit

Permalink
Bump to support go1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
PatWie committed Jan 7, 2023
1 parent 6dcdaa4 commit 1df82d4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/patwie/digitalmusicstand

go 1.12
go 1.19

require (
github.com/akamensky/argparse v1.1.0
github.com/go-chi/chi/v5 v5.0.0
github.com/markbates/pkger v0.17.1
github.com/gobuffalo/here v0.6.7 // indirect
gopkg.in/yaml.v2 v2.4.0
)
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ github.com/go-chi/chi/v5 v5.0.0 h1:DBPx88FjZJH3FsICfDAfIfnb7XxKIYVGG6lOPlhENAg=
github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJpoZOs=
github.com/gobuffalo/here v0.6.0 h1:hYrd0a6gDmWxBM4TnrGw8mQg24iSVoIkHEk7FodQcBI=
github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM=
github.com/gobuffalo/here v0.6.7 h1:hpfhh+kt2y9JLDfhYUxxCRxQol540jsVfKUZzjlbp8o=
github.com/gobuffalo/here v0.6.7/go.mod h1:vuCfanjqckTuRlqAitJz6QC4ABNnS27wLb816UhsPcc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand All @@ -17,12 +19,17 @@ github.com/markbates/pkger v0.17.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQ
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
43 changes: 34 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
package main

import (
"embed"
"encoding/json"
"fmt"
"html/template"
"io/ioutil"
"io/fs"
"log"
"net/http"
"os"
"strings"

"github.com/akamensky/argparse"
"github.com/go-chi/chi/v5"
"github.com/markbates/pkger"
)

//go:embed static.min/*
var embededFiles embed.FS

func getAllFilenames(efs fs.FS) (files []string, err error) {
if err := fs.WalkDir(efs, ".", func(path string, d fs.DirEntry, err error) error {
if d.IsDir() {
return nil
}

files = append(files, path)

return nil
}); err != nil {
return nil, err
}

return files, nil
}

func FileServer(r chi.Router, path string, root http.FileSystem) {
if strings.ContainsAny(path, "{}*") {
panic("FileServer does not permit URL parameters.")
}

fs := http.StripPrefix(path, http.FileServer(root))

if path != "/" && path[len(path)-1] != '/' {
r.Get(path, http.RedirectHandler(path+"/", 301).ServeHTTP)
path += "/"
Expand All @@ -34,11 +52,14 @@ func FileServer(r chi.Router, path string, root http.FileSystem) {
}

func ReadStringFromFile(path string) string {
packagedFile, _ := pkger.Open(path)
html_buf, err := ioutil.ReadAll(packagedFile)
fmt.Println(path)
fsys, err := fs.Sub(embededFiles, "static.min")
if err != nil {
panic(err)
}

html_buf, err := fs.ReadFile(fsys, path)

return string(html_buf)
}

Expand All @@ -54,7 +75,11 @@ func main() {
log.Fatal(parser.Usage(err))
}

html := ReadStringFromFile("/static.min/index.html")
staticFilesFS, err := fs.Sub(embededFiles, "static.min")
if err != nil {
panic(err)
}
indexHTML := ReadStringFromFile("index.html")

r := chi.NewRouter()

Expand All @@ -68,7 +93,7 @@ func main() {

if *allowUploads {
r.Post("/upload", UploadSheet(*sheetDir))
html = strings.Replace(html, "data-upload=disabled", "data-upload=enabled", 1)
indexHTML = strings.Replace(indexHTML, "data-upload=disabled", "data-upload=enabled", 1)

} else {
r.Post("/upload", func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -79,7 +104,7 @@ func main() {
}

t := template.New("index")
t, err = t.Parse(html)
t, err = t.Parse(indexHTML)
if err != nil {
panic(err)
}
Expand All @@ -90,7 +115,7 @@ func main() {
})

FileServer(r, "/sheet", http.Dir(*sheetDir))
FileServer(r, "/", pkger.Dir("/static.min"))
FileServer(r, "/", http.FS(staticFilesFS))

fmt.Println("Digital Music Stand (https://github.com/PatWie/digitalmusicstand)")
fmt.Println("listens at ", *addr)
Expand Down

0 comments on commit 1df82d4

Please sign in to comment.