Oracle by Example brandingDeploy a Go Application to Oracle Cloud

section 0Before You Begin

This 10-minute tutorial shows you how to create a basic Go application and how to deploy it to Oracle Application Container Cloud Service.

Background

Oracle Application Container Cloud Service lets you deploy Go, Java Platform, Standard Edition (Java SE), Node.js, PHP, Python, Ruby, and Enterprise Edition (Java EE) applications to the Oracle Cloud.

What Do You Need?

An Oracle Cloud account with access to Oracle Application Container Cloud Service


section 1Create a Go Application

  1. Create the go-service project directory in your local system.
  2. In the go-service directory, create the rest-service.go file and add the following content:
    package main
    import ("github.com/ant0ine/go-json-rest/rest"
    	"log"
    	"net/http"
    	"os")
    func main() {
    	api := rest.NewApi()
    	api.Use(rest.DefaultDevStack...)
    	api.SetApp(rest.AppSimple(func(w rest.ResponseWriter, r *rest.Request) {
    		w.WriteJson(map[string]string{"Body": "Hello World!"})
    	}))
    	log.Fatal(http.ListenAndServe(":"+os.Getenv("PORT"), api.MakeHandler()))
    }

section 2Prepare the Application to Cloud Deployment

  1. In the go-service directory, create the start.sh script file and add the following content:
    go get github.com/ant0ine/go-json-rest/rest
    go run rest-service.go  

    Note: If you're using Windows to create this file, then make sure you convert line endings (EOL) to Unix format.

  2. In the same directory, create the manifest.json file and add the following content:
    {
        "runtime": {
            "majorVersion": "1.8.3"
        },
    	"command": "sh ./start.sh",
        "notes": "Go Application Sample"
    } 
  3. Create a .zip file with the contents of the go-service directory.

section 3Deploy Your Application to Oracle Application Container Cloud Service

  1. Open the Oracle Application Container Cloud Service console.
  2. In the Applications list view, click Create Application and select Go.
  3. In the Application section, enter a name for your application and click Browse.
  4. On the File Upload dialog box, select the .zip file you created in the previous section and click Open.
  5. Keep the default values in the Instances and Memory fields and click Create.
  6. Wait until the application is created. The URL is enabled when the creation is completed.
  7. Click the URL of your application.
    GoSample application response
    Description of the illustration go-app-response.png

more informationWant to Learn More?

Connect Go to Oracle Database Cloud Service