-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproxy.go
36 lines (29 loc) · 845 Bytes
/
proxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package proxy
import (
"fmt"
"net/http"
"github.com/speakeasy-api/speakeasy-go-sdk"
"github.com/speakeasy-api/speakeasy-proxy/internal/handler"
)
type Options struct {
DownstreamBaseURL string
Port string
APIKey string
ApiID string
VersionID string
OpenAPIDocument []byte
}
func StartProxy(opts Options) error {
handler := handler.NewHandler(opts.DownstreamBaseURL)
sdk := speakeasy.New(speakeasy.Config{
APIKey: opts.APIKey,
ApiID: opts.ApiID,
VersionID: opts.VersionID,
OpenAPIDocument: opts.OpenAPIDocument,
})
fmt.Printf("proxy listening on port %s and redirecting to %s\n", opts.Port, opts.DownstreamBaseURL)
if err := http.ListenAndServe(fmt.Sprintf(":%s", opts.Port), sdk.Middleware(handler)); err != nil {
return err
}
return nil
}