-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add external-ip function by Alex Ellis
Original source from: https://github.com/openfaas/cloud-functions Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) 2023 Alex Ellis, OpenFaaS Ltd | ||
// Licensed under the MIT license, see LICENSE.md file. | ||
|
||
package function | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
) | ||
|
||
func Handle(w http.ResponseWriter, r *http.Request) { | ||
|
||
if r.Body != nil { | ||
defer r.Body.Close() | ||
} | ||
|
||
res, err := http.Get("https://api.ipify.org") | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
for k, v := range res.Header { | ||
w.Header().Set(k, v[0]) | ||
} | ||
|
||
if res.Body != nil { | ||
defer res.Body.Close() | ||
io.Copy(w, res.Body) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters