Skip to content

Commit

Permalink
Fix environment variables ordering by adding natural sort for envs
Browse files Browse the repository at this point in the history
  • Loading branch information
mgerasimchuk committed Oct 14, 2023
1 parent 293d2d5 commit ad4e499
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ These capabilities make Protty a useful tool for a variety of purposes, such as
The following command will start a proxy on port 8080, and after starting, all traffic from port 8080 will be redirected to a remote host located at https://example.com

```shell
docker run -p8080:80 -e REMOTE_URI=https://example.com:443 mgerasimchuk/protty:v0.4.2
docker run -p8080:80 -e REMOTE_URI=https://example.com:443 mgerasimchuk/protty:v0.4.3
```

## Running options and runtime configuration

```
» ~ docker run -p8080:80 -it mgerasimchuk/protty:v0.4.2 /bin/sh -c 'protty start --help'
» ~ docker run -p8080:80 -it mgerasimchuk/protty:v0.4.3 /bin/sh -c 'protty start --help'
Start the proxy
Usage:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module protty
go 1.20

require (
github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb
github.com/graze/go-throttled v0.3.1
github.com/itchyny/gojq v0.12.11
github.com/rwtodd/Go.Sed v0.0.0-20230610052213-ba3e9c186f0a
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb h1:IT4JYU7k4ikYg1SCxNI1/Tieq/NFvh6dzLdgi7eu0tM=
github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb/go.mod h1:bH6Xx7IW64qjjJq8M2u4dxNaBiDfKK+z/3eGDpXEQhc=
github.com/graze/go-throttled v0.3.1 h1:Mr9hMy0GXnbFlOWQl6pjNyn8T+9/LWIv1hJndNhs9mo=
github.com/graze/go-throttled v0.3.1/go.mod h1:OYBew5YhHxQqZGjoa7M8NQLIj+ztV+Iv5xCvzK1sQLg=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
Expand Down
5 changes: 4 additions & 1 deletion internal/infrastructure/config/start_command_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"crypto/md5"
"fmt"
"github.com/facette/natsort"
"github.com/sirupsen/logrus"
"net/http"
"net/url"
Expand Down Expand Up @@ -68,7 +69,9 @@ func (c *StartCommandConfig) SetFromEnv() error {

if optValueField.Kind() == reflect.Slice {
envValuesSlice := []string{}
for _, envPair := range os.Environ() {
sortedEnviron := os.Environ()
natsort.Sort(sortedEnviron)
for _, envPair := range sortedEnviron {
envPairSlice := strings.Split(envPair, "=")
eName, eVal := envPairSlice[0], envPairSlice[1]
if isMatch, _ := regexp.MatchString(envName+`(_\d+)?$`, eName); isMatch {
Expand Down

0 comments on commit ad4e499

Please sign in to comment.