Add config File and example conf
This commit is contained in:
3
domains.conf
Normal file
3
domains.conf
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
test.localhost;8181
|
||||||
|
test2.localhost;8282
|
||||||
|
localhost;8080
|
||||||
42
main.go
42
main.go
@@ -1,17 +1,28 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
configFileFlag = flag.String("config", "domains.conf", "Path to Domain config file")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
domains := make(map[string]int)
|
flag.Parse()
|
||||||
domains["test.localhost"] = 8181
|
domains, err := loadConfig(*configFileFlag)
|
||||||
domains["test2.localhost"] = 8282
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
CheckRedirect: func(req *http.Request, via []*http.Request) error {
|
||||||
@@ -104,3 +115,28 @@ func main() {
|
|||||||
fmt.Println("Starting server on :443")
|
fmt.Println("Starting server on :443")
|
||||||
http.ListenAndServeTLS(":443", "server.crt", "server.key", nil)
|
http.ListenAndServeTLS(":443", "server.crt", "server.key", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func loadConfig(path string) (map[string]int, error) {
|
||||||
|
file, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
scanner.Split(bufio.ScanLines)
|
||||||
|
|
||||||
|
m := make(map[string]int)
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
params := strings.Split(line, ";")
|
||||||
|
if len(params) <= 1 {
|
||||||
|
return nil, errors.New("Line does not contain enough Parameters")
|
||||||
|
}
|
||||||
|
port, err := strconv.Atoi(params[1])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
m[params[0]] = port
|
||||||
|
}
|
||||||
|
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user