Skip to content

Commit 62a86b6

Browse files
authored
feat!: replace to httputil.ReverseProxy (#1059)
Closes #1054
1 parent 50d85c8 commit 62a86b6

File tree

24 files changed

+831
-1051
lines changed

24 files changed

+831
-1051
lines changed

.github/workflows/go.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ jobs:
1414
strategy:
1515
matrix:
1616
go-version:
17-
- '1.19'
1817
- '1.20'
1918
- '1.21'
2019

cmd/manael/doc.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
//
2323
// Usage:
2424
//
25-
// manael [arguments]
25+
// manael [arguments]
2626
//
2727
// Example:
2828
//
29-
// manael -http=:8080 -upstream_url=http://localhost:9000
30-
//
29+
// manael -http=:8080 -upstream_url=http://localhost:9000
3130
package main

cmd/manael/main.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020

21-
package main // import "manael.org/x/manael/cmd/manael"
21+
package main
2222

2323
import (
2424
"flag"
2525
"fmt"
2626
"log"
2727
"net/http"
28+
"net/url"
2829
"os"
2930

3031
"github.com/gorilla/handlers"
31-
"manael.org/x/manael"
32+
"manael.org/x/manael/v2"
3233
)
3334

3435
const (
@@ -76,12 +77,16 @@ func main() {
7677
}
7778
}
7879

80+
upstreamURL, err := url.Parse(conf.upstreamURL)
81+
if err != nil {
82+
log.Fatalf("Error: %v", err)
83+
}
84+
7985
var handler http.Handler
80-
handler = manael.NewServeProxy(conf.upstreamURL)
86+
handler = manael.NewServeProxy(upstreamURL)
8187
handler = handlers.CombinedLoggingHandler(os.Stdout, handler)
8288

83-
err := http.ListenAndServe(conf.httpAddr, handler)
84-
if err != nil {
85-
log.Fatal(err)
89+
if err := http.ListenAndServe(conf.httpAddr, handler); err != nil {
90+
log.Fatalf("Error: %v", err)
8691
}
8792
}

decode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020

21-
package manael // import "manael.org/x/manael"
21+
package manael
2222

2323
import (
2424
"errors"

encode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020

21-
package manael // import "manael.org/x/manael"
21+
package manael
2222

2323
import (
2424
"errors"

example_test.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,25 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020

21-
package manael_test // import "manael.org/x/manael"
21+
package manael_test
2222

2323
import (
24-
"fmt"
2524
"log"
2625
"net/http"
26+
"net/url"
2727

28-
"manael.org/x/manael"
28+
"manael.org/x/manael/v2"
2929
)
3030

3131
func ExampleNewServeProxy() {
32-
p := manael.NewServeProxy("http://localhost:9000")
33-
34-
err := http.ListenAndServe(":8080", p)
32+
u, err := url.Parse("http://localhost:9000")
3533
if err != nil {
3634
log.Fatal(err)
3735
}
38-
}
3936

40-
func ExampleNewResponse() {
41-
req, err := http.NewRequest(http.MethodGet, "https://manael.test/", nil)
42-
if err != nil {
37+
p := manael.NewServeProxy(u)
38+
39+
if err := http.ListenAndServe(":8080", p); err != nil {
4340
log.Fatal(err)
4441
}
45-
46-
resp := manael.NewResponse(req, http.StatusOK)
47-
48-
fmt.Println(resp.StatusCode)
49-
// Output: 200
5042
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module manael.org/x/manael
1+
module manael.org/x/manael/v2
22

33
go 1.21
44

internal/testutil/testutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020

21-
package testutil // import "manael.org/x/manael/internal/testutil"
21+
package testutil
2222

2323
import (
2424
"image"

internal/testutil/testutil_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
// SOFTWARE.
2020

2121
// Package manael provides HTTP handler for processing images.
22-
package testutil_test // import "manael.org/x/manael/internal/testutil"
22+
package testutil_test
2323

2424
import (
2525
"os"
2626
"testing"
2727

28-
"manael.org/x/manael/internal/testutil"
28+
"manael.org/x/manael/v2/internal/testutil"
2929
)
3030

3131
var testutilTests = []struct {

lint-staged.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
'*.go': 'go fmt',
2+
// '*.go': 'go fmt',
33
'*.{js,jsx,ts,tsx}': 'eslint --fix',
44
'*.{json,yml}': 'prettier --write'
55
}

0 commit comments

Comments
 (0)