Copyright 2020 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

package frontend

import (
	
	
	
)

type badgePage struct {
LinkPath is the URL path of the badge will link to.
BadgePath is the URL path of the badge SVG.
badgeHandler serves a Go SVG badge image for requests to /badge/<path> and a badge generation tool page for requests to /badge/[?path=<path>].
func ( *Server) ( http.ResponseWriter,  *http.Request) {
	 := strings.TrimPrefix(.URL.Path, "/badge/")
	if  != "" {
		http.ServeFile(, , fmt.Sprintf("%s/img/badge.svg", .staticPath))
		return
	}
The user may input a fully qualified URL (https://pkg.go.dev/net/http or https://github.com/my/module) or just a pathname (net/http).
	 = strings.TrimPrefix(.URL.Query().Get("path"), "https://pkg.go.dev/")
	 := strings.Index(, "://")
	if  > -1 {
		 = [+3:]
	}

	 := badgePage{
		basePage:  .newBasePage(, "Badge generation tool"),
		LinkPath:  ,
		BadgePath: "badge/" +  + ".svg",
	}
	.servePage(.Context(), , "badge.tmpl", )