diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..226151e --- /dev/null +++ b/config/config.go @@ -0,0 +1,17 @@ +package config + +type Config struct { + Server Server + Services map[string]Service +} + +type Server struct { + Address string + Port int +} + +type Service struct { + BaseURL string + ForwardTo string + Protocol string +} diff --git a/config/test/sample.json b/config/test/sample.json new file mode 100644 index 0000000..b1c6df8 --- /dev/null +++ b/config/test/sample.json @@ -0,0 +1,18 @@ +{ + "server": { + "address": "127.0.0.1", + "port": 8080 + }, + "services": { + "test-app1": { + "baseUrl": "test/", + "forwardTo": "127.0.0.1:3030/", + "protocol": "http" + }, + "test-app2": { + "baseUrl": "test2/", + "forwardTo": "httpbin.org/", + "protocol": "http" + } + } +} \ No newline at end of file diff --git a/go.mod b/go.mod index b60d587..f9239a4 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module vegvisir go 1.13 + +require github.com/opentracing/opentracing-go v1.2.0 // indirect diff --git a/main.go b/main.go index da29a2c..a376935 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,10 @@ package main +import ( + "vegvisir/server" +) + func main() { + s := server.NewServer() + err := s.LoadConfig("config/test/sample.json") } diff --git a/server/server.go b/server/server.go new file mode 100644 index 0000000..c9ffca7 --- /dev/null +++ b/server/server.go @@ -0,0 +1,31 @@ +package server + +import ( + "encoding/json" + "io/ioutil" + "os" + "vegvisir/config" +) + +type Server struct { + Config config.Config +} + +func NewServer() Server { + return Server{} +} + +func (s *Server) LoadConfig(file string) error { + if _, err := os.Stat(file); err != nil { + return err + } + + data, err := ioutil.ReadFile(file) + if err != nil { + return err + } + + json.Unmarshal(data, &s.Config) + + return nil +}