Skip to content

Commit

Permalink
Adding code for the proxy
Browse files Browse the repository at this point in the history
Signed-off-by: Will Fisher <whfisher@alaska.edu>
  • Loading branch information
teknofire committed Feb 29, 2024
1 parent 2ccd5d1 commit 7101d1d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@ Dead simple http reverse proxy

## Build using

env GOOS=windows GOARCH=amd64 go build main.go
### Building for default OS

```bash
mkdir build
go build -o build/gorp
```

### Building for Windows
```bash
mkdir build
env GOOS=windows GOARCH=amd64 go build -o build/gorp.exe
```
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/acep-devops/gorp

go 1.21.4
40 changes: 40 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"flag"
"fmt"
"log"
"net/http"
"net/http/httputil"
"net/url"
)

func createReverseProxy(target string) (http.Handler, error) {
targetURL, err := url.Parse(target)
if err != nil {
return nil, err
}

proxy := httputil.NewSingleHostReverseProxy(targetURL)

return proxy, nil
}

func main() {
var port int
flag.IntVar(&port, "p", 9999, "port to serve on")
flag.Parse()

fmt.Println(port)

target := "http://127.0.0.1:55235"
proxy, err := createReverseProxy(target)
if err != nil {
log.Fatal(err)
}

http.Handle("/", proxy)

log.Printf("Starting reverse proxy server on port %d, forwarding requests to %s", port, target)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
}

0 comments on commit 7101d1d

Please # to comment.