mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-07 22:15:38 -05:00
switch hto monorepo structure
This commit is contained in:
31
backend/internal/server/models/types.go
Normal file
31
backend/internal/server/models/types.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net"
|
||||
|
||||
"github.com/AvengeMedia/DankMaterialShell/backend/internal/log"
|
||||
)
|
||||
|
||||
type Request struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
Method string `json:"method"`
|
||||
Params map[string]interface{} `json:"params,omitempty"`
|
||||
}
|
||||
|
||||
type Response[T any] struct {
|
||||
ID int `json:"id,omitempty"`
|
||||
Result *T `json:"result,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func RespondError(conn net.Conn, id int, errMsg string) {
|
||||
log.Errorf("DMS API Error: id=%d error=%s", id, errMsg)
|
||||
resp := Response[any]{ID: id, Error: errMsg}
|
||||
json.NewEncoder(conn).Encode(resp)
|
||||
}
|
||||
|
||||
func Respond[T any](conn net.Conn, id int, result T) {
|
||||
resp := Response[T]{ID: id, Result: &result}
|
||||
json.NewEncoder(conn).Encode(resp)
|
||||
}
|
||||
Reference in New Issue
Block a user