File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -82,10 +82,11 @@ func callbackHandler(w http.ResponseWriter, r *http.Request) {
8282
8383 log .Println ("Got GeminiImage ret:" , ret )
8484
85- jsonData := extractJSONFromString (ret )
85+ // Remove first and last line, which are the backticks.
86+ jsonData := removeFirstAndLastLine (ret )
8687 log .Println ("Got jsonData:" , jsonData )
87- // Parse json and insert NotionDB
8888
89+ // Parse json and insert NotionDB
8990 var person Person
9091 err = json .Unmarshal ([]byte (jsonData ), & person )
9192 if err != nil {
@@ -186,3 +187,17 @@ func extractJSONFromString(s string) string {
186187
187188 return s
188189}
190+
191+ // removeFirstAndLastLine takes a string and removes the first and last lines.
192+ func removeFirstAndLastLine (s string ) string {
193+ // Split the string into lines.
194+ lines := strings .Split (s , "\n " )
195+
196+ // If there are less than 3 lines, return an empty string because removing the first and last would leave nothing.
197+ if len (lines ) < 3 {
198+ return ""
199+ }
200+
201+ // Join the lines back together, skipping the first and last lines.
202+ return strings .Join (lines [1 :len (lines )- 1 ], "\n " )
203+ }
You can’t perform that action at this time.
0 commit comments