Commits

desmaj committed 2445cc5

created the config package

Comments (0)

Files changed (7)

src/aquchinchay/clients.go

 package aquchinchay
 
-func getClientFactory(factoryName string) func (ClientConfig) RemoteClient {
-	return map[string]func (ClientConfig) RemoteClient{
+import (
+	"aquchinchay/config"
+)
+
+func getClientFactory(factoryName string) func (config.ClientConfig) RemoteClient {
+	return map[string]func (config.ClientConfig) RemoteClient{
 		"echo": OpenEcho,
 		"proxy": OpenProxy}[factoryName]
 }
 
-func MakeClient(clientConfig ClientConfig) func () RemoteClient {
+func MakeClient(clientConfig config.ClientConfig) func () RemoteClient {
 	clientFactory := getClientFactory(clientConfig["Client"])
 	return func () RemoteClient {
 		client := clientFactory(clientConfig)

src/aquchinchay/config.go

-package aquchinchay
-
-import (
-	"encoding/json"
-	"io/ioutil"
-)
-
-type ClientConfig map[string]string
-
-type ServiceConfig struct {
-	ListenerAddress string
-	ClientConfig ClientConfig
-}
-
-type GlobalConfig struct {
-	Servers []ServiceConfig
-	StaticDirectory string
-}
-
-func LoadConfig (configPath string) GlobalConfig {
-	configJSON, err := ioutil.ReadFile(configPath)
-	if err != nil {
-		panic(err)
-	}
-	var rawConfig GlobalConfig
-	err = json.Unmarshal(configJSON, &rawConfig)
-	if err != nil {
-		panic(err)
-	}
-	return rawConfig
-}

src/aquchinchay/config/config.go

+package config
+
+import (
+	"encoding/json"
+	"io/ioutil"
+)
+
+type ClientConfig map[string]string
+
+type ServiceConfig struct {
+	ListenerAddress string
+	ClientConfig ClientConfig
+}
+
+type GlobalConfig struct {
+	Servers []ServiceConfig
+	StaticDirectory string
+}
+
+func LoadConfig (configPath string) GlobalConfig {
+	configJSON, err := ioutil.ReadFile(configPath)
+	if err != nil {
+		panic(err)
+	}
+	var rawConfig GlobalConfig
+	err = json.Unmarshal(configJSON, &rawConfig)
+	if err != nil {
+		panic(err)
+	}
+	return rawConfig
+}

src/aquchinchay/csp/server.go

 
 import (
 	"aquchinchay"
+	"aquchinchay/config"
 	"crypto/rand"
 	"encoding/json"
 	"fmt"
 }
 
 func NewServer (
-	globalConfig aquchinchay.GlobalConfig,
-	serverConfig aquchinchay.ServiceConfig) CSPServer {
+	globalConfig config.GlobalConfig,
+	serverConfig config.ServiceConfig) CSPServer {
 	server := CSPServer{
 		make(map[string]CSPSession), 
 		aquchinchay.MakeClient(serverConfig.ClientConfig),
 }
 
 func StartServer (
-	globalConfig aquchinchay.GlobalConfig,
-	serverConfig aquchinchay.ServiceConfig,
+	globalConfig config.GlobalConfig,
+	serverConfig config.ServiceConfig,
 	resultChan chan error) {
 	server := NewServer(globalConfig, serverConfig)
 	server.start(serverConfig.ListenerAddress, resultChan)

src/aquchinchay/echo.go

 package aquchinchay
 
 import (
+	"aquchinchay/config"
 	"fmt"
 )
 
 	channel chan string
 }
 
-func OpenEcho (clientConfig ClientConfig) RemoteClient {
+func OpenEcho (clientConfig config.ClientConfig) RemoteClient {
 	client := EchoClient{make(chan string, 1024)}
 	return client
 }

src/aquchinchay/proxy.go

 package aquchinchay
 
 import (
+	"aquchinchay/config"
 	"encoding/base64"
 	"fmt"
 	"log"
 	RemoteAddress string
 }
 
-func OpenProxy (clientConfig ClientConfig) RemoteClient {
+func OpenProxy (clientConfig config.ClientConfig) RemoteClient {
 	return &TCPProxyClient{
 		make(chan string, 1024), 
 		nil, 
 package main
 
 import (
-	"aquchinchay"
+	"aquchinchay/config"
 	"aquchinchay/csp"
 	"flag"
 	"fmt"
 	if len(args) > 0 {
 		configPath = args[0]
 	}
-	config := aquchinchay.LoadConfig(configPath)
-	resultChan := make(chan error, len(config.Servers))
-	for _, serviceConfig := range(config.Servers) {
-		csp.StartServer(config, serviceConfig, resultChan)
+	globalConfig := config.LoadConfig(configPath)
+	resultChan := make(chan error, len(globalConfig.Servers))
+	for _, serviceConfig := range(globalConfig.Servers) {
+		csp.StartServer(globalConfig, serviceConfig, resultChan)
 	}
 	err := <- resultChan
  	fmt.Println(err)