summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHorus32015-04-21 07:04:00 +0200
committerHorus32015-04-21 07:04:00 +0200
commit9d86a3c05ec4339da74dae6cc3bf2f91d49f1574 (patch)
treebe12d7bf0cbe847ed30f177acc48fa9e99bfe1eb
parent7e4ccc40be46366fd8c0550aca1bfb6e73c3b5c6 (diff)
downloadmandible-9d86a3c05ec4339da74dae6cc3bf2f91d49f1574.tar.gz
Add Ip to config.
-rw-r--r--config/config.go1
-rw-r--r--config/default.conf.json1
-rwxr-xr-xrun.sh1
-rw-r--r--server/server.go9
4 files changed, 11 insertions, 1 deletions
diff --git a/config/config.go b/config/config.go
index b1022e2..44640c2 100644
--- a/config/config.go
+++ b/config/config.go
@@ -12,6 +12,7 @@ type Configuration struct {
UserAgent string
Stores []map[string]string
Port int
+ Ip string
}
func NewConfiguration(path string) *Configuration {
diff --git a/config/default.conf.json b/config/default.conf.json
index 2b7520e..03362ec 100644
--- a/config/default.conf.json
+++ b/config/default.conf.json
@@ -1,5 +1,6 @@
{
"Port": 8080,
+ "Ip": "127.0.0.1",
"MaxFileSize": 20971520,
"HashLength": 7,
"UserAgent": "Mandible",
diff --git a/run.sh b/run.sh
index 27c86ae..7c20eaa 100755
--- a/run.sh
+++ b/run.sh
@@ -22,6 +22,7 @@ fi
echo "Running $APP..."
+export PORT=8087
STATIC_DIR=$(pwd)/static \
IMGUR_GO_CONF=$(pwd)/config/conf.json \
UPLOAD_DIR=$(pwd)/files \
diff --git a/server/server.go b/server/server.go
index e55d2e1..37fa8aa 100644
--- a/server/server.go
+++ b/server/server.go
@@ -68,12 +68,14 @@ func (s *Server) uploadFile(uploadFile io.Reader, w http.ResponseWriter, fileNam
processor, err := imageprocessor.Factory(s.Config.MaxFileSize, upload)
if err != nil {
+ log.Println(err)
ErrorResponse(w, "Unable to process image!", http.StatusInternalServerError)
return
}
err = processor.Run(upload)
if err != nil {
+ log.Println(err)
ErrorResponse(w, "Unable to process image!", http.StatusInternalServerError)
return
}
@@ -233,8 +235,13 @@ func (s *Server) Start() {
if port == ":" {
port = fmt.Sprintf(":%d", s.Config.Port)
}
+ ip := os.Getenv("IP")
+ if ip == "" {
+ ip = fmt.Sprintf("%s", s.Config.Ip)
+ }
- log.Panic(http.ListenAndServe(port, nil))
+ fmt.Println("Starting server listening on " + ip + port + ".")
+ log.Panic(http.ListenAndServe(ip+port, nil))
}
func (s *Server) download(url string) (io.ReadCloser, error) {