mirror of
https://github.com/Infisical/infisical.git
synced 2025-03-31 22:09:57 +00:00
Update go.mdx
This commit is contained in:
@ -17,16 +17,17 @@ If you're working with Go Lang, the official [Infisical Go SDK](https://github.c
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
infisical "github.com/infisical/go-sdk"
|
||||
"fmt"
|
||||
"os"
|
||||
"context"
|
||||
infisical "github.com/infisical/go-sdk"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
client := infisical.NewInfisicalClient(infisical.Config{
|
||||
client := infisical.NewInfisicalClient(context.Background(), infisical.Config{
|
||||
SiteUrl: "https://app.infisical.com", // Optional, default is https://app.infisical.com
|
||||
AutoTokenRefresh: true, // Wether or not to let the SDK handle the access token lifecycle. Defaults to true if not specified.
|
||||
})
|
||||
|
||||
_, err = client.Auth().UniversalAuthLogin("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET")
|
||||
@ -64,12 +65,41 @@ This example demonstrates how to use the Infisical Go SDK in a simple Go applica
|
||||
```console
|
||||
$ go get github.com/infisical/go-sdk
|
||||
```
|
||||
|
||||
## Automatic token refreshing
|
||||
|
||||
The Infisical Go SDK supports automatic token refreshing. After using one of the auth methods such as Universal Auth, the SDK will automatically renew and re-authenticate when needed.
|
||||
This behavior is enabled by default, but you can opt-out by setting `AutoTokenRefresh` to `false` in the client settings.
|
||||
|
||||
```go
|
||||
client := infisical.NewInfisicalClient(context.Background(), infisical.Config{
|
||||
AutoTokenRefresh: false, // <- Disable automatic token refreshing
|
||||
})
|
||||
```
|
||||
|
||||
When using automatic token refreshing it's important to understand how your application uses the Infiiscal client. If you are instantiating new instances of the client often, it's important to cancel the context when the client is no longer needed to avoid the token refreshing process from running indefinitely.
|
||||
|
||||
```go
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel() // Cancel the context when the client is no longer needed
|
||||
|
||||
client := infisical.NewInfisicalClient(ctx, infisical.Config{
|
||||
AutoTokenRefresh: true,
|
||||
})
|
||||
|
||||
// Use the client
|
||||
```
|
||||
|
||||
This is only necessary if you are creating multiple instances of the client, and those instances are deleted or otherwise removed throughout the application lifecycle.
|
||||
If you are only creating one instance of the client, and it will be used throughout the lifetime of your application, you don't need to worry about this.
|
||||
|
||||
|
||||
# Configuration
|
||||
|
||||
Import the SDK and create a client instance.
|
||||
|
||||
```go
|
||||
client := infisical.NewInfisicalClient(infisical.Config{
|
||||
client := infisical.NewInfisicalClient(context.Background(), infisical.Config{
|
||||
SiteUrl: "https://app.infisical.com", // Optional, default is https://api.infisical.com
|
||||
})
|
||||
```
|
||||
@ -78,13 +108,21 @@ client := infisical.NewInfisicalClient(infisical.Config{
|
||||
|
||||
<ParamField query="options" type="object">
|
||||
<Expandable title="properties">
|
||||
<ParamField query="SiteUrl" type="string" optional>
|
||||
The URL of the Infisical API. Default is `https://api.infisical.com`.
|
||||
<ParamField query="SiteUrl" type="string" optional default="https://app.infisical.com">
|
||||
The URL of the Infisical API..
|
||||
</ParamField>
|
||||
|
||||
<ParamField query="UserAgent" type="string" required>
|
||||
<ParamField query="UserAgent" type="string">
|
||||
Optionally set the user agent that will be used for HTTP requests. _(Not recommended)_
|
||||
</ParamField>
|
||||
|
||||
<ParamField query="AutoTokenRefresh" type="boolean" default={true} optional>
|
||||
Whether or not to let the SDK handle the access token lifecycle. Defaults to true if not specified.
|
||||
</ParamField>
|
||||
|
||||
<ParamField query="SilentMode" type="boolean" default={false} optional>
|
||||
Whether or not to suppress logs such as warnings from the token refreshing process. Defaults to false if not specified.
|
||||
</ParamField>
|
||||
</Expandable>
|
||||
|
||||
</ParamField>
|
||||
@ -567,4 +605,6 @@ Delete a folder in Infisical.
|
||||
The path from where the folder should be deleted.
|
||||
</ParamField>
|
||||
</Expandable>
|
||||
</ParamField>
|
||||
</ParamField>
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user