summaryrefslogtreecommitdiffstats
path: root/internal/api/api.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-09-28 09:48:40 -0700
committerRose Hogenson <rosehogenson@posteo.net>2025-09-28 09:48:40 -0700
commit04821a6e7752d6852bc1d283a88f05f7abecae87 (patch)
tree667266ce89224443831cb21d4d9e94cd6ce48c3d /internal/api/api.go
parent768d3629b938196d132b80864204d7b6a9683a9e (diff)
downloadroseh.moe-04821a6e7752d6852bc1d283a88f05f7abecae87.tar.zst
Add a gob API
Diffstat (limited to 'internal/api/api.go')
-rw-r--r--internal/api/api.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/internal/api/api.go b/internal/api/api.go
new file mode 100644
index 0000000..7c8472a
--- /dev/null
+++ b/internal/api/api.go
@@ -0,0 +1,64 @@
+// Package api contains type definitions for the gob API.
+package api
+
+import "encoding/gob"
+
+type ErrorCode int
+
+//go:generate go tool stringer -type=ErrorCode
+const (
+ Ok ErrorCode = iota
+ Unauthenticated // missing credentials
+ PermissionDenied // invalid credentials, or login required
+ BadRequest // incorrect request format (try gob)
+ NotFound // requested resource was not found
+ Internal // server encountered an unexpected error
+)
+
+func (c ErrorCode) Error() string {
+ return c.String()
+}
+
+type Response struct {
+ Status ErrorCode
+ Err string
+ Ok any
+}
+
+type LoginResponse struct {
+ Token string
+}
+
+type ListNotesRequest struct{}
+
+type ListNotesResponse struct {
+ Notes []string
+}
+
+type CreateNoteRequestStream struct {
+ Chunk []byte
+}
+
+type CreateNoteResponse struct {
+ Name string
+}
+
+type ReadNoteRequest struct {
+ Note string
+}
+
+type ReadNoteResponseStream struct {
+ Chunk []byte
+}
+
+type DeleteNoteRequest struct{}
+
+type DeleteNoteResponse struct{}
+
+func init() {
+ gob.Register(&LoginResponse{})
+ gob.Register(&ListNotesResponse{})
+ gob.Register(&CreateNoteResponse{})
+ gob.Register(&ReadNoteResponseStream{})
+ gob.Register(&DeleteNoteResponse{})
+}