Skip to content

Commit

Permalink
fixed startup crash for file provider
Browse files Browse the repository at this point in the history
  • Loading branch information
yusing committed Sep 21, 2024
1 parent a29bf88 commit 26e2154
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 18 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ A lightweight, easy-to-use, and [performant](docs/benchmark_result.md) reverse p

### Environment variables

| Environment Variable | Description | Default | Values |
| ------------------------------ | ------------------------- | ------- | ------- |
| `GOPROXY_NO_SCHEMA_VALIDATION` | disable schema validation | `false` | boolean |
| `GOPROXY_DEBUG` | enable debug behaviors | `false` | boolean |
| Environment Variable | Description | Default | Values |
| ------------------------------ | ----------------------------- | ------- | ------- |
| `GOPROXY_NO_SCHEMA_VALIDATION` | disable schema validation | `false` | boolean |
| `GOPROXY_DEBUG` | enable debug behaviors | `false` | boolean |
| `GOPROXY_HTTP_PORT` | http server port | `80` | integer |
| `GOPROXY_HTTPS_PORT` | http server port (if enabled) | `443` | integer |
| `GOPROXY_API_PORT` | api server port | `8888` | integer |

### Use JSON Schema in VSCode

Expand Down
6 changes: 0 additions & 6 deletions src/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ const (

const DockerHostFromEnv = "$DOCKER_HOST"

const (
ProxyHTTPPort = ":80"
ProxyHTTPSPort = ":443"
APIHTTPPort = ":8888"
)

var WellKnownHTTPPorts = map[uint16]bool{
80: true,
8000: true,
Expand Down
17 changes: 15 additions & 2 deletions src/common/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@ import (
U "github.com/yusing/go-proxy/utils"
)

var NoSchemaValidation = getEnvBool("GOPROXY_NO_SCHEMA_VALIDATION")
var IsDebug = getEnvBool("GOPROXY_DEBUG")
var (
NoSchemaValidation = getEnvBool("GOPROXY_NO_SCHEMA_VALIDATION")
IsDebug = getEnvBool("GOPROXY_DEBUG")
ProxyHTTPPort = ":" + getEnv("GOPROXY_HTTP_PORT", "80")
ProxyHTTPSPort = ":" + getEnv("GOPROXY_HTTPS_PORT", "443")
APIHTTPPort = ":" + getEnv("GOPROXY_API_PORT", "8888")
)

func getEnvBool(key string) bool {
return U.ParseBool(os.Getenv(key))
}

func getEnv(key string, defaultValue string) string {
value, ok := os.LookupEnv(key)
if !ok {
value = defaultValue
}
return value
}
2 changes: 0 additions & 2 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
R "github.com/yusing/go-proxy/route"
"github.com/yusing/go-proxy/server"
F "github.com/yusing/go-proxy/utils/functional"
W "github.com/yusing/go-proxy/watcher"
)

func main() {
Expand Down Expand Up @@ -92,7 +91,6 @@ func main() {
l.Warn(err)
}

W.InitFileWatcherHelper()
cfg.WatchChanges()

onShutdown.Add(docker.CloseAllClients)
Expand Down
4 changes: 4 additions & 0 deletions src/models/proxy_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ type (
var NewProxyEntries = F.NewMapOf[string, *ProxyEntry]

func (e *ProxyEntry) SetDefaults() {
if e.ProxyProperties == nil {
e.ProxyProperties = &D.ProxyProperties{}
}

if e.Scheme == "" {
switch {
case strings.ContainsRune(e.Port, ':'):
Expand Down
7 changes: 3 additions & 4 deletions src/watcher/file_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ func NewFileWatcher(filename string) Watcher {
}

func (f *fileWatcher) Events(ctx context.Context) (<-chan Event, <-chan E.NestedError) {
if fwHelper == nil {
fwHelper = newFileWatcherHelper(common.ConfigBasePath)
}
return fwHelper.Add(ctx, f)
}

func InitFileWatcherHelper() {
fwHelper = newFileWatcherHelper(common.ConfigBasePath)
}

var fwHelper *fileWatcherHelper

0 comments on commit 26e2154

Please sign in to comment.