Skip to content

refactor: magic-strings - extract auth HTML templates and hardcoded URLs #16

@aliwatters

Description

@aliwatters

Summary

The auth/auth.go file contains two inline HTML templates (errorPageTemplate and successPageTemplate) totaling 88 lines of CSS/HTML string literals. These represent 15% of the file and obscure the Go logic. Moving them to embedded files using //go:embed would improve readability and maintainability. Additionally, the Google userinfo URL is a hardcoded magic string.

Location

  • File: internal/auth/auth.go
  • HTML templates: L55-95 (errorPageTemplate), L97-143 (successPageTemplate)
  • Magic URL: L202 ("https://www.googleapis.com/oauth2/v2/userinfo")

Category

Type: Magic Strings / Code Organization

Severity: Low

Evidence

88 lines of inline HTML/CSS:

var errorPageTemplate = `<!DOCTYPE html>
<html><head>
<style>
  body { font-family: -apple-system, ...; }
  ...
</style>
</head><body>
...
</body></html>`

Hardcoded URL:

resp, err := client.Get("https://www.googleapis.com/oauth2/v2/userinfo")

Suggested Refactoring

  1. Create internal/auth/templates/ directory with error.html and success.html
  2. Use //go:embed templates/error.html to load at compile time
  3. Extract const googleUserInfoURL = "https://www.googleapis.com/oauth2/v2/userinfo"
  4. Consider using html/template for the success page's dynamic account list

Effort Estimate

  • Size: Small (< 1 hour)
  • Risk: Low (cosmetic change, same behavior)
  • Tests Required: No (manual OAuth flow test recommended)

Acceptance Criteria

  • HTML templates moved to embedded files
  • Userinfo URL extracted to named constant
  • auth.go reduced by ~88 lines
  • OAuth flow still works correctly
  • go build ./... passes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions