서비스의 런타임 환경 설정을 지정하는 구성 파일입니다.
Go 1.12+ 런타임 환경 문서를 참조하면 지원되는 Go 버전 목록을 확인할 수 있습니다.
이 파일을 다음 콘텐츠로 채웁니다.
runtime:go116#oranothersupportedversion
main.go 파일 콘텐츠
이 파일에는 애플리케이션 코드가 포함되어 있습니다.
이 파일을 다음 콘텐츠로 채웁니다.
//Packagemainisthemainpackagepackagemainimport("log""net/http""os""text/template")vartemplates*template.Templatefuncinit(){templates=template.Must(template.New("").ParseGlob("templates/*"))}//indexHandlerhandlesthehomepage.funcindexHandler(whttp.ResponseWriter,r*http.Request){ifr.URL.Path!="/"{http.NotFound(w,r)return}iferr:=templates.ExecuteTemplate(w,"index.html",nil);err!=nil{log.Fatal(err)}}funcmain(){//Registerthehandlershttp.HandleFunc("/",indexHandler)port:=os.Getenv("PORT")ifport==""{port="8080"log.Printf("Defaulting to port %s",port)}log.Printf("Listening on port %s",port)iferr:=http.ListenAndServe(":"+port,nil);err!=nil{log.Fatal(err)}}
웹 서비스 배포
이제 코드를 배포할 준비가 되었습니다.
이 단계에서는 배포에 gcloud 도구를 사용합니다.
gcloud가 Dialogflow 에이전트와 동일한 프로젝트로 구성되었는지 확인합니다.
프로젝트를 확인하는 방법은 다음과 같습니다.
gcloud config get-value project
프로젝트를 변경하는 방법은 다음과 같습니다.
gcloud config set project YOUR_PROJECT
app.yaml 파일이 있는 go-app 디렉터리에서 다음 명령어를 사용하여 웹 서비스를 App Engine에 배포합니다.
gcloud app deploy
이 명령어를 실행하면 리전을 입력하라는 메시지가 표시됩니다.
Dialogflow 에이전트와 동일한 리전을 선택해야 합니다.
이 명령어는 웹 서비스 URL인 target url 값을 출력합니다.
브라우저를 실행하고 웹 서비스를 보려면 이전 단계의 대상 URL을 열거나 다음 명령어를 실행합니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eThis tutorial guides you through hosting a Dialogflow agent using App Engine, which is chosen for its ease of setup and scalability.\u003c/p\u003e\n"],["\u003cp\u003eThe process involves creating a Go application with specific file structures (\u003ccode\u003ego-app/\u003c/code\u003e, \u003ccode\u003etemplates/\u003c/code\u003e, \u003ccode\u003eindex.html\u003c/code\u003e, \u003ccode\u003eapp.yaml\u003c/code\u003e, \u003ccode\u003emain.go\u003c/code\u003e) and content to be hosted.\u003c/p\u003e\n"],["\u003cp\u003eDeployment of the web service is managed using the \u003ccode\u003egcloud\u003c/code\u003e tool, ensuring it's configured with the same project and region as your Dialogflow agent.\u003c/p\u003e\n"],["\u003cp\u003eDialogflow Messenger is used as the agent's user interface, and its embed code is integrated into the \u003ccode\u003eindex.html\u003c/code\u003e file to enable chat functionality.\u003c/p\u003e\n"],["\u003cp\u003eAfter deployment, it's important to clean up billable resources, such as the database instance, the function, and the app, to avoid incurring additional charges.\u003c/p\u003e\n"]]],[],null,["# Host your agent\n\nThe final step of this tutorial is to host your Dialogflow agent.\n[App Engine](/appengine/docs)\nis used for hosting,\nbecause it is simple to set up and scales well.\nThe\n[Dialogflow Messenger](/dialogflow/es/docs/integrations/dialogflow-messenger)\nintegration is used for an agent user interface.\n\nProject configuration\n---------------------\n\nIdeally, your Dialogflow agent and the App Engine instance\nare both in the same project.\nAlso, you must enable the Cloud Build API.\n\n1. Before creating the instance,\n select your project from the Google Cloud console.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n2. Enable the Cloud Build API for the project.\n\n [Enable the Cloud Build API](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com)\n\nEnvironment setup\n-----------------\n\nYou need to install and configure some things\nin order to develop a Go application for App Engine.\nFollow any steps you haven't already completed at\n[Setting up your development environment](/appengine/docs/standard/go/setting-up-environment).\n\nCreate the web service code\n---------------------------\n\nThe example code for this tutorial is written in Go,\nbut you can use any language supported by App Engine.\nCreate the following file structure anywhere on your local machine:\n\n- `go-app/`: directory for your Go service.\n - `templates/`: directory for your Go HTML templates.\n - `index.html`: Go HTML template.\n - `app.yaml`: Your service's configuration settings.\n - `main.go`: Your application code.\n\nThe next three sections provide content for the three files.\n\n### Contents of the `index.html` file\n\nThis Go HTML template file contains the HTML for the homepage.\nPopulate this file with the following contents: \n\n```matlab\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en-US\"\u003e\n \u003chead\u003e\n \u003cmeta charset=\"utf-8\"\u003e\n \u003cmeta name=\"viewport\" content=\"width=device-width\"\u003e\n \u003ctitle\u003eTutorial agent\u003c/title\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003cp\u003eOpen the chat window in the bottom right corner.\u003c/p\u003e\n \u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Contents of the `app.yaml` file\n\nThis is a configuration file which\nspecifies your service's runtime environment settings.\nYou can reference the\n[Go 1.12+ Runtime Environment document](/appengine/docs/standard/go/runtime)\nto see the list of supported Go versions.\nPopulate this file with the following contents: \n\n```actionscript-3\nruntime: go116 # or another supported version\n```\n\n### Contents of the `main.go` file\n\nThis file contains your application code.\nPopulate this file with the following contents: \n\n```python\n// Package main is the main package\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\t\"os\"\n\t\"text/template\"\n)\n\nvar templates *template.Template\n\nfunc init() {\n\ttemplates = template.Must(template.New(\"\").ParseGlob(\"templates/*\"))\n}\n\n// indexHandler handles the homepage.\nfunc indexHandler(w http.ResponseWriter, r *http.Request) {\n\tif r.URL.Path != \"/\" {\n\t\thttp.NotFound(w, r)\n\t\treturn\n\t}\n\tif err := templates.ExecuteTemplate(w, \"index.html\", nil); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n\nfunc main() {\n\t// Register the handlers\n\thttp.HandleFunc(\"/\", indexHandler)\n\n\tport := os.Getenv(\"PORT\")\n\tif port == \"\" {\n\t\tport = \"8080\"\n\t\tlog.Printf(\"Defaulting to port %s\", port)\n\t}\n\n\tlog.Printf(\"Listening on port %s\", port)\n\tif err := http.ListenAndServe(\":\"+port, nil); err != nil {\n\t\tlog.Fatal(err)\n\t}\n}\n```\n\nDeploy your web service\n-----------------------\n\nYour code is now ready to deploy.\nThese steps use the\n[gcloud tool](/sdk/gcloud)\nfor deployment:\n\n1. Ensure that gcloud is configured with the same project\n as your Dialogflow agent.\n To check the project:\n\n ```\n gcloud config get-value project\n ```\n\n To change the project: \n\n ```\n gcloud config set project YOUR_PROJECT\n ```\n2. In your `go-app` directory where your `app.yaml` file is located, deploy your\n web service to App Engine using the following command:\n\n ```\n gcloud app deploy\n ```\n\n The command will prompt you for a region.\n Be sure to select the same region as your Dialogflow agent.\n The command will output the `target url` value,\n which is the URL for your web service.\n3. To launch your browser and view your web service,\n you can open the target URL from the previous step,\n or run the following command:\n\n ```\n gcloud app browse\n ```\n\nSetup Dialogflow Messenger\n--------------------------\n\nTo set up and enable Dialogflow Messenger:\n\n1. Go to the [Dialogflow ES console](https://dialogflow.cloud.google.com).\n2. Click **Integrations** in the left sidebar menu.\n3. Click **Dialogflow Messenger**.\n4. A configuration dialog opens.\n5. Choose an [environment](/dialogflow/docs/agents-versions).\n6. Click **Enable**.\n7. Copy the embed code for pasting in your website.\n8. Click **Close**.\n\nEmbed the agent in your web service\n-----------------------------------\n\nPaste the embed code you copied above in your `index.html` file.\nThe `\u003cscript\u003e` and `\u003cdf-messenger\u003e` HTML elements\nshould be in the `\u003cbody\u003e` element of your page.\n\nDeploy your web service app again with gcloud.\nOnce deployed,\nyou can interact with your agent through the webpage\nby clicking the chat icon in the lower right corner.\n\nYou now have a fully deployed Dialogflow agent!\nTry having a conversation with the agent.\n\nCleanup\n-------\n\nWhile going through the steps of this tutorial,\n[you created billable resources](/dialogflow/es/docs/tutorials/deploy#cost).\nTo avoid incurring additional charges to your Google Cloud account:\n\n1. [Delete your database instance](/spanner/docs/create-manage-instances#delete-instance).\n2. Delete your function:\n\n ```\n gcloud functions delete tutorial-telecommunications-webhook\n ```\n3. [Disable your app](/appengine/docs/standard/go/console#disabling_an_application).\n\n4. [Delete your agent](/dialogflow/es/docs/agents-manage#delete)\n\nMore information\n----------------\n\nFor more information about the steps above, see:\n\n- [Building a Go App on App Engine](/appengine/docs/standard/go/building-app)\n- [Dialogflow Messenger](/dialogflow/es/docs/integrations/dialogflow-messenger)"]]