Skip to content

Commit

Permalink
+ public files is dynamically generated/populated in html template
Browse files Browse the repository at this point in the history
  • Loading branch information
m0zgen committed Mar 22, 2023
1 parent 79f84df commit d4c2627
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
22 changes: 21 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,30 @@ func runHttpServer(port string) {
}
}

//type PublicFiles

func listPublicFilesDir(target string) []string {
files, err := os.ReadDir(target)
//var m map[string]string
var PublicFiles []string
if err != nil {
handleErr(err)
}

for _, file := range files {
//fmt.Println(file.Name(), file.IsDir())
//m["file"] = file.Name()
PublicFiles = append(PublicFiles, file.Name())
}
return PublicFiles
}

func serveTemplate(w http.ResponseWriter, r *http.Request) {

appVersion := "0.1.6"
hostname, err := os.Hostname()
handleErr(err)

publicFiles := listPublicFilesDir("./public/files/")
//
files := []string{
"./templates/base.html",
Expand All @@ -661,10 +679,12 @@ func serveTemplate(w http.ResponseWriter, r *http.Request) {
AppVersion string
CurrentDate string
HostName string
PublicFiles []string
}{
appVersion,
getTime(),
hostname,
publicFiles,
}

//err = ts.Execute(w, data)
Expand Down
19 changes: 6 additions & 13 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@
<div class="columns is-multiline">
<div class="column is-8-tablet has-text-centered">
<p>Already files to download:</p>

<ul class="is-flex is-flex-wrap-wrap is-align-items-center is-justify-content-center">
{{range $i, $a := .PublicFiles}}
<li class="mr-4">
<a href="public/files/bl.txt">bl.txt</a>
</li>
<li class="mr-4">
<a href="public/files/bl_plain.txt">bl_plain.txt</a>
</li>
<li class="mr-4">
<a href="public/files/wl.txt">wl.txt</a>
</li>
<li class="mr-4">
<a href="public/files/wl_plain.txt">wl_plain.txt</a>
</li>
<li class="mr-4">
<a href="public/files/ip_plain.txt">ip_plain.txt</a>
<a href="public/files/{{$a}}">{{$a}}</a>
</li>
{{end}}
</ul>


</div>
<div class="column is-4-tablet">
<ul class="is-flex is-flex-wrap-wrap is-align-items-baseline is-justify-content-center">
Expand Down

0 comments on commit d4c2627

Please sign in to comment.