How can I extend a function from another package

I’m using a package that is reading ENV from the ENV_VaRIABES, as below:

func New() (*LLM, error) {
	token := os.Getenv(tokenEnvVarName)
	if token == "" {
		return nil, ErrMissingToken
	}
	c, err := huggingfaceclient.New(token)
	return &LLM{
		client: c,
	}, err
}

I know I can modify it to read the key from .env file, using godotenv like:

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/joho/godotenv"
)

func main() {
	err := godotenv.Load() // will load the ".env" file
	if err != nil {
		log.Fatalf("Some error occured. Err: %s", err)
	}

	env := os.Getenv("HUGGINGFACEHUB_API_TOKEN")
	if "" == env {
             log.Fatalf("Can not find the API")
       }
}

Is there a way to modify the New() function through something like an extension to be used in my golang code instead of modifying the package code itself?

I solved it by creating a wrapper function around the New() function that loads the environment variables from the .env file using godotenv before calling the original New() function.

package main

import (
	"fmt"
	"log"

	"github.com/joho/godotenv"
	hf "github.com/tmc/langchaingo/llms/huggingface"
)

func NewWithDotEnv() (*hf.LLM, error) {
	err := godotenv.Load()
	if err != nil {
		return nil, err
	}
	return hf.New()
}

func main() {
	llm, err := NewWithDotEnv()
	if err != nil {
		log.Fatal(err)
	}
	completion, err := llm.Call("What would be a good company name for a company that makes colorful socks?")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(completion)
}