Refactor
Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
parent
304584fc66
commit
a0cb9d8075
3 changed files with 10 additions and 5 deletions
33
go-api/utils/utils.go
Normal file
33
go-api/utils/utils.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func GetPort() string {
|
||||
port := os.Getenv("PORT")
|
||||
|
||||
if port != "" {
|
||||
return port
|
||||
}
|
||||
|
||||
return "8080"
|
||||
}
|
||||
|
||||
func GetResponseCode(r *http.Request) int {
|
||||
// If the `force-fail` header is set, get and return its value.
|
||||
if failCode := r.Header.Get("force-fail"); failCode != "" {
|
||||
log.Println("`force-fail` header set...")
|
||||
|
||||
if code, err := strconv.Atoi(failCode); err == nil {
|
||||
log.Printf("Setting the response code to %d...", code)
|
||||
|
||||
return code
|
||||
}
|
||||
}
|
||||
|
||||
return http.StatusOK
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue