Skip to content

Commit 7e985fe

Browse files
feat: support setting headers via env
1 parent da44eaf commit 7e985fe

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

client.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/http"
88
"os"
99
"slices"
10+
"strings"
1011

1112
"github.com/openlayer-ai/openlayer-go/internal/requestconfig"
1213
"github.com/openlayer-ai/openlayer-go/option"
@@ -35,6 +36,14 @@ func DefaultClientOptions() []option.RequestOption {
3536
if o, ok := os.LookupEnv("OPENLAYER_API_KEY"); ok {
3637
defaults = append(defaults, option.WithAPIKey(o))
3738
}
39+
if o, ok := os.LookupEnv("OPENLAYER_CUSTOM_HEADERS"); ok {
40+
for _, line := range strings.Split(o, "\n") {
41+
colon := strings.Index(line, ":")
42+
if colon >= 0 {
43+
defaults = append(defaults, option.WithHeader(strings.TrimSpace(line[:colon]), strings.TrimSpace(line[colon+1:])))
44+
}
45+
}
46+
}
3847
return defaults
3948
}
4049

0 commit comments

Comments
 (0)