File tree Expand file tree Collapse file tree 4 files changed +46
-0
lines changed Expand file tree Collapse file tree 4 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ module handler/function
2
+
3
+ go 1.18
4
+
5
+ require github.com/russross/blackfriday/v2 v2.1.0
Original file line number Diff line number Diff line change
1
+ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk =
2
+ github.com/russross/blackfriday/v2 v2.1.0 /go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM =
Original file line number Diff line number Diff line change
1
+ package function
2
+
3
+ import (
4
+ "io"
5
+ "net/http"
6
+
7
+ "github.com/russross/blackfriday/v2"
8
+ )
9
+
10
+ func Handle (w http.ResponseWriter , r * http.Request ) {
11
+ var input []byte
12
+
13
+ if r .Body != nil {
14
+ defer r .Body .Close ()
15
+
16
+ body , err := io .ReadAll (r .Body )
17
+ if err != nil {
18
+ http .Error (w , "Failed to read body" , http .StatusInternalServerError )
19
+ return
20
+ }
21
+
22
+ input = body
23
+ }
24
+
25
+ // Convert Markdown to HTML
26
+ htmlContent := blackfriday .Run (input )
27
+
28
+ // Set response header for HTML
29
+ w .Header ().Set ("Content-Type" , "text/html" )
30
+ w .WriteHeader (http .StatusOK )
31
+ w .Write (htmlContent )
32
+ }
Original file line number Diff line number Diff line change @@ -96,8 +96,15 @@ functions:
96
96
handler : ./external-ip
97
97
image : ${SERVER:-ghcr.io}/${OWNER:-openfaas}/external-ip-fn:${TAG:-latest}
98
98
99
+ markdown :
100
+ lang : golang-middleware
101
+ handler : ./markdown
102
+ image : ${SERVER:-ghcr.io}/${OWNER:-openfaas}/markdown-fn:${TAG:-latest}
103
+
104
+
99
105
configuration :
100
106
templates :
101
107
- name : golang-middleware
102
108
source : https://github.com/openfaas/golang-http-template
103
109
110
+
You can’t perform that action at this time.
0 commit comments