This commit provides a modified Go runtime in Docker image. Now we can build a Go program using `occlum-go`, then run it in SGX enclaves by Occlum. The Golang demo demonstrates how to build and run a web server program written in Go.
30 lines
667 B
Go
30 lines
667 B
Go
package main
|
|
|
|
import "net/http"
|
|
import "log"
|
|
import "flag"
|
|
import "fmt"
|
|
|
|
type Controller struct {}
|
|
func (c Controller)ServeHTTP(writer http.ResponseWriter, request *http.Request){
|
|
writer.Write([]byte("hello,1\n"));
|
|
}
|
|
|
|
func hello(writer http.ResponseWriter, request *http.Request) {
|
|
writer.Write([]byte("hello,2\n"));
|
|
}
|
|
|
|
var port string
|
|
|
|
func init() {
|
|
flag.StringVar(&port, "port", "8090", "port number, default value is 8090")
|
|
}
|
|
|
|
func main(){
|
|
flag.Parse()
|
|
fmt.Println("Web Server port is:", port)
|
|
http.Handle("/hello1",&Controller{})
|
|
http.Handle("/hello2",http.HandlerFunc(hello))
|
|
log.Fatal(http.ListenAndServe(":" + port, nil))
|
|
}
|