Skip to content

Commit

Permalink
feat: specify config file path
Browse files Browse the repository at this point in the history
  • Loading branch information
muzea committed Sep 5, 2019
1 parent a457308 commit 8e54944
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion portfw.go → portfwd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package main

import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"net"
"net/http"
"os"
"path"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -70,7 +73,14 @@ func addProxyItem(localPort string, target string) {
}

func resolveConfig() {
configContent := getFileContent("./config.json")
wd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
configName := flag.String("config", path.Join(wd, "config.json"), "config file path")
flag.Parse()
log.Printf("use config %s", *configName)
configContent := getFileContent(*configName)
json.Unmarshal(configContent, &configResult)
for localPort, target := range configResult.Proxy {
go addProxyItem(localPort, target)
Expand Down

0 comments on commit 8e54944

Please sign in to comment.