code: func resolveFormat(request *http.Request) string {
  	// If a known format is specified, return it.
  	format := request.URL.Query().Get("format")
  	switch f := strings.ToLower(format); f {
  	case formatHTMLLite, formatHTMLFull, formatRAW:
  		return f
  	}
  	// TODO(hinoka): Check accept header first.
  	// User Agents are basically formatted as "<Type>/<Version> <other stuff>"
  	// We really only care about the very first <Type> string.
  	// from there we can basically differentiate between major classes of user agents. (Browser vs CLI)
  	if format == "" {
  		clientType := strings.SplitN(request.UserAgent(), "/", 2)[0]
  		switch strings.ToLower(clientType) {
  		case "curl", "wget", "python-urllib":
  			return formatRAW
  		}
  	}
  
  	// Default to some sort of HTML mode, decide if it's full or lite.
  	if request.URL.Fragment != "" {
  		return formatHTMLFull // URL fragment requires full mode.
  	}
  	if cookie, err := request.Cookie("html-mode"); err == nil && cookie.Value == formatHTMLFull {
  		return formatHTMLFull
  	}
  	return formatHTMLLite
  }
docs: // resolveFormat resolves the output format to serve to the user.
  // This could be "html", "lite", "full", or "raw".
  // Here we try to be smart, and detect if the user is a web browser, or a CLI tool (E.G. cURL).
  // For web browsers, default to HTML mode, unless ?format=raw is specified.
  // For CLI tools, default to raw mode, unless ?format=html is specified.
  // HTML mode has two modes, "lite" and "full".  Lite is default, unless:
  //   * The user has a cookie specifying preference to full mode.
  //   * A URL fragment is detected in the path.
  // If we can't figure anything out, default to HTML lite mode.
  // We do this before path parsing to figure out which mode we want
  // to render parsing errors in.