Files
plex-sdk-docs/content/pages/01-reference/go/server_options/_snippet.mdx

108 lines
2.2 KiB
Plaintext

{/* Start Go Server Options */}
### Select Server by Index
You can override the default server globally using the `WithServerIndex` option when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
#### Example
```go
package main
import (
"context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/components"
"log"
)
func main() {
s := plexgo.New(
plexgo.WithServerIndex(0),
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
)
ctx := context.Background()
res, err := s.Server.GetServerCapabilities(ctx)
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
```
#### Variables
Some of the server options above contain variables. If you want to set the values of those variables, the following options are provided for doing so:
* `WithProtocol plexgo.ServerProtocol`
* `WithIP string`
* `WithPort string`
### Override Server URL Per-Client
The default server can also be overridden globally using the `WithServerURL` option when initializing the SDK client instance. For example:
```go
package main
import (
"context"
"github.com/LukeHagar/plexgo"
"github.com/LukeHagar/plexgo/models/components"
"log"
)
func main() {
s := plexgo.New(
plexgo.WithServerURL("{protocol}://{ip}:{port}"),
plexgo.WithSecurity("<YOUR_API_KEY_HERE>"),
)
ctx := context.Background()
res, err := s.Server.GetServerCapabilities(ctx)
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
```
### Override Server URL Per-Operation
The server URL can also be overridden on a per-operation basis, provided a server list was specified for the operation. For example:
```go
package main
import (
"context"
"github.com/LukeHagar/plexgo"
"log"
)
func main() {
s := plexgo.New()
var xPlexClientIdentifier string = "<value>"
var strong *bool = plexgo.Bool(false)
ctx := context.Background()
res, err := s.Plex.GetPin(ctx, operations.WithServerURL("https://plex.tv/api/v2"), xPlexClientIdentifier, strong)
if err != nil {
log.Fatal(err)
}
if res.Object != nil {
// handle response
}
}
```
{/* End Go Server Options */}