func TestConfigIsParsedCorrectly(t *testing.T) { jsonToParse := ` { "targetBaseUrl": "http://wpos.platform.nl", "authToken": "some-very-random-token", "mappings": [ { "from": "/update", "to": "/UpdateProductService" }, { "from": "/recover", "to": "/RecoverService" } ] } ` expectedMappingConfig := config.MappingConfig{ TargetBaseUrl: "http://wpos.platform.nl", AuthToken: "some-very-random-token", Mappings: []config.MappingPath{ config.MappingPath{From: "/update", To: "/UpdateProductService"}, config.MappingPath{From: "/recover", To: "/RecoverService"}, }, } mappings := config.Parse(strings.NewReader(jsonToParse)) if !reflect.DeepEqual(mappings, expectedMappingConfig) { t.Errorf("expected %+v, got %+v", expectedMappingConfig, mappings) } }
func main() { var bindPort int flag.IntVar(&bindPort, "port", 8080, "The port to bind on to receive requests") flag.Parse() logFile, err := os.OpenFile("log.txt", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { log.Fatal("Was unable to open log file", err) } defer logFile.Close() log.SetOutput(io.MultiWriter(os.Stdout, logFile)) configFile, err := os.Open("config.json") if err != nil { log.Fatal("Was unable to open config.json", err) } mappingConfig := config.Parse(configFile) defer configFile.Close() log.Println("Binding to port", fmt.Sprintf(":%d", bindPort)) ApplyMappings(&mappingConfig) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", bindPort), nil)) }