Skip to content

Commit

Permalink
publish as package
Browse files Browse the repository at this point in the history
  • Loading branch information
navigaid committed Jan 14, 2024
1 parent 700660c commit 43a76bc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.sum
portmux
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# portmux

[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white)](https://pkg.go.dev/github.com/btwiuse/portmux?tab=doc)
[![Go 1.18+](https://img.shields.io/github/go-mod/go-version/btwiuse/portmux)](https://golang.org/dl/)
[![License](https://img.shields.io/github/license/btwiuse/portmux?color=%23000&style=flat-round)](https://github.com/btwiuse/portmux/blob/main/LICENSE)

Port multiplexer: a reverse proxy that exposes HTTP / WS endpoints with UI on a single PORT

## Install

```
$ go install github.com/btwiuse/portmux@latest
$ go install github.com/btwiuse/portmux/cmd/portmux@latest
```

## Examples
Expand Down
13 changes: 6 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package portmux

import (
"fmt"
Expand Down Expand Up @@ -140,18 +140,17 @@ func (p *PortMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}

func main() {
func Run(args []string) error {
port := envPORT(":8000")
mux := NewPortMux(&Options{
argv: portmuxArgv(),
argv: args,
ui: portmuxUI(),
ws: portmuxWS(),
http: portmuxHTTP(),
})
if u := portmuxUFO(); u != nil {
log.Fatalln(wtf.Serve(*u, mux))
return
return wtf.Serve(*u, mux)
}
log.Println(fmt.Sprintf("listening on http://127.0.0.1%s", port))
log.Fatalln(http.ListenAndServe(port, mux))
log.Println(fmt.Sprintf("No PORTMUX_UFO envvar found, listening on http://127.0.0.1%s", port))
return http.ListenAndServe(port, mux)
}

0 comments on commit 43a76bc

Please sign in to comment.