refactor(openflare): unify protocol API responses to Wavelet format

Migrate Agent/Relay/Tunnel handlers from compat {success,message,data}
to response.OK and response.Abort* with real HTTP status codes. Remove
the compat package and update openflare-agent, openflare-relay, and
openflared clients to parse {error_msg,data}.
This commit is contained in:
ryan
2026-06-19 11:23:12 +08:00
parent 42ca0ec642
commit 33b4123444
18 changed files with 230 additions and 358 deletions
@@ -10,7 +10,6 @@ import (
"net/http/httptest"
"testing"
"github.com/Rain-kl/Wavelet/internal/apps/openflare/compat"
"github.com/Rain-kl/Wavelet/internal/common/response"
v1 "github.com/Rain-kl/Wavelet/internal/router/v1"
ofrouter "github.com/Rain-kl/Wavelet/internal/router/v1/openflare"
@@ -34,14 +33,6 @@ func requireAPIOK(t *testing.T, rec *httptest.ResponseRecorder) response.Any {
return resp
}
func decodeEnvelope(t *testing.T, rec *httptest.ResponseRecorder) compat.Envelope {
t.Helper()
var envelope compat.Envelope
require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &envelope))
return envelope
}
func unmarshalAPIData(t *testing.T, data any, target any) {
t.Helper()
@@ -50,11 +41,6 @@ func unmarshalAPIData(t *testing.T, data any, target any) {
require.NoError(t, json.Unmarshal(payload, target))
}
func unmarshalEnvelopeData(t *testing.T, data any, target any) {
t.Helper()
unmarshalAPIData(t, data, target)
}
func unmarshalAPIMap(t *testing.T, data any) map[string]any {
t.Helper()
@@ -63,11 +49,6 @@ func unmarshalAPIMap(t *testing.T, data any) map[string]any {
return result
}
func unmarshalEnvelopeMap(t *testing.T, data any) map[string]any {
t.Helper()
return unmarshalAPIMap(t, data)
}
func unmarshalAPISlice(t *testing.T, data any) []any {
t.Helper()
@@ -76,11 +57,6 @@ func unmarshalAPISlice(t *testing.T, data any) []any {
return result
}
func unmarshalEnvelopeSlice(t *testing.T, data any) []any {
t.Helper()
return unmarshalAPISlice(t, data)
}
func mountOpenFlareTestRoutes(engine *gin.Engine) {
api := engine.Group("/api")
apiV1 := api.Group("/v1")
@@ -120,19 +96,8 @@ func performJSONRequest(
return rec
}
func performLegacyRequest(
t *testing.T,
engine http.Handler,
method, path string,
body any,
headers map[string]string,
) *httptest.ResponseRecorder {
t.Helper()
return performJSONRequest(t, engine, method, path, body, headers)
}
func adminAuthHeaders(token string) map[string]string {
return map[string]string{
"X-Access-Token": token,
}
}
}