diff --git a/cmd/pkgsite/main.go b/cmd/pkgsite/main.go index 6f431be67..758de301f 100644 --- a/cmd/pkgsite/main.go +++ b/cmd/pkgsite/main.go @@ -106,12 +106,12 @@ func main() { if *useProxy { url := os.Getenv("GOPROXY") if url == "" { - die("GOPROXY environment variable is not set") + dief("GOPROXY environment variable is not set") } var err error serverCfg.Proxy, err = proxy.New(url, nil) if err != nil { - die("connecting to proxy: %s", err) + dief("connecting to proxy: %s", err) } } @@ -122,7 +122,7 @@ func main() { ctx := context.Background() server, err := pkgsite.BuildServer(ctx, serverCfg) if err != nil { - die(err.Error()) + dief("%s", err) } addr := *httpAddr @@ -132,7 +132,7 @@ func main() { ln, err := net.Listen("tcp", addr) if err != nil { - die(err.Error()) + dief("%s", err) } url := "http://" + addr @@ -150,10 +150,10 @@ func main() { server.Install(router.Handle, nil, nil) mw := timeout.Timeout(54 * time.Second) srv := &http.Server{Addr: addr, Handler: mw(router)} - die("%v", srv.Serve(ln)) + dief("%v", srv.Serve(ln)) } -func die(format string, args ...any) { +func dief(format string, args ...any) { fmt.Fprintf(os.Stderr, format, args...) fmt.Fprintln(os.Stderr) os.Exit(1) diff --git a/internal/frontend/client/client.go b/internal/frontend/client/client.go index d141aa1d5..d1078af16 100644 --- a/internal/frontend/client/client.go +++ b/internal/frontend/client/client.go @@ -8,6 +8,7 @@ package client import ( "encoding/json" + "errors" "fmt" "io" "net/http" @@ -81,7 +82,7 @@ func (c *Client) fetchJSONPage(url string) (_ []byte, err error) { } defer r.Body.Close() if r.StatusCode != http.StatusOK { - return nil, fmt.Errorf(r.Status) + return nil, errors.New(r.Status) } body, err := io.ReadAll(r.Body) if err != nil { diff --git a/internal/symbol/generate.go b/internal/symbol/generate.go index 9e1c2de12..7c73f31f8 100644 --- a/internal/symbol/generate.go +++ b/internal/symbol/generate.go @@ -289,7 +289,7 @@ func (w *Walker) loadImports(pkgPath string) { // except we also check if a field is Embedded. If so, we ignore that field. func (w *Walker) emitStructType(name string, typ *types.Struct) { typeStruct := fmt.Sprintf("type %s struct", name) - w.emitf(typeStruct) + w.emitf("%s", typeStruct) defer w.pushScope(typeStruct)() for i := 0; i < typ.NumFields(); i++ { f := typ.Field(i) @@ -312,8 +312,8 @@ func (w *Walker) emitStructType(name string, typ *types.Struct) { // https://go.googlesource.com/go/+/refs/tags/go1.16.6/src/cmd/api/goapi.go#931, // except we don't check for unexported methods. func (w *Walker) emitIfaceType(name string, typ *types.Interface) { - typeInterface := fmt.Sprintf("type " + name + " interface") - w.emitf(typeInterface) + typeInterface := fmt.Sprintf("type %s interface", name) + w.emitf("%s", typeInterface) pop := w.pushScope(typeInterface) var methodNames []string