forked from knative/func
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9597296
commit 94d5c6e
Showing
4 changed files
with
71 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,4 @@ | ||
module function | ||
|
||
go 1.21 | ||
|
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,19 @@ | ||
package function | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func Handle(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Add("Content-Type", "text/plain") | ||
testEnvVars := []string{} | ||
for _, e := range os.Environ() { | ||
if strings.HasPrefix(e, "TEST_") { | ||
testEnvVars = append(testEnvVars, e) | ||
} | ||
} | ||
fmt.Fprintf(w, "%v\n", strings.Join(testEnvVars, "\n")) | ||
} |
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,4 @@ | ||
module function | ||
|
||
go 1.21 | ||
|
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,44 @@ | ||
package function | ||
|
||
/* | ||
This function template read and (optionally) write the content of a file on the server | ||
The template is meant to be used in by `func config volumes` e2e test | ||
*/ | ||
import ( | ||
"fmt" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
func Handle(w http.ResponseWriter, r *http.Request) { | ||
w.Header().Add("Content-Type", "text/plain") | ||
|
||
// v=/test/volume-config/myconfig | ||
// w=hello | ||
path := r.URL.Query().Get("v") | ||
content := r.URL.Query().Get("w") | ||
|
||
if path != "" { | ||
if content != "" { | ||
f, err := os.Create(path) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error creating file: %v\n", err) | ||
} else { | ||
defer f.Close() | ||
err = os.WriteFile(path, []byte(content), 0644) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error writing file: %v\n", err) | ||
} | ||
} | ||
} | ||
b, err := os.ReadFile(path) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error reading file: %v", err) | ||
} | ||
_, err = fmt.Fprintf(w, "%v", string(b)) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error on response write: %v", err) | ||
} | ||
} | ||
|
||
} |