用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/OthmanAdi/openui-forge --skill openui-forge-go命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | openui-forge-go |
| description | OpenUI generative UI with Go (net/http) backend. Direct OpenAI API streaming via HTTP. |
| version | 1.2.0 |
| author | OthmanAdi |
Build generative UI apps with a React frontend + Go backend. Streams OpenAI API responses directly via net/http.
OPENAI_API_KEY environment variable setnpm install @openuidev/react-ui @openuidev/react-headless @openuidev/react-lang lucide-react zod
npx @openuidev/cli generate ./src/lib/library.ts --out backend/system-prompt.txt
go run main.go on :8080, frontend on :3000backend/go.modmodule openui-backend
go 1.24
require (
github.com/joho/godotenv v1.5.1
)
backend/main.gopackage main
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"log"
"net/http"
"os"
_ "github.com/joho/godotenv/autoload"
)
var systemPrompt string
func init() {
data, err := os.ReadFile("system-prompt.txt")
if err != nil {
log.Fatal("system-prompt.txt not found: ", err)
}
systemPrompt = string(data)
}
func corsMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "http://localhost:3000")
w.Header().Set("Vary", "Origin")
w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
if r.Method == "OPTIONS" {
w.WriteHeader(204)
return
}
next.ServeHTTP(w, r)
})
}
type Message struct {
Role string `json:"role"`
Content string `json:"content"`
}
type ChatRequest struct {
Messages []Message
}
{
r.Method != {
http.Error(w, , )
}
req ChatRequest
err := json.NewDecoder(r.Body).Decode(&req); err != {
http.Error(w, , )
}
messages := ([]Message{{Role: , Content: systemPrompt}}, req.Messages...)
model := os.Getenv()
model == {
model =
}
body, _ := json.Marshal([]{}{
: model, : , : messages,
})
apiReq, _ := http.NewRequest(, , bytes.NewReader(body))
apiReq.Header.Set(, )
apiReq.Header.Set(, +os.Getenv())
resp, err := http.DefaultClient.Do(apiReq)
err != {
http.Error(w, , )
}
resp.Body.Close()
w.Header().Set(, )
w.Header().Set(, )
w.Header().Set(, )
flusher, ok := w.(http.Flusher)
!ok {
http.Error(w, , )
}
scanner := bufio.NewScanner(resp.Body)
scanner.Buffer(([], , *), *)
scanner.Scan() {
line := scanner.Bytes()
_, err := w.Write(line); err != {
}
_, err := w.Write([]()); err != {
}
flusher.Flush()
}
}
{
mux := http.NewServeMux()
mux.HandleFunc(, chatHandler)
fmt.Println()
log.Fatal(http.ListenAndServe(, corsMiddleware(mux)))
}
app/chat/page.tsx"use client";
import { FullScreen } from "@openuidev/react-ui";
import { openuiChatLibrary } from "@openuidev/react-ui/genui-lib";
import {
openAIAdapter,
openAIMessageFormat,
} from "@openuidev/react-headless";
export default function ChatPage() {
return (
<FullScreen
componentLibrary={openuiChatLibrary}
streamProtocol={openAIAdapter()}
messageFormat={openAIMessageFormat}
apiUrl="http://localhost:8080/api/chat"
/>
);
}
The Go backend forwards OpenAI's SSE stream line-by-line with a
bufio.Scannerloop, flushing after each line (noio.Copy), so the client sees tokens as they arrive. Pair it withopenAIAdapter()on the frontend.openAIReadableStreamAdapter()is for NDJSON (nodata:prefix) and will silently produce no output here.An official OpenAI Go SDK exists (
github.com/openai/openai-go/v3, ~v3.41.0, requires Go 1.22+) as an alternative to hand-rolling the HTTP call. This skill keeps rawnet/httpas the dependency-free default. Note the SDK still ships small, limited breaking changes between releases (per its own README, some backwards-incompatible changes land in minor versions), so pin a version if you adopt it.
npx @openuidev/cli generate ./src/lib/library.ts --out backend/system-prompt.txt
system-prompt.txt exists in the Go backend directoryOPENAI_API_KEY is set in environment or .envapiUrl points to http://localhost:8080/api/chatstreamProtocol={openAIAdapter()} and openAIMessageFormatcomponentLibrary={openuiChatLibrary} prop passed to FullScreen@openuidev/react-ui/components.css)| Error | Cause | Fix |
|---|---|---|
| CORS blocked | Origin mismatch | Update Access-Control-Allow-Origin in middleware |
system-prompt.txt not found | File missing from backend dir | Run CLI generate command |
| 502 Bad Gateway | OpenAI API unreachable or key invalid | Check OPENAI_API_KEY and network |
| Stream not flushing | Missing http.Flusher | Ensure handler calls flusher.Flush() |
| Empty response | Body not forwarded | Verify the bufio.Scanner loop writes and flushes each line |