Sha256: 4ab311358c0b538b13de38c768628ebb29721ca8d27b0dcf23df6d6018693b50

Contents?: true

Size: 1.03 KB

Versions: 138

Compression:

Stored size: 1.03 KB

Contents

package main

import (
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
    "os"
)

const homepageEndPoint = "/"

// StartWebServer the webserver
func StartWebServer() {
    http.HandleFunc(homepageEndPoint, handleHomepage)
    port := os.Getenv("PORT")
    if len(port) == 0 {
        panic("Environment variable PORT is not set")
    }

    log.Printf("Starting web server to listen on endpoints [%s] and port %s",
        homepageEndPoint, port)
    if err := http.ListenAndServe(":"+port, nil); err != nil {
        panic(err)
    }
}

func handleHomepage(w http.ResponseWriter, r *http.Request) {
    urlPath := r.URL.Path
    log.Printf("Web request received on url path %s", urlPath)
    content, content_err := ioutil.ReadFile("/root/hello_world.txt")
    if content_err != nil {
        fmt.Printf("Failed to read message to display, err: %s", content_err)
    }
    _, write_err := w.Write(content)
    if write_err != nil {
        fmt.Printf("Failed to write response, err: %s", write_err)
    }
}

func main() {
    StartWebServer()
}

Version data entries

138 entries across 46 versions & 1 rubygems

Version Path
hybrid_platforms_conductor-33.9.5 examples/tutorial/05_extend_with_plugins/web_docker_image/main.go
hybrid_platforms_conductor-33.9.5 examples/tutorial/03_scale/web_docker_image/main.go
hybrid_platforms_conductor-33.9.5 examples/tutorial/04_test/web_docker_image/main.go
hybrid_platforms_conductor-33.9.4 examples/tutorial/04_test/web_docker_image/main.go
hybrid_platforms_conductor-33.9.4 examples/tutorial/05_extend_with_plugins/web_docker_image/main.go
hybrid_platforms_conductor-33.9.4 examples/tutorial/03_scale/web_docker_image/main.go
hybrid_platforms_conductor-33.9.2 examples/tutorial/03_scale/web_docker_image/main.go
hybrid_platforms_conductor-33.9.2 examples/tutorial/04_test/web_docker_image/main.go
hybrid_platforms_conductor-33.9.2 examples/tutorial/05_extend_with_plugins/web_docker_image/main.go
hybrid_platforms_conductor-33.9.1 examples/tutorial/03_scale/web_docker_image/main.go
hybrid_platforms_conductor-33.9.1 examples/tutorial/04_test/web_docker_image/main.go
hybrid_platforms_conductor-33.9.1 examples/tutorial/05_extend_with_plugins/web_docker_image/main.go
hybrid_platforms_conductor-33.9.0 examples/tutorial/03_scale/web_docker_image/main.go
hybrid_platforms_conductor-33.9.0 examples/tutorial/04_test/web_docker_image/main.go
hybrid_platforms_conductor-33.9.0 examples/tutorial/05_extend_with_plugins/web_docker_image/main.go
hybrid_platforms_conductor-33.8.4 examples/tutorial/05_extend_with_plugins/web_docker_image/main.go
hybrid_platforms_conductor-33.8.4 examples/tutorial/03_scale/web_docker_image/main.go
hybrid_platforms_conductor-33.8.4 examples/tutorial/04_test/web_docker_image/main.go
hybrid_platforms_conductor-33.8.3 examples/tutorial/03_scale/web_docker_image/main.go
hybrid_platforms_conductor-33.8.3 examples/tutorial/05_extend_with_plugins/web_docker_image/main.go