Skip to content

Instantly share code, notes, and snippets.

@rrgarciach
Created June 11, 2018 04:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrgarciach/0ea36f2ecb3e2211f42f75787ab9ec47 to your computer and use it in GitHub Desktop.
Save rrgarciach/0ea36f2ecb3e2211f42f75787ab9ec47 to your computer and use it in GitHub Desktop.
Go HTTP server example
version: '2'
services:
my-golang-app-run:
container_name: my-golang-app-run
build: .
command: go run main.go
volumes:
- ./src:/go/src/app
working_dir: /go/src/app
ports:
- "3030:3000"
environment:
PORT: 3001
FROM golang:alpine
ADD ./src /go/src/app
WORKDIR /go/src/app
ENV PORT=3001
CMD ["go", "run", "main.go"]
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "This is a website server by a Go HTTP server.")
})
http.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World! I'm a HTTP server!")
})
fs := http.FileServer(http.Dir("static/"))
http.Handle("/static/", http.StripPrefix("/static/", fs))
http.ListenAndServe(":3001", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment