Skip to content

Commit

Permalink
build client
Browse files Browse the repository at this point in the history
  • Loading branch information
onyas committed Aug 19, 2022
1 parent 7f40f7e commit 0bfbaf6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ggrok
ggrok
dist/
26 changes: 26 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
27 changes: 5 additions & 22 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ package main
import (
"flag"
"log"
"net/http"
"os"

"github.com/onyas/ggrok/core"
)

var client bool
var proxyServer string
var port int
var config *core.Config

func init() {
flag.BoolVar(&client, "client", false, "start client")
flag.StringVar(&proxyServer, "proxyServer", "", "provide server address, for example: https://proxy.yourdomain.com")
flag.IntVar(&port, "port", -1, "provide port, for example: 8080")
config = core.NewConfig()
Expand All @@ -25,29 +21,16 @@ func main() {
flag.Parse()
log.SetFlags(0)

if client {
if proxyServer != "" {
saveToConfig(proxyServer)
return
}

if port != -1 {
startProxy(port)
}
log.Println("Using -proxyServer or -port args")
if proxyServer != "" {
saveToConfig(proxyServer)
return
}

port := os.Getenv("PORT")
if port == "" {
log.Fatal("$PORT must be set")
if port != -1 {
startProxy(port)
}
s := core.NewServer()
log.Println("Using -proxyServer or -port args")

http.HandleFunc("/$$ggrok", s.Register)
http.HandleFunc("/", s.Proxy)
log.Println("Server started at port:", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}

func saveToConfig(proxyServer string) {
Expand Down

0 comments on commit 0bfbaf6

Please sign in to comment.