Skip to content

✅ HasFunding

Checks whether there are any packages in the current project that declare funding support.

When to use

Use this when deciding whether to show a "fund the author" entry in your application UI, CLI prompts, or CI pipeline, avoiding showing an empty section when there are no fundable packages.

Signature

go
func (c *Composer) HasFunding() (bool, error)

Parameters

This method takes no parameters.

Return value

  • bool: true when there are fundable packages, otherwise false.
  • error: Returns the corresponding error message when running composer fund --format=text fails.

Example

go
package main

import (
	"fmt"
	"log"

	"github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
	comp, err := composer.New(composer.DefaultOptions())
	if err != nil {
		log.Fatalf("Initialization failed: %v", err)
	}

	has, err := comp.HasFunding()
	if err != nil {
		log.Fatalf("Failed to check funding: %v", err)
	}

	if has {
		fmt.Println("Fundable packages exist; run composer fund for details")
	} else {
		fmt.Println("No fundable packages in the project")
	}
}

Advanced

  • Detection logic: returns false when the composer fund --format=text output contains No funding.
  • For specific links, use GetFundingURLs; for structured details, use FundWithJSON; for plain text output, use Fund.

Released under the MIT License