File tree Expand file tree Collapse file tree 3 files changed +18
-0
lines changed Expand file tree Collapse file tree 3 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package cmd
22
33import (
44 "context"
5+ "os"
56 "reflect"
67 "strconv"
78 "strings"
@@ -74,6 +75,13 @@ func (r *Request) PathParam(key string) string {
7475func (r * Request ) Context () context.Context {
7576 return context .Background ()
7677}
78+ func (r * Request ) HostName () string {
79+ h , err := os .Hostname ()
80+ if err != nil {
81+ return ""
82+ }
83+ return h
84+ }
7785
7886func (r * Request ) Bind (i interface {}) error {
7987 // pointer to struct - addressable
Original file line number Diff line number Diff line change 44 "bytes"
55 "context"
66 "encoding/json"
7+ "fmt"
78 "io/ioutil"
89 "net/http"
910
@@ -45,6 +46,14 @@ func (r *Request) Bind(i interface{}) error {
4546 return json .Unmarshal (body , & i )
4647}
4748
49+ func (r * Request ) HostName () string {
50+ proto := r .req .Header .Get ("X-forwarded-proto" )
51+ if proto == "" {
52+ proto = "http"
53+ }
54+ return fmt .Sprintf ("%s://%s" , proto , r .req .Host )
55+ }
56+
4857func (r * Request ) body () ([]byte , error ) {
4958 bodyBytes , err := ioutil .ReadAll (r .req .Body )
5059 if err != nil {
Original file line number Diff line number Diff line change @@ -12,4 +12,5 @@ type Request interface {
1212 Param (string ) string
1313 PathParam (string ) string
1414 Bind (interface {}) error
15+ HostName () string
1516}
You can’t perform that action at this time.
0 commit comments