Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an optional Home property to path configuration #44

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use home property in index template
  • Loading branch information
bmfs committed Jun 29, 2021
commit c6d787e12093a75d6fbe91c40df9f88953bc3223
17 changes: 13 additions & 4 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,24 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}

type indexDTO struct {
Import string
URL string
}

func (h *handler) serveIndex(w http.ResponseWriter, r *http.Request) {
host := h.Host(r)
handlers := make([]string, len(h.paths))
handlers := make([]indexDTO, len(h.paths))
for i, h := range h.paths {
handlers[i] = host + h.path
url := fmt.Sprintf("https://pkg.go.dev/%s", host+h.path)
if h.home != "" {
url = h.home
}
handlers[i] = indexDTO{Import: host + h.path, URL: url}
}
if err := indexTmpl.Execute(w, struct {
Host string
Handlers []string
Handlers []indexDTO
}{
Host: host,
Handlers: handlers,
Expand All @@ -163,7 +172,7 @@ var indexTmpl = template.Must(template.New("index").Parse(`<!DOCTYPE html>
<html>
<h1>{{.Host}}</h1>
<ul>
{{range .Handlers}}<li><a href="https://pkg.go.dev/{{.}}">{{.}}</a></li>{{end}}
{{range .Handlers}}<li><a href="{{.URL}}">{{.Import}}</a></li>{{end}}
</ul>
</html>
`))
Expand Down