mirror of
https://github.com/LukeHagar/plex-sdk-docs.git
synced 2025-12-06 04:20:46 +00:00
79 lines
1.6 KiB
Plaintext
79 lines
1.6 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
|
|
}
|
|
}
|
|
|
|
```
|
|
{/* End Go Server Options */}
|