Skip to content

Commit

Permalink
add the global forward function
Browse files Browse the repository at this point in the history
  • Loading branch information
xgfone committed Mar 4, 2024
1 parent fea3aea commit a51cd00
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions http/forwarder/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import (
// DefaultForwarder is the default request forwarder.
var DefaultForwarder = NewForwarder("")

// Forward is equal to DefaultForwarder.Forward(w, r, host).
func Forward(w http.ResponseWriter, r *http.Request, host string) error {
return DefaultForwarder.Forward(w, r, host)
}

// Forwarder is used to forwards a request to another host.
type Forwarder struct {
Scheme string
Expand Down
2 changes: 1 addition & 1 deletion http/forwarder/forwarder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestForwarder(t *testing.T) {

w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodPost, "/", nil)
err := DefaultForwarder.Forward(w, r, host)
err := Forward(w, r, host)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit a51cd00

Please sign in to comment.