본문 바로가기
Google Cloud/0x01-app engine

google app engine 사용하기 ][ go hello world 출력 및 배포하기

by SpeeDr00t 2019. 2. 19.
반응형

google app engine 사용하기 ][ go hello world 출력 및 배포하기   


■ app engine 선택 


■ app 만들기 클릭 



■ go 언어 선택

■ "documentation"과 github 샘플 확인



■ cloud shell 클릭


■ 샘플 소스 다운로드

git clone https://github.com/GoogleCloudPlatform/golang-samples
cd golang-samples/appengine/go11x/helloworld
view raw download hosted with ❤ by GitHub


■ app 테스트

■ helloworld.go

// 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]
view raw helloworld.go hosted with ❤ by GitHub

■ app.yaml

# 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.
runtime: go111
view raw app.yaml hosted with ❤ by GitHub
dev_appserver.py app.yaml
view raw command hosted with ❤ by GitHub


■ 결과 확인






반응형