Add files
This commit is contained in:
parent
ff43e48d85
commit
f56dd36bdf
|
@ -0,0 +1,7 @@
|
|||
FROM golang:alpine
|
||||
|
||||
ADD . /go/src/git.netflux.io/rob/simple-http-page-docker/
|
||||
RUN go install git.netflux.io/rob/simple-http-page-docker
|
||||
ENTRYPOINT /go/bin/simple-http-page-docker
|
||||
|
||||
EXPOSE 3000
|
2
LICENSE
2
LICENSE
|
@ -1,4 +1,4 @@
|
|||
MIT License Copyright (c) <year> <copyright holders>
|
||||
MIT License Copyright (c) 2020 Rob Watson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
# simple-http-page-docker
|
||||
|
||||
A Docker container that runs an HTTP server returning a simple one-line plain text response.
|
||||
|
||||
Available at https://hub.docker.com/r/netfluxio/simple-http-page-docker.
|
||||
|
||||
Environment variables:
|
||||
|
||||
* `RESPONSE_STRING` - the HTTP response body
|
||||
* `STATUS_CODE` - the numeric HTTP status code (default: 200)
|
||||
* `BIND_ADDR` - bind string (default: `:3000`)
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultBindAddress = ":3000"
|
||||
defaultResponseString = "Hello world"
|
||||
defaultResponseStatus = http.StatusOK
|
||||
)
|
||||
|
||||
func main() {
|
||||
addr, ok := os.LookupEnv("BIND_ADDR")
|
||||
if !ok {
|
||||
addr = defaultBindAddress
|
||||
}
|
||||
|
||||
responseString, ok := os.LookupEnv("RESPONSE_STRING")
|
||||
if !ok {
|
||||
responseString = defaultResponseString
|
||||
}
|
||||
|
||||
var statusCode int
|
||||
statusCodeString, ok := os.LookupEnv("STATUS_CODE")
|
||||
if ok {
|
||||
var err error
|
||||
statusCode, err = strconv.Atoi(statusCodeString)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
statusCode = defaultResponseStatus
|
||||
}
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.WriteHeader(statusCode)
|
||||
fmt.Fprintf(w, responseString)
|
||||
})
|
||||
|
||||
fmt.Printf("Listening on %s...\n", addr)
|
||||
log.Fatal(http.ListenAndServe(addr, nil))
|
||||
}
|
Loading…
Reference in New Issue