github.com/grokify/go-ringcentral-client@v0.3.31/office/v1/examples/setup.go (about)

     1  package examples
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/joho/godotenv"
     7  
     8  	rc "github.com/grokify/go-ringcentral-client/office/v1/client"
     9  	"github.com/grokify/goauth"
    10  	ro "github.com/grokify/goauth/ringcentral"
    11  )
    12  
    13  func LoadEnv() error {
    14  	envPaths := []string{}
    15  	if len(os.Getenv("ENV_PATH")) > 0 {
    16  		envPaths = append(envPaths, os.Getenv("ENV_PATH"))
    17  	}
    18  	return godotenv.Load(envPaths...)
    19  }
    20  
    21  func NewApiClient() (*rc.APIClient, error) {
    22  	httpClient, err := ro.NewClientPassword(
    23  		goauth.NewCredentialsOAuth2Env("RINGCENTRAL_"))
    24  	if err != nil {
    25  		return nil, err
    26  	}
    27  
    28  	apiConfig := rc.NewConfiguration()
    29  	apiConfig.BasePath = os.Getenv("RINGCENTRAL_SERVER_URL")
    30  	apiConfig.HTTPClient = httpClient
    31  	apiClient := rc.NewAPIClient(apiConfig)
    32  	return apiClient, nil
    33  }