Examples

Check out this list of examples here.

Deploying a Static File Server

Lets start with a basic go static file server, copy-and-paste below to server.go:

package main

import (
    "log"
    "net/http"
)

func main() {
    fs := http.FileServer(http.Dir("static"))
    http.Handle("/", fs)

    log.Println("Listening...on 8080")
    http.ListenAndServe(":8080", nil)
}

Now build server.go:

$ GOOS=linux go build server.go

Prepare the HTML content:

Create hello.html:

Create a config file named config.json:

If you are on linux you can use the above example to enable dns/tls, otherwise you can use this for local Mac examples.

Note: This is more than likely to change in the very near future.

The directory structure should look like below after these steps:

Package and deploy:

Notice that we are using KVM user-mode networking and have to forward host port 8080 to VM.

Curl it:

To learn more about various config options visit OPS GitHub repository.

Examples

More examples can be found from the ops-examples repository.

Last updated

Was this helpful?