반응형
google app engine 사용하기 ][ go hello world 출력 및 배포하기
■ app engine 선택
■ app 만들기 클릭
■ go 언어 선택
■ "documentation"과 github 샘플 확인
■ cloud shell 클릭
■ 샘플 소스 다운로드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git clone https://github.com/GoogleCloudPlatform/golang-samples | |
cd golang-samples/appengine/go11x/helloworld |
■ app 테스트
■ helloworld.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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] |
■ app.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dev_appserver.py app.yaml |
■ 결과 확인
반응형
'Google Cloud > 0x01-app engine' 카테고리의 다른 글
google app engine 사용하기 ][ python으로 google otp 사용하기 (0) | 2019.02.18 |
---|---|
google app engine 사용하기 ][ ruby hello world 출력 및 배포하기 (0) | 2019.02.14 |
google app engine 사용하기 ][ nodejs hello world 출력 및 배포하기 (0) | 2019.02.14 |
google app engine 사용하기 ][ python hello world 출력 및 배포하기 (0) | 2019.02.14 |