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?