diff --git a/public/src/examples.html b/public/src/examples.html index 45848df..28f1eac 100644 --- a/public/src/examples.html +++ b/public/src/examples.html @@ -294,25 +294,32 @@ response.raise_for_status()

Go Integration

SDK coming soon. In the meantime, use the HTTP example below — it works with any HTTP client.

- Go — Using the SDK + Go — generate-pdf.go
package main
 
 import (
+    "bytes"
+    "encoding/json"
+    "io"
+    "net/http"
     "os"
-    docfast "github.com/docfast/docfast-go"
 )
 
-func main() {
-    client := docfast.New("df_pro_your_api_key")
-
-    pdf, err := client.HTML("<h1>Hello</h1><p>Generated with DocFast</p>", &docfast.PDFOptions{
-        Format: "A4",
-        Margin: &docfast.Margin{Top: "20mm", Bottom: "20mm"},
+func main() {
+    body, _ := json.Marshal(map[string]string{
+        "html": "<h1>Hello</h1><p>Generated with DocFast</p>",
     })
-    if err != nil {
-        panic(err)
-    }
-    os.WriteFile("output.pdf", pdf, 0644)
+
+    req, _ := http.NewRequest("POST", "https://docfast.dev/v1/convert/html", bytes.NewReader(body))
+    req.Header.Set("Authorization", "Bearer "+os.Getenv("DOCFAST_API_KEY"))
+    req.Header.Set("Content-Type", "application/json")
+
+    resp, err := http.DefaultClient.Do(req)
+    if err != nil { panic(err) }
+    defer resp.Body.Close()
+
+    pdf, _ := io.ReadAll(resp.Body)
+    os.WriteFile("output.pdf", pdf, 0644)
 }
diff --git a/src/__tests__/examples-http-only.test.ts b/src/__tests__/examples-http-only.test.ts new file mode 100644 index 0000000..f4ab279 --- /dev/null +++ b/src/__tests__/examples-http-only.test.ts @@ -0,0 +1,27 @@ +import { describe, it, expect } from 'vitest'; +import { readFileSync } from 'fs'; +import { join } from 'path'; + +describe('examples.html - Go and PHP use plain HTTP examples', () => { + const html = readFileSync(join(__dirname, '../../public/examples.html'), 'utf-8'); + + it('does NOT contain the fake Go SDK import', () => { + expect(html).not.toContain('github.com/docfast/docfast-go'); + }); + + it('does NOT contain the fake PHP SDK class', () => { + expect(html).not.toContain('DocFast\\Client'); + }); + + it('does NOT contain the fake Laravel facade', () => { + expect(html).not.toContain('DocFast\\Laravel'); + }); + + it('contains Go net/http example', () => { + expect(html).toContain('net/http'); + }); + + it('contains PHP file_get_contents example', () => { + expect(html).toContain('file_get_contents'); + }); +});