Skip to content

Commit

Permalink
add dockerizing support
Browse files Browse the repository at this point in the history
  • Loading branch information
zkrhm committed Sep 2, 2018
1 parent 8310608 commit e3d2db9
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 9 deletions.
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.10.4

RUN mkdir -p $GOPATH/src/github.com/zkrhm/imd-socialnetwork
WORKDIR $GOPATH/src/github.com/zkrhm/imd-socialnetwork/

COPY . .
COPY Gopkg.toml Gopkg.lock ./

RUN apt-get install curl
RUN curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh

RUN dep ensure -vendor-only
RUN go install

ENTRYPOINT [ "imd-socialnetwork" ]

EXPOSE 8000

6 changes: 1 addition & 5 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,4 @@

[[constraint]]
name = "github.com/oleiade/reflections"
version = "1.0.0"

[[constraint]]
name = "github.com/Benjamintf1/ExpandedUnmarshalledMatchers"
branch = "master"
version = "1.0.0"
4 changes: 4 additions & 0 deletions app/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ func (app *App) ListSubscribers(w http.ResponseWriter, r *http.Request){
Message : err.Error(),
Success: false,
})

return
}

subscribers, err := app.DB.GetFriendList(User(reqObj.Email))
Expand All @@ -187,6 +189,8 @@ func (app *App) ListSubscribers(w http.ResponseWriter, r *http.Request){
Message: err.Error(),

})

return
}

helper.WriteReponse(w, SubscriberListResponse{
Expand Down
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3'
services:
friend-mgt:
build: .
ports:
- "8000:8000"
8 changes: 5 additions & 3 deletions helper/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package helper

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"github.com/oleiade/reflections"
Expand All @@ -21,6 +20,7 @@ func GetRequest(r *http.Request, reqObj interface{}) error {

func WriteReponse(w http.ResponseWriter, resObj interface{}) error {

w.Header().Set("Content-Type", "application/json")

hasField , err := reflections.HasField(resObj, "Code")
if err != nil {
Expand Down Expand Up @@ -50,7 +50,9 @@ func WriteReponse(w http.ResponseWriter, resObj interface{}) error {
if err != nil {
return err
}
w.Header().Set("Content-type", "application/json")
fmt.Fprintln(w, string(b))


w.Write(b)

return nil
}
Binary file modified imd-socialnetwork
Binary file not shown.
15 changes: 14 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
package main

import (
"fmt"
"strconv"
"os"
"github.com/zkrhm/imd-socialnetwork/db"
"github.com/zkrhm/imd-socialnetwork/app"
)

func main() {
port := os.Getenv("APP_PORT")

if port == "" {
port = ":8000"
}
iport, err := strconv.Atoi(port)
if err == nil {
port = fmt.Sprintf(":%d",iport)
}

app := app.NewApp()
db, err := db.NewCayleyStore()
if err != nil {
Expand All @@ -14,5 +27,5 @@ func main() {
app.UseDb(db)
app.Initialize()

app.Run("localhost:8000")
app.Run(port)
}

0 comments on commit e3d2db9

Please sign in to comment.