diff --git a/.gitignore b/.gitignore index dd99617..98d2148 100644 --- a/.gitignore +++ b/.gitignore @@ -63,4 +63,6 @@ fabric.properties vendor/ glide.lock -.DS_Store \ No newline at end of file +.DS_Store +dist/ +debug \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..27b0c7b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM alpine:latest + +ENV APP_VERSION=1.0.0 \ + APP_HOME=/service \ + APP_NAME=overflow_service_websocket + +WORKDIR ${APP_HOME} + +ADD dist/${APP_NAME} ${APP_HOME}/ +ADD config.json ${APP_HOME}/ + +EXPOSE 80 443 + +ENTRYPOINT ["./overflow_service_websocket"] + +# docker build -f Dockerfile -t docker.loafle.net/overflow/overflow_service_websocket:1.0.0-alpine . +# docker run -d -p 18081:80 -t docker.loafle.net/overflow/overflow_service_websocket:1.0.0-alpine diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..1ab2707 --- /dev/null +++ b/build.sh @@ -0,0 +1,2 @@ +rm ./dist/* +CGO_ENABLED=0 go build -a --installsuffix cgo --ldflags="-s" -o ./dist/overflow_service_websocket \ No newline at end of file diff --git a/config.json b/config.json index 3e6105f..0b2a307 100644 --- a/config.json +++ b/config.json @@ -1,7 +1,6 @@ { "server": { - "ip": "127.0.0.1", - "port": 18081, + "addr": ":80", "tls": false }, "websocket": { @@ -14,8 +13,7 @@ "writeBufferSize": 4096 }, "gRpc": { - "ip": "localhost", - "port": 50006, + "addr": "192.168.1.101:50006", "tls": false, "pool": { "initialCapacity": 30, diff --git a/config/config.go b/config/config.go index 7173c4a..c49aabe 100644 --- a/config/config.go +++ b/config/config.go @@ -13,8 +13,7 @@ type Config struct { } type ServerConfig struct { - Ip string `required:"true"` - Port uint16 `required:"true"` + Addr string `required:"true"` Tls bool `default:"false"` } diff --git a/main.go b/main.go index a5795a8..f88d640 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "log" "net/http" "os" @@ -17,7 +16,7 @@ func main() { // Initialize config config := loadConfig() - addr := fmt.Sprintf("%s:%d", config.Server.Ip, config.Server.Port) + addr := config.Server.Addr useTLS := config.Server.Tls sConfig := server.NewOptions(&config.Websocket) // Print banner diff --git a/protocol/jsonrpc/rpc.go b/protocol/jsonrpc/rpc.go index 0f8d2ce..b0b9a60 100644 --- a/protocol/jsonrpc/rpc.go +++ b/protocol/jsonrpc/rpc.go @@ -2,7 +2,6 @@ package jsonrpc import ( "encoding/json" - "fmt" "log" "strings" @@ -29,7 +28,7 @@ type Response struct { func NewHandler() protocol.Handler { c := config.GetConfig().GRpc - addr := fmt.Sprintf("%s:%d", c.Ip, c.Port) + addr := c.Addr servicePool, err := grpcPool.New(1, 5, func(conn *grpc.ClientConn) (interface{}, error) {