Skip to content

Commit

Permalink
continue to build out
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Aug 2, 2023
1 parent 77152ef commit 0b1e3a8
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions cmd/badges/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,45 @@ import (
)

func main() {

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
//query := r.URL.Query().Get("q")
//ext := r.URL.Query().Get("ext")
fmt.Println(r.URL.Path)
processPath(r.URL.Path)
//pageSize := 20
_, err := processPath(r.URL.Path)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte("you be invalid"))
return
}

category := strings.TrimSpace(strings.ToLower(r.URL.Query().Get("category")))

title := "Total lines"
text_length := "250"

switch category {
case "code":
title = "Code lines"
case "blanks":
title = "Blank lines"
case "comment":
fallthrough
case "comments":
title = "Comments"
case "cocomo":
title = "COCOMO $"
case "lines": // lines is the default
fallthrough
default:
//
title = "Total lines"
}

textLength := "250"
s := formatCount(30000)

if len(s) <= 3 {
textLength = "200"
}

w.Header().Set("Content-Type", "image/svg+xml;charset=utf-8")
w.Write([]byte(`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="100" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h69v20H0z"/><path fill="#4c1" d="M69 0h31v20H69z"/><path fill="url(#b)" d="M0 0h100v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="355" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="590">` + title + `</text><text x="355" y="140" transform="scale(.1)" textLength="590">` + title + `</text><text x="835" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="` + text_length + `">` + s + `</text><text x="835" y="140" transform="scale(.1)" textLength="` + text_length + `">` + s + `</text></g> </svg>`))
_, _ = w.Write([]byte(`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="a"><rect width="100" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#a)"><path fill="#555" d="M0 0h69v20H0z"/><path fill="#4c1" d="M69 0h31v20H69z"/><path fill="url(#b)" d="M0 0h100v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="110"> <text x="355" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="590">` + title + `</text><text x="355" y="140" transform="scale(.1)" textLength="590">` + title + `</text><text x="835" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="` + textLength + `">` + s + `</text><text x="835" y="140" transform="scale(.1)" textLength="` + textLength + `">` + s + `</text></g> </svg>`))
})

http.ListenAndServe(":8080", nil).Error()
Expand Down

0 comments on commit 0b1e3a8

Please sign in to comment.