Skip to content

Commit 730e45d

Browse files
committed
update outdated packages
Signed-off-by: Sertac Ozercan <[email protected]>
1 parent e114286 commit 730e45d

File tree

5 files changed

+64
-71
lines changed

5 files changed

+64
-71
lines changed

azure/model.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package azure
33
import (
44
"bytes"
55
"fmt"
6-
"github.com/pkg/errors"
76
"log"
87
"net/http"
98
"net/url"
@@ -74,7 +73,7 @@ func (c *TemplateConverter) Convert(req *http.Request, config *DeploymentConfig)
7473
}
7574
buff := new(bytes.Buffer)
7675
if err := c.Tempalte.Execute(buff, data); err != nil {
77-
return req, errors.Wrap(err, "template execute error")
76+
return req, fmt.Errorf("template execute error: %w", err)
7877
}
7978

8079
req.Host = config.EndpointUrl.Host

azure/proxy.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7+
"errors"
78
"fmt"
89
"io"
910
"log"
@@ -18,7 +19,6 @@ import (
1819

1920
"github.com/bytedance/sonic"
2021
"github.com/gin-gonic/gin"
21-
"github.com/pkg/errors"
2222
)
2323

2424
const cognitiveservicesScope = "https://cognitiveservices.azure.com/.default"
@@ -141,12 +141,12 @@ func Proxy(c *gin.Context, requestConverter RequestConverter) {
141141
if model == "" {
142142
_model, err := sonic.Get(body, "model")
143143
if err != nil {
144-
util.SendError(c, errors.Wrap(err, "get model error"))
144+
util.SendError(c, fmt.Errorf("get model error: %w", err))
145145
return
146146
}
147147
_modelStr, err := _model.String()
148148
if err != nil {
149-
util.SendError(c, errors.Wrap(err, "get model name error"))
149+
util.SendError(c, fmt.Errorf("get model name error: %w", err))
150150
return
151151
}
152152
model = _modelStr
@@ -161,40 +161,43 @@ func Proxy(c *gin.Context, requestConverter RequestConverter) {
161161

162162
// get auth token from header or deployment config
163163
token := deployment.ApiKey
164+
tokenFound := false
164165
if token == "" && token != "msi" {
165166
rawToken := req.Header.Get("Authorization")
166167
token = strings.TrimPrefix(rawToken, "Bearer ")
167168
req.Header.Set(APIKeyHeaderKey, token)
168169
req.Header.Del("Authorization")
170+
tokenFound = true
169171
}
170172
// get azure token using managed identity
171173
var azureToken azcore.AccessToken
172174
if token == "" || token == "msi" {
173175
cred, err := azidentity.NewManagedIdentityCredential(nil)
174176
if err != nil {
175-
util.SendError(c, errors.Wrap(err, "failed to create managed identity credential"))
177+
util.SendError(c, fmt.Errorf("failed to create managed identity credential: %w", err))
176178
}
177179

178180
azureToken, err = cred.GetToken(context.TODO(), policy.TokenRequestOptions{
179181
Scopes: []string{cognitiveservicesScope},
180182
})
181183
if err != nil {
182-
util.SendError(c, errors.Wrap(err, "failed to get token"))
184+
util.SendError(c, fmt.Errorf("failed to get token: %w", err))
183185
}
184186

185187
req.Header.Del(APIKeyHeaderKey)
186188
req.Header.Set(AuthHeaderKey, "Bearer "+azureToken.Token)
189+
tokenFound = true
187190
}
188191

189-
if token == "" && azureToken.Token == ""{
192+
if !tokenFound {
190193
util.SendError(c, errors.New("token is empty"))
191194
return
192195
}
193196

194197
originURL := req.URL.String()
195198
req, err = requestConverter.Convert(req, deployment)
196199
if err != nil {
197-
util.SendError(c, errors.Wrap(err, "convert request error"))
200+
util.SendError(c, fmt.Errorf("convert request error: %w", err))
198201
return
199202
}
200203
log.Printf("proxying request [%s] %s -> %s", model, originURL, req.URL.String())
@@ -203,7 +206,7 @@ func Proxy(c *gin.Context, requestConverter RequestConverter) {
203206
proxy := &httputil.ReverseProxy{Director: director}
204207
transport, err := util.NewProxyFromEnv()
205208
if err != nil {
206-
util.SendError(c, errors.Wrap(err, "get proxy error"))
209+
util.SendError(c, fmt.Errorf("get proxy error: %w", err))
207210
return
208211
}
209212
if transport != nil {
@@ -227,7 +230,7 @@ func Proxy(c *gin.Context, requestConverter RequestConverter) {
227230
func GetDeploymentByModel(model string) (*DeploymentConfig, error) {
228231
deploymentConfig, exist := ModelDeploymentConfig[model]
229232
if !exist {
230-
return nil, errors.New(fmt.Sprintf("deployment config for %s not found", model))
233+
return nil, fmt.Errorf("deployment config for %s not found", model)
231234
}
232235
return &deploymentConfig, nil
233236
}

cmd/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ package main
33
import (
44
"context"
55
"fmt"
6-
"github.com/spf13/pflag"
7-
"github.com/spf13/viper"
8-
"github.com/stulzq/azure-openai-proxy/azure"
96
"log"
107
"net/http"
118
"os"
129
"os/signal"
1310
"syscall"
1411

12+
"github.com/spf13/pflag"
13+
"github.com/spf13/viper"
14+
"github.com/stulzq/azure-openai-proxy/azure"
15+
1516
"github.com/gin-gonic/gin"
16-
"github.com/pkg/errors"
1717
)
1818

1919
var (
@@ -74,7 +74,7 @@ func runServer(srv *http.Server) {
7474
go func() {
7575
log.Printf("Server listening at %s\n", srv.Addr)
7676
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
77-
panic(errors.Errorf("listen: %s\n", err))
77+
panic(fmt.Errorf("listen: %w", err))
7878
}
7979
}()
8080

go.mod

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,41 @@ go 1.21
55
require (
66
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.11.1
77
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.5.2
8-
github.com/bytedance/sonic v1.10.2
9-
github.com/gin-gonic/gin v1.9.1
10-
github.com/pkg/errors v0.9.1
8+
github.com/bytedance/sonic v1.11.8
9+
github.com/gin-gonic/gin v1.10.0
1110
github.com/spf13/pflag v1.0.5
1211
github.com/spf13/viper v1.18.2
1312
github.com/stretchr/testify v1.9.0
14-
golang.org/x/net v0.22.0
13+
golang.org/x/net v0.25.0
1514
)
1615

1716
require (
1817
github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.2 // indirect
1918
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 // indirect
20-
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
21-
github.com/chenzhuoyu/iasm v0.9.1 // indirect
19+
github.com/bytedance/sonic/loader v0.1.1 // indirect
20+
github.com/cloudwego/base64x v0.1.4 // indirect
21+
github.com/cloudwego/iasm v0.2.0 // indirect
2222
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
2323
github.com/fsnotify/fsnotify v1.7.0 // indirect
2424
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
2525
github.com/gin-contrib/sse v0.1.0 // indirect
2626
github.com/go-playground/locales v0.14.1 // indirect
2727
github.com/go-playground/universal-translator v0.18.1 // indirect
28-
github.com/go-playground/validator/v10 v10.16.0 // indirect
28+
github.com/go-playground/validator/v10 v10.20.0 // indirect
2929
github.com/goccy/go-json v0.10.2 // indirect
3030
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
3131
github.com/google/uuid v1.6.0 // indirect
3232
github.com/hashicorp/hcl v1.0.0 // indirect
3333
github.com/json-iterator/go v1.1.12 // indirect
34-
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
34+
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
3535
github.com/kylelemons/godebug v1.1.0 // indirect
36-
github.com/leodido/go-urn v1.2.4 // indirect
36+
github.com/leodido/go-urn v1.4.0 // indirect
3737
github.com/magiconair/properties v1.8.7 // indirect
3838
github.com/mattn/go-isatty v0.0.20 // indirect
3939
github.com/mitchellh/mapstructure v1.5.0 // indirect
4040
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4141
github.com/modern-go/reflect2 v1.0.2 // indirect
42-
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
42+
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
4343
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
4444
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
4545
github.com/sagikazarmark/locafero v0.4.0 // indirect
@@ -51,12 +51,12 @@ require (
5151
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
5252
github.com/ugorji/go/codec v1.2.12 // indirect
5353
go.uber.org/multierr v1.11.0 // indirect
54-
golang.org/x/arch v0.6.0 // indirect
55-
golang.org/x/crypto v0.21.0 // indirect
54+
golang.org/x/arch v0.8.0 // indirect
55+
golang.org/x/crypto v0.23.0 // indirect
5656
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 // indirect
57-
golang.org/x/sys v0.18.0 // indirect
58-
golang.org/x/text v0.14.0 // indirect
59-
google.golang.org/protobuf v1.31.0 // indirect
57+
golang.org/x/sys v0.20.0 // indirect
58+
golang.org/x/text v0.15.0 // indirect
59+
google.golang.org/protobuf v1.34.1 // indirect
6060
gopkg.in/ini.v1 v1.67.0 // indirect
6161
gopkg.in/yaml.v3 v3.0.1 // indirect
6262
)

0 commit comments

Comments
 (0)