diff options
| -rw-r--r-- | config/config.go | 1 | ||||
| -rw-r--r-- | config/default.conf.json | 1 | ||||
| -rwxr-xr-x | run.sh | 1 | ||||
| -rw-r--r-- | server/server.go | 9 |
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", @@ -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) { |
