✅ 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:truewhen there are fundable packages, otherwisefalse.error: Returns the corresponding error message when runningcomposer fund --format=textfails.
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
falsewhen thecomposer fund --format=textoutput containsNo funding. - For specific links, use
GetFundingURLs; for structured details, useFundWithJSON; for plain text output, useFund.