├── .gitignore ├── .godir ├── Godeps ├── Godeps.json ├── Readme └── _workspace │ └── .gitignore ├── LICENSE ├── Procfile ├── README.md └── web.go /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 3 | *.o 4 | *.a 5 | *.so 6 | 7 | # Folders 8 | _obj 9 | _test 10 | 11 | # Architecture specific extensions/prefixes 12 | *.[568vq] 13 | [568vq].out 14 | 15 | *.cgo1.go 16 | *.cgo2.c 17 | _cgo_defun.c 18 | _cgo_gotypes.go 19 | _cgo_export.* 20 | 21 | _testmain.go 22 | 23 | *.exe 24 | 25 | .env 26 | -------------------------------------------------------------------------------- /.godir: -------------------------------------------------------------------------------- 1 | example-go 2 | -------------------------------------------------------------------------------- /Godeps/Godeps.json: -------------------------------------------------------------------------------- 1 | { 2 | "ImportPath": "github.com/deis/example-go", 3 | "GoVersion": "go1.7", 4 | "Packages": ["."], 5 | "Deps": [] 6 | } 7 | -------------------------------------------------------------------------------- /Godeps/Readme: -------------------------------------------------------------------------------- 1 | This directory tree is generated automatically by godep. 2 | 3 | Please do not edit. 4 | 5 | See https://github.com/tools/godep for more information. 6 | -------------------------------------------------------------------------------- /Godeps/_workspace/.gitignore: -------------------------------------------------------------------------------- 1 | /pkg 2 | /bin 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: example-go 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Go Quick Start Guide 2 | 3 | This guide will walk you through deploying a Go application on [Deis Workflow][]. 4 | 5 | ## Usage 6 | 7 | ```console 8 | $ git clone https://github.com/deis/example-go.git 9 | $ cd example-go 10 | $ deis create 11 | Creating Application... done, created allied-question 12 | Git remote deis added for app allied-question 13 | $ git push deis master 14 | Counting objects: 89, done. 15 | Delta compression using up to 4 threads. 16 | Compressing objects: 100% (67/67), done. 17 | Writing objects: 100% (89/89), 19.23 KiB | 0 bytes/s, done. 18 | Total 89 (delta 37), reused 46 (delta 17) 19 | Starting build... but first, coffee! 20 | -----> Go app detected 21 | -----> Checking Godeps/Godeps.json file. 22 | -----> Installing go1.7... done 23 | -----> Running: go install -v -tags heroku . 24 | github.com/deis/example-go 25 | -----> Discovering process types 26 | Procfile declares types -> web 27 | -----> Compiled slug size is 1.9M 28 | Build complete. 29 | Launching App... 30 | Done, allied-question:v2 deployed to Workflow 31 | 32 | Use 'deis open' to view this application in your browser 33 | 34 | To learn more, use 'deis help' or visit https://deis.com/ 35 | 36 | To ssh://git@deis-builder.deis.rocks:2222/allied-question.git 37 | * [new branch] master -> master 38 | $ curl http://allied-question.deis.rocks 39 | Powered by Deis 40 | Release v2 on allied-question-v2-web-wudcx 41 | ``` 42 | 43 | ## Additional Resources 44 | 45 | * [GitHub Project](https://github.com/deis/workflow) 46 | * [Documentation](https://deis.com/docs/workflow/) 47 | * [Blog](https://deis.com/blog/) 48 | 49 | [Deis Workflow]: https://github.com/deis/workflow#readme 50 | -------------------------------------------------------------------------------- /web.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "net/http" 7 | "os" 8 | ) 9 | 10 | // main starts an HTTP server listening on $PORT which dispatches to request handlers. 11 | func main() { 12 | http.Handle("/healthz", http.HandlerFunc(healthcheckHandler)) 13 | // wrap the poweredByHandler with logging middleware 14 | http.Handle("/", logRequestMiddleware(http.HandlerFunc(poweredByHandler))) 15 | port := os.Getenv("PORT") 16 | log.Printf("listening on %v...\n", port) 17 | err := http.ListenAndServe(":"+port, nil) 18 | if err != nil { 19 | panic(err) 20 | } 21 | } 22 | 23 | // poweredByHandler writes "Powered by $POWERED_BY" to the response. 24 | func poweredByHandler(w http.ResponseWriter, r *http.Request) { 25 | release := os.Getenv("WORKFLOW_RELEASE") 26 | if release == "" { 27 | release = "" 28 | } 29 | powered := os.Getenv("POWERED_BY") 30 | if powered == "" { 31 | powered = "Deis" 32 | } 33 | // print the string to the ResponseWriter 34 | hostname, _ := os.Hostname() 35 | fmt.Fprintf(w, "Powered by %v\nRelease %v on %v\n", powered, release, hostname) 36 | } 37 | 38 | // healthcheckHandler returns 200 for kubernetes healthchecks. 39 | func healthcheckHandler(w http.ResponseWriter, r *http.Request) { 40 | w.WriteHeader(http.StatusOK) 41 | w.Write([]byte{}) 42 | } 43 | 44 | // logRequestMiddleware writes out HTTP request information before passing to the next handler. 45 | func logRequestMiddleware(next http.Handler) http.Handler { 46 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 47 | remote := r.RemoteAddr 48 | if forwardedFor := r.Header.Get("X-Forwarded-For"); forwardedFor != "" { 49 | remote = forwardedFor 50 | } 51 | log.Printf("%s %s %s", remote, r.Method, r.URL) 52 | // pass the request to the next handler 53 | next.ServeHTTP(w, r) 54 | }) 55 | } 56 | --------------------------------------------------------------------------------