forked from prakashpandey/hello-world-rest-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (49 loc) · 1.16 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"net/http"
"os" // Required external App Engine library
)
func helloHandler(w http.ResponseWriter, r *http.Request) {
response := os.Getenv("RESPONSE")
if len(response) == 0 {
response = "Hello OpenShift for Developers!"
}
fmt.Fprintln(w, response)
}
func main() {
http.HandleFunc("/", helloHandler)
http.ListenAndServe(":8080", nil)
}
// package main
// import (
// "fmt"
// "log"
// "net/http"
// "os"
// "google.golang.org/appengine" // Required external App Engine library
// )
// func determineListnerAddress() (string, error) {
// port := os.Getenv("PORT")
// if port == "" {
// return "", fmt.Errorf("$PORT not set")
// }
// return ":" + port, nil
// }
// func hello(w http.ResponseWriter, r *http.Request) {
// fmt.Fprintln(w, "Hello, from Tenx Infotech")
// }
// func main() {
// addr, err := determineListnerAddress()
// if err != nil {
// log.Fatal(err)
// }
// http.HandleFunc("/", hello)
// log.Printf("Listening os %s...\n", addr)
// // Starting listening
// if err := http.ListenAndServe(addr, nil); err != nil {
// panic(err)
// }
// // Starts the server to receive requests
// appengine.Main()
// }