Skip to content

Commit

Permalink
docs: enhance documentation with custom client and proxy examples
Browse files Browse the repository at this point in the history
- Rename "Sample Usage" section to "Usage"
- Add a section for using a custom HTTP client with example code
- Add a section for using a custom proxy server with example code

Signed-off-by: appleboy <[email protected]>
  • Loading branch information
appleboy committed May 25, 2024
1 parent ad6019a commit 83a5230
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ See the more detail information [here][12].
[11]: https://console.firebase.google.com/project/_/settings/serviceaccounts/adminsdk
[12]: https://firebase.google.com/docs/cloud-messaging/auth-server#provide-credentials-using-adc

## Sample Usage
## Usage

Here is a simple example illustrating how to use FCM library:

Expand Down Expand Up @@ -190,3 +190,47 @@ func main() {
}
}
```

### Custom HTTP Client

You can use a custom HTTP client by passing it to the `NewClient` function:

```go
func main() {
httpTimeout := time.Duration(5) * time.Second
tlsTimeout := time.Duration(5) * time.Second

transport := &http2.Transport{
DialTLS: func(network, addr string, cfg *tls.Config) (net.Conn, error) {
return tls.DialWithDialer(&net.Dialer{Timeout: tlsTimeout}, network, addr, cfg)
},
}

httpClient := &http.Client{
Transport: transport,
Timeout: httpTimeout,
}

ctx := context.Background()
client, err := fcm.NewClient(
ctx,
fcm.WithCredentialsFile("path/to/serviceAccountKey.json"),
fcm.WithHTTPClient(httpClient),
)
}
```

### Custom Proxy Server

You can use a custom proxy server by passing it to the `NewClient` function:

```go
func main() {
ctx := context.Background()
client, err := fcm.NewClient(
ctx,
fcm.WithCredentialsFile("path/to/serviceAccountKey.json"),
fcm.WithHTTPProxy("http://localhost:8088"),
)
}
```

0 comments on commit 83a5230

Please sign in to comment.