...

Text file src/github.com/grpc-ecosystem/grpc-gateway/docs/_docs/cygwin.md

Documentation: github.com/grpc-ecosystem/grpc-gateway/docs/_docs

     1---
     2category: documentation
     3title: Installation for Cygwin
     4order: 1000
     5---
     6
     7# Installation for Cygwin
     8
     9![cygwin-logo](https://upload.wikimedia.org/wikipedia/commons/thumb/2/29/Cygwin_logo.svg/145px-Cygwin_logo.svg.png)
    10
    11## Installation
    12
    13First you need to install the [Go language](https://golang.org/dl/). Please install the latest version, not the one that is listed here.
    14
    15    wget -N https://storage.googleapis.com/golang/go1.8.1.windows-amd64.msi
    16    msiexec /i go1.8.1.windows-amd64.msi /passive /promptrestart
    17
    18Then you need to install [ProtocolBuffers 3.0.0-beta-3](https://github.com/google/protobuf/releases) or later. Use the Windows release as no native Cygwin protoc with version 3 is available yet.
    19
    20    wget -N https://github.com/google/protobuf/releases/download/v3.2.0/protoc-3.2.0-win32.zip`
    21    7z x protoc-3.2.0-win32.zip -o/usr/local/
    22
    23Then you need to setup your Go workspace. Create the workspace dir.
    24
    25    mkdir /home/user/go
    26    mkdir /home/user/go/bin
    27    mkdir /home/user/go/pkg
    28    mkdir /home/user/go/src
    29
    30From an elevated cmd.exe prompt set the GOPATH variable in Windows and add the `$GOPATH/bin` directory to your path using `reg add` instead of `setx` because [setx can truncate your PATH variable to 1024 characters](https://encrypted.google.com/search?hl=en&q=setx%20truncates%20PATH%201024#safe=off&hl=en&q=setx+truncated+PATH+1024).
    31
    32    setx GOPATH c:\path\to\your\cygwin\home\user\go /M
    33    set pathkey="HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment"
    34    for /F "usebackq skip=2 tokens=2*" %A IN (`reg query %pathkey% /v Path`) do (reg add %pathkey% /f /v Path /t REG_SZ /d "%B;c:\path\to\your\cygwin\home\user\go\bin")
    35
    36Then `go get -u -v` the following packages:
    37
    38    go get -u -v github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
    39    go get -u -v github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
    40    go get -u -v github.com/golang/protobuf/protoc-gen-go
    41
    42This will probably fail with a similar output to this:
    43
    44    github.com/grpc-ecosystem/grpc-gateway (download)
    45    # cd .; git clone https://github.com/grpc-ecosystem/grpc-gateway C:\path\to\your\cygwin\home\user\go\src\github.com\grpc-ecosystem\grpc-gateway
    46    Cloning into 'C:\path\to\your\cygwin\home\user\go\src\github.com\grpc-ecosystem\grpc-gateway'...
    47    fatal: Invalid path '/home/user/go/C:\path\to\your\cygwin\home\user\go\src\github.com\grpc-ecosystem\grpc-gateway': No such file or directory
    48    package github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway: exit status 128
    49
    50To fix this you need to run the `go get -u -v` commands and look for all lines starting with `# cd .;`.
    51Copy and paste these lines into your shell and change the clone destination directories.
    52
    53    git clone https://github.com/grpc-ecosystem/grpc-gateway $(cygpath -u $GOPATH)/src/github.com/grpc-ecosystem/grpc-gateway
    54    git clone https://github.com/golang/glog $(cygpath -u $GOPATH)/src/github.com/golang/glog
    55    git clone https://github.com/golang/protobuf $(cygpath -u $GOPATH)/src/github.com/golang/protobuf
    56    git clone https://github.com/google/go-genproto $(cygpath -u $GOPATH)/src/google.golang.org/genproto
    57
    58Once the clone operations are finished the `go get -u -v` commands shouldn't give you an error anymore.
    59
    60## Usage
    61
    62Follow the [instructions](https://github.com/grpc-ecosystem/grpc-gateway#usage) in the [README](https://github.com/grpc-ecosystem/grpc-gateway#readme).
    63
    64Adjust steps 3, 5 and 7 like this. protoc expects native Windows paths.
    65
    66    protoc -I. -I$(cygpath -w /usr/local/include) -I${GOPATH}/src -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=plugins=grpc:. ./path/to/your_service.proto
    67    protoc -I. -I$(cygpath -w /usr/local/include) -I${GOPATH}/src -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:. ./path/to/your_service.proto
    68    protoc -I. -I$(cygpath -w /usr/local/include) -I${GOPATH}/src -I${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --swagger_out=logtostderr=true:. ./path/to/your_service.proto
    69
    70Then `cd` into the directory where your entry-point `main.go` file is located and run:
    71
    72    go get -v
    73
    74This will fail in this same way as it did during the installation. Look for all lines starting with `# cd .;`. Copy and paste these lines into your shell and change the clone destination directories.
    75
    76    git clone https://go.googlesource.com/net $(cygpath -u $GOPATH)/src/golang.org/x/net
    77    git clone https://go.googlesource.com/text $(cygpath -u $GOPATH)/src/golang.org/x/text
    78    git clone https://github.com/grpc/grpc-go $(cygpath -u $GOPATH)/src/google.golang.org/grpc
    79
    80Once the clone operations are finished the `go get -v` commands shouldn't give you an error anymore.
    81
    82Then run:
    83
    84    go install
    85
    86This will compile and install your grpc-gateway service into `$GOPATH/bin`.

View as plain text