portal: remove api.go
Kim committed
Mar 6, 2026 at 14:42 UTC
8bc55d1fbac5531545715ca0a6875574cb629eb8
2 files changed
+19
-27
portal/api.go
deleted
-27
@@ -1,27 +0,0 @@
1
-package portal
2
-
3
-import (
4
- "encoding/json"
5
- "net/http"
6
-
7
- "gosuda.org/portal/types"
8
-)
9
-
10
-func writeAPIData(w http.ResponseWriter, status int, data any) {
11
- w.Header().Set("Content-Type", "application/json")
12
- w.WriteHeader(status)
13
- _ = json.NewEncoder(w).Encode(types.APIEnvelope{OK: true, Data: data})
14
-}
15
-
16
-func writeAPIOK(w http.ResponseWriter, status int) {
17
- writeAPIData(w, status, map[string]any{})
18
-}
19
-
20
-func writeAPIError(w http.ResponseWriter, status int, code, message string) {
21
- w.Header().Set("Content-Type", "application/json")
22
- w.WriteHeader(status)
23
- _ = json.NewEncoder(w).Encode(types.APIEnvelope{
24
- OK: false,
25
- Error: &types.APIError{Code: code, Message: message},
26
- })
27
-}
portal/server.go
+19
@@ -708,6 +708,25 @@ func tokenMatches(expected, actual string) bool {
708
return subtle.ConstantTimeCompare([]byte(expected), []byte(actual)) == 1
709
}
710
711
+func writeAPIData(w http.ResponseWriter, status int, data any) {
712
+ w.Header().Set("Content-Type", "application/json")
713
+ w.WriteHeader(status)
714
+ _ = json.NewEncoder(w).Encode(types.APIEnvelope{OK: true, Data: data})
715
+}
716
+
717
+func writeAPIOK(w http.ResponseWriter, status int) {
718
+ writeAPIData(w, status, map[string]any{})
719
+}
720
+
721
+func writeAPIError(w http.ResponseWriter, status int, code, message string) {
722
+ w.Header().Set("Content-Type", "application/json")
723
+ w.WriteHeader(status)
724
+ _ = json.NewEncoder(w).Encode(types.APIEnvelope{
725
+ OK: false,
726
+ Error: &types.APIError{Code: code, Message: message},
727
+ })
728
+}
729
+
730
func bridgeConns(left, right net.Conn) {
731
defer left.Close()
732
defer right.Close()