occlum/demos/golang/README.md
Tate, Hongliang Tian 5e8f997d4d Make PIE the default mode for Go toolchain
Occlum-compatible executable binaries must be Position-Independent
Executable (PIE). Previously, to build such binaries, the users need to
explicitly give `-buildmode=pie` flag to `occlum-go`. Apparently, this
is error-prone. This commit sets `-buildmode=pie` by default for `occlum-go`.

In addition, this commit upgrades the Go version to 1.13.7.
2020-08-11 05:35:43 +00:00

26 lines
840 B
Markdown

# Use Golang with Occlum
This project demonstrates how Occlum enables [Golang](https://golang.org) programs running in SGX enclaves, the demo program is a HTTP web server based on a widely used web framework([Gin](https://gin-gonic.com)) for Go.
Step 1: Install Gin with `occlum-go`, it may take a few minutes
```
occlum-go get -u -v github.com/gin-gonic/gin
```
Step 2: Build the Golang web server using the Occlum Golang toolchain(i.e., `occlum-go`)
```
occlum-go build -o web_server ./web_server.go
```
Step 3: You can run the web server demo on Occlum via
```
./run_golang_on_occlum.sh
```
The HTTP web server should now start to listen on port 8090 and serve HTTP requests.
Step 4: To check whether the HTTP server works, run
```
curl http://127.0.0.1:8090/ping
```
in another terminal, and get the response `{"message":"pong"}`.