|
| 1 | +--- |
| 2 | +title: Golang Baseline Testing |
| 3 | +weight: 5 |
| 4 | + |
| 5 | +### FIXED, DO NOT MODIFY |
| 6 | +layout: learningpathall |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +### Baseline testing of Golang Web Page on Azure Arm64 |
| 11 | +This section demonstrates how to test your Go installation on the **Ubuntu Pro 24.04 LTS Arm64** virtual machine by creating and running a simple Go web server that serves a styled HTML page. |
| 12 | + |
| 13 | +**1. Create Project Directory** |
| 14 | + |
| 15 | +First, create a new folder called goweb to contain all project files, and then navigate into it: |
| 16 | + |
| 17 | +```console |
| 18 | +mkdir goweb && cd goweb |
| 19 | +``` |
| 20 | +This command creates a new directory named goweb and then switches into it. |
| 21 | + |
| 22 | +**2. Create HTML Page with Bootstrap Styling** |
| 23 | + |
| 24 | +Next, create a file named `index.html` using the nano editor: |
| 25 | + |
| 26 | +```console |
| 27 | +nano index.html |
| 28 | +``` |
| 29 | + |
| 30 | +Paste the following HTML code into the index.html file. This builds a simple, styled web page with a header, a welcome message, and a button using Bootstrap. |
| 31 | + |
| 32 | +```html |
| 33 | +<!DOCTYPE html> |
| 34 | +<html lang="en"> |
| 35 | +<head> |
| 36 | + <meta charset="UTF-8"> |
| 37 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 38 | + <title>Go Web on Azure ARM64</title> |
| 39 | + < link href= "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel= "stylesheet"> |
| 40 | + <style> |
| 41 | + body { |
| 42 | + background: linear-gradient(135deg, #6dd5fa, #2980b9); |
| 43 | + color: white; |
| 44 | + min-height: 100vh; |
| 45 | + display: flex; |
| 46 | + align-items: center; |
| 47 | + justify-content: center; |
| 48 | + text-align: center; |
| 49 | + } |
| 50 | + .card { |
| 51 | + background: rgba(255, 255, 255, 0.9); |
| 52 | + color: #333; |
| 53 | + border-radius: 20px; |
| 54 | + box-shadow: 0 4px 15px rgba(0,0,0,0.2); |
| 55 | + } |
| 56 | + </style> |
| 57 | +</head> |
| 58 | +<body> |
| 59 | + <div class="container"> |
| 60 | + <div class="card p-5"> |
| 61 | + <h1 class="mb-3"> Go Web on Azure Arm64</h1> |
| 62 | + <p class="lead">This page is powered by Golang running on the Microsoft Azure Cobalt 100 processors.</p> |
| 63 | + <a href="/api/hello" class="btn btn-primary mt-3">Test API Endpoint</a> |
| 64 | + </div> |
| 65 | + </div> |
| 66 | +</body> |
| 67 | +</html> |
| 68 | +``` |
| 69 | +**3. Create Golang Web Server** |
| 70 | + |
| 71 | +Now create the Go program that will serve this web page: |
| 72 | + |
| 73 | +```console |
| 74 | +nano main.go |
| 75 | +``` |
| 76 | +Paste the following code into the main.go file. This sets up a very basic web server that serves files from the current folder, including the **index.html** you just created. When it runs, it will print a message showing the server address. |
| 77 | + |
| 78 | +```go |
| 79 | +package main |
| 80 | +import ( |
| 81 | + "encoding/json" |
| 82 | + "log" |
| 83 | + "net/http" |
| 84 | + "time" |
| 85 | +) |
| 86 | +func main() { |
| 87 | + // Serve index.html for root |
| 88 | + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 89 | + if r.URL.Path == "/" { |
| 90 | + http.ServeFile(w, r, "index.html") |
| 91 | + return |
| 92 | + } |
| 93 | + http.FileServer(http.Dir(".")).ServeHTTP(w, r) |
| 94 | + }) |
| 95 | + // REST API endpoint for JSON response |
| 96 | + http.HandleFunc("/api/hello", func(w http.ResponseWriter, r *http.Request) { |
| 97 | + w.Header().Set("Content-Type", "application/json") |
| 98 | + json.NewEncoder(w).Encode(map[string]string{ |
| 99 | + "message": "Hello from Go on Azure ARM64!", |
| 100 | + "time": time.Now().Format(time.RFC1123), |
| 101 | + }) |
| 102 | + }) |
| 103 | + log.Println("Server running on http://0.0.0.0:80") |
| 104 | + log.Fatal(http.ListenAndServe(":80", nil)) |
| 105 | +} |
| 106 | +``` |
| 107 | +{{% notice Note %}}Running on port 80 requires root privileges. Use sudo with the full Go path if needed.{{% /notice %}} |
| 108 | +**4. Run on the Web Server** |
| 109 | + |
| 110 | +Run your Go program with: |
| 111 | + |
| 112 | +```console |
| 113 | +sudo /usr/local/go/bin/go run main.go |
| 114 | +``` |
| 115 | + |
| 116 | +This compiles and immediately starts the server. If the server starts successfully, you will see the following message in your terminal:: |
| 117 | + |
| 118 | +```output |
| 119 | +2025/08/19 04:35:06 Server running on http://0.0.0.0:80 |
| 120 | +``` |
| 121 | +**5. Allow HTTP Traffic in Firewall** |
| 122 | + |
| 123 | +On **Ubuntu Pro 24.04 LTS** virtual machines, **UFW (Uncomplicated Firewall)** is used to manage firewall rules. By default, it allows only SSH (port 22) and blocks most other traffic. |
| 124 | + |
| 125 | +So even if Azure allows HTTP on port 80 (added to inbound ports during VM creation), your VM’s firewall may still block it until you run: |
| 126 | + |
| 127 | +```console |
| 128 | +sudo ufw allow 80/tcp |
| 129 | +sudo ufw enable |
| 130 | +``` |
| 131 | +You can verify that HTTP is now allowed with: |
| 132 | + |
| 133 | +```console |
| 134 | +sudo ufw status |
| 135 | +``` |
| 136 | +You should see an output similar to: |
| 137 | +```output |
| 138 | +Status: active |
| 139 | +
|
| 140 | +To Action From |
| 141 | +-- ------ ---- |
| 142 | +8080/tcp ALLOW Anywhere |
| 143 | +80/tcp ALLOW Anywhere |
| 144 | +8080/tcp (v6) ALLOW Anywhere (v6) |
| 145 | +80/tcp (v6) ALLOW Anywhere (v6) |
| 146 | +``` |
| 147 | + |
| 148 | +**6. Open in Browser** |
| 149 | + |
| 150 | +Run the following command to print your VM’s public URL, then open it in a browser: |
| 151 | + |
| 152 | +```console |
| 153 | +echo "http://$(curl -s ifconfig.me)/" |
| 154 | +``` |
| 155 | +When you visit this link, you should see the styled HTML page being served directly by your Go application. |
| 156 | + |
| 157 | +You should see the Golang web page confirming a successful installation of Golang. |
| 158 | + |
| 159 | + |
| 160 | + |
| 161 | +Now, your Golang instance is ready for further benchmarking and production use. |
0 commit comments