Skip to content

Instantly share code, notes, and snippets.

@ox1111
Created February 19, 2019 08:13
Show Gist options
  • Save ox1111/505e75780641b6b5f075dc1f6c91ae74 to your computer and use it in GitHub Desktop.
Save ox1111/505e75780641b6b5f075dc1f6c91ae74 to your computer and use it in GitHub Desktop.
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// [START gae_go111_app]
// Sample helloworld is an App Engine app.
package main
// [START import]
import (
"fmt"
"log"
"net/http"
"os"
)
// [END import]
// [START main_func]
func main() {
http.HandleFunc("/", indexHandler)
// [START setting_port]
port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Printf("Defaulting to port %s", port)
}
log.Printf("Listening on port %s", port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil))
// [END setting_port]
}
// [END main_func]
// [START indexHandler]
// indexHandler responds to requests with our greeting.
func indexHandler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
fmt.Fprint(w, "Hello, World!")
}
// [END indexHandler]
// [END gae_go111_app]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment